Skip to content

Instantly share code, notes, and snippets.

@jigneshthummar
Last active February 21, 2022 17:55
Show Gist options
  • Save jigneshthummar/39c4ebef8d5b5aa51df3b1d7d447d6c4 to your computer and use it in GitHub Desktop.
Save jigneshthummar/39c4ebef8d5b5aa51df3b1d7d447d6c4 to your computer and use it in GitHub Desktop.
JavaScript / TypeScript / ES6 / ReactJS - CheatSheet
Variables & Constants
//-------------------------------------------------------------------------//
| # | var | let | const |
|-----------------|-----|-----|-------|
| global scoped | yes | no | no |
| function scoped | yes | yes | yes |
| block scoped | no | yes | yes |
| redeclarable | yes | no | no |
| reassignable | yes | yes | no |
| can be hoisted | yes | no | no |
Declaration / Initilization / Assignment
//-------------------------------------------------------------------------//
// myVar is declared globally
var myVar = "Hello";
function myFn(){
console.log(myVar)
}
myFn();
console.log(myVar);
//-------------------------------------------------------------------------//
// myVar2 is declared inside the function / block
function myFn2(){
var myVar2 = "Hello";
console.log(myVar2)
}
myFn2();
console.log(myVar2); // Uncaught ReferenceError: myVar is not defined
//-------------------------------------------------------------------------//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment