2. Agenda
Introduction to let
Let syntax
Live examples
Introduction to const
Const syntax
Live examples
3. Introduction to let
Let is a block level scope variable.
Let allows you to declare variables that are limited in scope to the block,
statement, or expression.
Using var we can define a variable either globally, or locally to entire
function regardless of block scope.
Let doesn’t allow duplicate variable creation.
4. let syntax
Syntax
let var_name = value_1 [, var_name2 = val_2, …..];
Example
let value_of_pi = 3.14, body_temp = 98.9; // initialization optional
5. Examples
Var Example :
var testLet = ( ) => {
var x = 10;
if ( true ) { var x = 20; console.log ( x ); }
}
console.log ( x );
7. Introduction to const
Constants are block level scope variables. The scope may either global or
local scope.
Constants are working like variables defined using let statement.
We can’t modify value of constants.
Constants re-declarations are not allowed.