Last active
February 11, 2016 08:18
-
-
Save sagar-ganatra/d9c7cb78629b7cadfbe5 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
exports.fn1 = function(){ | |
'use strict'; | |
console.log('Example 1 - use of let in blocks'); | |
let a = 10; | |
function test() { //new scope, TDZ | |
//console.log(a); //throws reference error | |
let a = 20; | |
console.log(a); // prints 20 | |
{ | |
console.log(a); // prints 20 | |
a = 40; //change in assignment | |
console.log(a); // prints 40 | |
} | |
console.log(a); //prints 40, the value of the variable is changed in the block | |
} | |
test(); | |
console.log(a); //prints 10 | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment