Skip to content

Instantly share code, notes, and snippets.

@sagar-ganatra
Last active February 11, 2016 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagar-ganatra/d9c7cb78629b7cadfbe5 to your computer and use it in GitHub Desktop.
Save sagar-ganatra/d9c7cb78629b7cadfbe5 to your computer and use it in GitHub Desktop.
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