Skip to content

Instantly share code, notes, and snippets.

@atorralb
Last active October 31, 2016 01:25
Show Gist options
  • Save atorralb/6b2ad46b296616bd1d2747095305a471 to your computer and use it in GitHub Desktop.
Save atorralb/6b2ad46b296616bd1d2747095305a471 to your computer and use it in GitHub Desktop.

###var vs let vs const var is only used for backward compatibility with plain javascript (ES5 and before) "var" variables are visible outside the block scope

var m = "hello";
if (m){
  var i:number;
  for(i=0; i<3;i++){
    console.log(m + ' ' + i)
  }
}
console.log(i); // outputs 2

"let" variables are not visible outsidde the block scope

var m = "hello";
if (m){
  let i:number;
  for(i=0; i<3;i++){
    console.log(m + ' ' + i)
  }
}
console.log(i) //undefined

"const" variables is one of the best practices because creates an inmutable reference,

const  m = "hello";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment