Last active
February 21, 2022 17:55
-
-
Save jigneshthummar/39c4ebef8d5b5aa51df3b1d7d447d6c4 to your computer and use it in GitHub Desktop.
JavaScript / TypeScript / ES6 / ReactJS - CheatSheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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