ES6 Syntax Examples I : let (var), const, block scoping

Hey,

This blog is about let, const and block scoping on ES6. I'm gonna put some small ES6 code pieces which I found interesting & different from ES5. I hope you find it useful & helpful.

Reference Error
'use strict';  
console.log(blogId);  
let blogId = 67;  

Logs: ReferrenceError : blogId is not defined


Undefined Variable
'use strict';  
let blogId;  
console.log(blogId);  

Logs: Undefined


Function Block Scoping
'use strict';  
function updateBlogId(){  
    blogId = 25;
}
let blogId = null;  
updateBlogId();  
console.log(blogId);  

Logs: 25


var & let Difference in Closure
'use strict';  
let updateFunctions = [];  
for(var i = 0; i<2; i++){  
    updateFunctions.push(function(){return i;})
}
console.log(updateFunctions[0]());  

Logs: 2


What if we use let instead of var ?

'use strict';  
let updateFunctions = [];  
for(let i = 0; i<2; i++){  
    updateFunctions.push(function(){return i;})
}
console.log(updateFunctions[0]());  

Logs: 0


const Keyword
'use strict';  
const SECRET;  
console.log(SECRET);  

Logs: SyntaxError: Unexpected token;


const Assignment
'use strict';  
const SECRET='OGPOYRAZ';  
SECRET = 'OGPOYRAZ.COM';  
console.log(SECRET);  

Logs: TypeError: Assignment to constant variable.

Feel free to add more on disquss so I can update. Thanks for reading.