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
var funcArray = []; | |
for (let i = 0; i < 10; i++) { | |
funcArray.push(function() { console.log(i); }); | |
} | |
//console.log(i); // Not accessible as i is block scope variable !!! | |
funcArray.forEach(function(func) { | |
func(); | |
}); |
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
var funcArray_1 = []; | |
var funcArray_2 = []; | |
//IIFE of type 1 | |
for (var i = 0; i < 10; i++) { | |
funcArray_1.push(function(val){ | |
return function() { console.log(val); } | |
}(i)); | |
} | |
console.log(i); // 10 |
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
var funcArray = []; | |
for (var i = 0; i < 10; i++) { | |
funcArray.push(function() { console.log(i); }); | |
} | |
console.log(i); // Accessible but undefined | |
funcArray.forEach(function(func) { | |
func(); | |
}); |
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
function checkVar() { | |
var validate = 1; //Make it 0 to execute else block | |
if(validate) { | |
var varName = "test"; //comment this line to confirm exception | |
console.log(varName); | |
} | |
else{ | |
console.log(varName); //varName is accessible with value undefined | |
} | |
console.log(varName); // varName is accessible and defined if validate = 1, varName is accessible but undefined if validate = 0 |
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
/***/ function(module, exports) { | |
"use strict"; | |
var greeting = "Hello world"; | |
console.log("" + greeting); | |
/***/ } |
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
<!DOCTYPE <!DOCTYPE html> | |
<html> | |
<head> | |
<title>ECAMScript Beginner Guide</title> | |
<script src="bundle.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
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
{ | |
"name": "ecmascript-6-beginner-guide", | |
"version": "1.0.0", | |
"description": "Demo on setting develop environment setup for \"ECMAScript 6: Beginner Guide\"", | |
"main": "index.js", | |
"scripts": { | |
"start": "./node_modules/webpack/bin/webpack.js --config webpack.config.js --progress --colors", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [ |
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
let greeting = "Hello world"; | |
console.log(`${greeting}`) |
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
module.exports = { | |
entry:'./script.js', | |
output:{ | |
filename:'bundle.js' | |
}, | |
module:{ | |
loaders:[ | |
{ | |
test: /\.js?/, | |
loader: 'babel', |
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
{ | |
"name": "ecmascript-6-beginner-guide", | |
"version": "1.0.0", | |
"description": "Demo on setting develop environment setup for \"ECMAScript 6: Beginner Guide\"", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"keywords": [ | |
"ECMAScript6", |