Last active
November 12, 2017 22:01
-
-
Save travissanon/3befe5ce3f0ae2e529bda6d0d9044099 to your computer and use it in GitHub Desktop.
var vs let vs const
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
var, let, and const. What are the differences of the three and which ones should you use? | |
If you do not know what let and const are, they are basically different variations of the “variable”, derived from ES6. | |
Variables are absolutely essential to any programming language, but in Javascript, the var keyword does has some flaws. | |
Thats where ES6 variables come in. | |
When you declare a const = Cannot be updated | |
When you declare a let = The variable can only be used in the block its created in | |
What do I mean by “block”? | |
Anything inside a pair of curly braces is a block. | |
Now lets take a look at some examples to better understand var let and const | |
// const | |
const yo = ‘Hello’; | |
yo = ‘Hey’; | |
// console: **ERROR** | |
// let | |
function greetings(){ | |
if (true) { | |
let greeting = ‘whats up’; | |
} | |
console.log(greeting); | |
} | |
// console: **ERROR** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment