Created
October 24, 2016 19:53
-
-
Save KinoAR/2d0b6ecf30938df55ad7789633d258db to your computer and use it in GitHub Desktop.
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
//============================================================================= | |
// Block Scoped Variables | |
//============================================================================= | |
//Variable Types | |
//var | |
//let | |
//ES5 | |
function blockScope1() { | |
//Not considered a block scope for var | |
{ | |
var a = 1; | |
} | |
function blockScope() { | |
var b = 0; | |
console.log("Block Scope 1: " + b); //Block Scope 1: 0 | |
} | |
blockScope2(); | |
console.log("Block Scope 1 :" + a); //Block Scope 1: 1 | |
console.log("Block Scope 1: " + b); //b is not defined | |
} | |
blockScope1(); | |
//ES6 | |
function blockScope2() { | |
{ | |
let a = 0; | |
console.log(`Block Scope 2 : ${a}`); //Block Scope 2 : 0 | |
} | |
console.log(`Block Scope 2 : ${a}`);//a is not defined | |
} | |
blockScope2(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment