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* myGenerator() { | |
var array = [1, 2]; | |
while (array.length) { | |
yield array.shift(); | |
} | |
} | |
var generator = myGenerator(); | |
console.log(generator.next()); // { value: 1, done: false } |
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 myIterator() { | |
var array = [1, 2]; | |
return { | |
next: function() { | |
if (array.length) { | |
return { | |
value: array.shift(), | |
done: false | |
}; | |
} else { |
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 myIterator() { | |
var array = [1, 2]; | |
return { | |
next: function() { | |
if (array.length) { | |
return { | |
value: array.shift(), | |
done: false | |
}; | |
} else { |
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
typeof undefined // 'undefined' | |
typeof null // 'object' |
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
({}).toString() // '[object Object]' | |
[].toString() // '' |
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
({}).valueOf() // {} | |
[].valueOf() // [] |
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
[1,2,3].slice(0, null) // [] | |
[1,2,3].slice(0, undefined) // [1,2,3] |
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
> 0.1.toString(2) | |
'0.0001100110011001100110011001100110011001100110011001101' | |
> 0.2.toString(2) | |
'0.001100110011001100110011001100110011001100110011001101' |
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
'0'.charCodeAt(0) // 48 | |
'2'.charCodeAt(0) // 50 | |
'10'.charCodeAt(0) // 49 |
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 example = { length: 3 } // An array-like object | |
// When executing 'Array.apply(null, example)' | |
// Array will be executed with its arguments being the properties' values from 0...length - 1 | |
Array(example[0], example[1], example[2]) | |
// Which translates into | |
Array(undefined, undefined, undefined) // [ undefined, undefined, undefined ] |