variable

Estimated reading time: 1 minute

es6 let & const

  • let
  • const

var

  • var
  • access any where
  • last value is current value
var name = 'code4mk'
{
  var name = 'kamal';
  console.log(name);
}
console.log(name);
// kamal
// kamal

let

  • let is local variable
  • don’t access outside of block
  • don’t duplicate accept same block
let name = 'code4mk'
{
  let name = 'kamal';
  console.log(name);
}
console.log(name);
// kamal
// code4mk

const

  • const always fixed
  • no change allow
const price = 51;
// const price = 55 // error
console.log(price);
es, es6, js