Last active
April 15, 2018 09:00
-
-
Save evagabond/30ca19b1627477783aec01f82cbac0fe to your computer and use it in GitHub Desktop.
Why not to use var in variable declaration, and instead use let or const in JavaScript
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
// Global Scope | |
var a = 1; | |
var b = 2; | |
var c = 3; | |
// Testing Block Scope | |
if(true) { | |
// Block scope | |
var a = 4; | |
let b = 5; | |
const c = 6; | |
console.log('If Scope: ', a, b, c); | |
} | |
console.log('Global Scope: ', a, b, c); | |
// Output will be as follows | |
// Block Scope of if Statement: 4, 5, 6 | |
// Global Scope: 4, 2, 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment