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
/** | |
* JS + ES6 - Buit-in types. | |
* | |
* There are 6 built-in types in JavaScript (undefined, string, number, boolean, null, object). Plus, a new one | |
* introduced with ES6 (symbol). | |
**/ | |
var foo; | |
console.log(typeof foo); // "undefined" | |
var bar = 'P. Nutt'; |
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
/** | |
* ES6 - Destructuring assignment | |
**/ | |
var [person1, person2, person3, ...otherPeople] = [ | |
{ | |
name: 'P. Nutt', | |
age: 18 | |
}, | |
{ | |
name: 'Hazel Nutt', |
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
/** | |
* ES6 - Default function parameters. | |
* | |
* Define default value for empty function parameters. | |
**/ | |
function sayHello(name, isPirate = false) { | |
if (isPirate) { | |
console.log(name + ' says: Arrr! This be good grog!'); // Manny Bones says: Arrr! This be good grog! | |
} else { | |
console.log(name + ' says: Hi, how are you?'); // P. Nutt says: Hi, how are you? |
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
/** | |
* ES6 - Arrow functions. | |
* | |
* Empty arrow functions return `undefined`. The same as normal functions. | |
**/ | |
let emptyness = () => {}; | |
console.log(emptyness()); // undefined | |
var completelyEmpty = function() { | |
}; |
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
/** | |
* ES6 - Arrow functions. | |
* | |
* Arrow functions don't rebind `this`. Comparison between old `function` approach and `arrow function` approach. | |
**/ | |
function Person0(name, age) { | |
this.name = name; | |
this.age = age; | |
setTimeout(function() { |
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
/** | |
* Difference between implicit and explicit global variables | |
**/ | |
var myGlobal1 = 'P. Nutt'; | |
myGlobal2 = 'Hazel Nutt'; | |
delete myGlobal1; // false | |
delete myGlobal2; // true | |
console.log(myGlobal1); // P. Nutt | |
console.log(myGlobal2); // ReferenceError |
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
/** | |
* ES6 - Arrow functions. | |
* | |
* Arrow functions are always anonymous. Useful for one line callbacks. | |
**/ | |
const people = [ | |
{ | |
name: 'P. Nutt', | |
age: 18 | |
}, |
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
/** | |
* ES6 - var, let, const. The temporal dead zone. | |
* | |
* According to ECMAScript 6 specification. https://tc39.github.io/ecma262/#sec-let-and-const-declarations | |
* let and const declarations define variables that are scoped to the running execution context's | |
* LexicalEnvironment. The variables are created when their containing Lexical Environment is instantiated but may | |
* not be accessed in any way until the variable's LexicalBinding is evaluated. A variable defined by a | |
* LexicalBinding with an Initializer is assigned the value of its Initializer's AssignmentExpression when the | |
* LexicalBinding is evaluated, not when the variable is created. If a LexicalBinding in a let declaration does | |
* not have an Initializer the variable is assigned the value undefined when the LexicalBinding is evaluated. |