WebMasterCampus
WEB DEVELOPER Resources

Javascript ES6 Let Keyword

Learn Javascript ES6 let keyword


let keyword

The let keyword was introduced in ES6. The let statement declares a block-scoped local variable, optionally initializing it to a value.

let Keyword Rules

  • Variables defined with let have Block Scope.
  • Variables defined with let cannot be Redeclared.
  • Variables defined with let must be Declared before use.

let Block Scope Example

var x = 20;
console.log("x outer scope value: "+x);

{
  let x = 10;
  console.log("x inner Scope with let : "+x);
}

console.log("x outer scope value: "+x);

let cannot be Redeclared Example

let a = 20;

let a = True;

console.log(a);

let must be Declared before use


x = 30;
console.log(x);  // variable without declaration considered as var
Created with love and passion.