javascript var let
snippet in javascript

javascript var let

user2024

// var has function scope.
// let has block scope.

function func(){
  if(true){
    var A = 1;
    let B = 2;
  }
  A++; // 2 --> ok, inside function scope
  B++; // B is not defined --> not ok, outside of block scope
  return A + B; // NaN --> B is not defined
}

vars with let in it javascript

user7151

let /*Var name*/ = /*what is equals*/

let vs var javascript

user7389

var: older
let: newer