JavaScript Variables and 3commonly used methods.

JavaScript Variables and 3commonly used methods.

JS Variables:

Variables are like a container that contains some value also we can declare a variable without assigning any values otherwise, we can say a name given to memory allocation.

EX: a = 18 Here 'a' is the variable and 18 is the value.

Declare Variable in JavaScript:

  • JavaScript is a scripting language. It has 3 methods to declare variables as,

    1- Var ,2-let , 3-const.

  • Var keyword is developed by JavaScript and let & const are developed by ECMA Script.

var: By using Var keyword declaration, initialization, re-declaration, re-initialization and so-on is possible but scope of the variable is not limited to all the blocks.

EX:

let: By using let keyword declaration, initialization, and re-initialization are possible but re-declaration is not possible and the scope of the variable is limited to all the blocks except the function block.

EX:

const: By using const keyword at the same time declaration and initialization will occur but we can't re-declare it.

Ex:

3-most commonly used methods of JavaScript.

  1. alert(): To display alerts to the end-user we can use this method.

  2. console.log(): To print messages to the developer's console we can use this method.

  3. prompt(): To get input from the end-user we can use this method.

Upcoming chapter (JavaScript operators)....