Learn Javascript With Me

JavaScript Basics

1. JavaScript is the most popular programming language out there.
2. It is one of the languages all web developers must learn.
3. It is basically a dynamic programming language commonly used as a part of the web pages.

1. Script Tag

1. If you are trying to code JS inside html page we need a special tag to write JS and that tag is script.
2. We can use script tag to write JS code as well as to reference to an external .js file into the html page.
3. We can add script tag in the head tag as well as in the body tag.
4. The script included into head tag may not be able to access DOM elements because head loads before body. Write script before ending of body tag if script code needs to access DOM elements.

Following is the example of how to use script tag:

2. JS is case sensitive

1. JavaScript is a case-sensitive language, which means that the language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.
So the identifiers food and FOOD will convey different meanings.

Be clear from the example:

3. JS is dynamically typed not statically

JavaScript is dynamically typed, that means types of variables are generally not known at compile time.

Be clear through example:

Error encountered:

4. JS datatypes are inferred

The mechanism that frees us from having to babysit the compiler is called type inference.
Type inference means you don't have to worry about declaring types everywhere just to make the compiler happy

Understand better with example:

5. Importance of var

The var keyword is used to create new variables in the current scope. var respects the scope ,without var variables are global.
Always declare using var to decrease global variable pollution.

Go through example to be more clear:

Error encountered:

6. JS Hoisting

Hoisting is JS default behaviour of moving all the declarations to the top. Variable can be declared after it has been used.

Example:

Also it works fine if we code like:

1 comments:

Click here for comments
4 December 2020 at 00:44 ×

Nice work krishna :)

Congrats bro Bibek Chaudhary you got PERTAMAX...! hehehehe...
Reply
avatar