On Github richgilbank / lightning-talk-es6
var myVar = "Foo";
(function(){
console.log( myVar ); // Logs 'Foo'
})();
var myVar = "Foo";
(function(){
console.log( myVar ); // Logs 'undefined'
var myVar = "Bar";
})();
function foo() {
var x, y;
// ...
x = "Shop";
y = "ify";
return x + y;
}
var es = [];
for (var i = 0; i < 10; i++) {
es[i] = function () {
console.log("Upcoming edition of ECMAScript is ES" + i);
};
}
es[6](); // Upcoming edition of ECMAScript is ES10
var es = [];
for (var i = 0; i < 10; i++) {
let c = i;
es[i] = function () {
console.log("Upcoming edition of ECMAScript is ES" + c);
};
}
es[6](); // Upcoming edition of ECMAScript is ES6
var a = 5;
var b = 10;
if (a === 5) {
let a = 4; // The scope is inside the if-block
var b = 1; // The scope is inside the function
console.log(a); // 4
console.log(b); // 1
}
console.log(a); // 5
console.log(b); // 1