Let and Const | ES6 JAGADEESH PATTA ( PJ )
Agenda  Introduction to let  Let syntax  Live examples  Introduction to const  Const syntax  Live examples
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.
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
Examples Var Example : var testLet = ( ) => { var x = 10; if ( true ) { var x = 20; console.log ( x ); } } console.log ( x );
Examples(cont…) Let Example : var testLet = ( ) => { let x = 10; if ( true ) { let x = 20; console.log ( x ); } } console.log ( x );
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.
Const syntax Syntax const const_name = value_1 [, const_name2 = val_2, …..]; Example const value_of_pi = 3.14, body_temp = 98.9;
Examples Const Example : var testConst = ( ) => { const x = 10; if ( true ) { const x = 20; console.log ( x ); } } console.log ( x );
Any Q ?
Thank You

9. ES6 | Let And Const | TypeScript | JavaScript

  • 1.
    Let and Const| ES6 JAGADEESH PATTA ( PJ )
  • 2.
    Agenda  Introduction tolet  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 : vartestLet = ( ) => { var x = 10; if ( true ) { var x = 20; console.log ( x ); } } console.log ( x );
  • 6.
    Examples(cont…) Let Example : vartestLet = ( ) => { let x = 10; if ( true ) { let 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.
  • 8.
    Const syntax Syntax const const_name= value_1 [, const_name2 = val_2, …..]; Example const value_of_pi = 3.14, body_temp = 98.9;
  • 9.
    Examples Const Example : vartestConst = ( ) => { const x = 10; if ( true ) { const x = 20; console.log ( x ); } } console.log ( x );
  • 10.
  • 11.