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
console.log("1"); | |
setTimeout(() => console.log("2"),0); | |
var promise = new Promise(function(resolve, reject) { | |
resolve(); | |
}); | |
promise.then(function(resolve) { | |
console.log('3'); | |
}) | |
.then(function(resolve) { | |
console.log('4'); |
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
Promise.resolve().then(() => console.log("promise resolved")); | |
process.nextTick(() => console.log("process.nextTick")); |
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 start = Date.now(); | |
setTimeout(() => console.log(Date.now()-start), 1000); | |
for(let i=0;i<1000;i++); |
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
setTimeout(() => console.log("1"), 0); | |
Promise.resolve().then(() => console.log("2")); | |
console.log("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
const fs = require('fs'), | |
path = require('path'), | |
filePath = path.join(__dirname, 'test.js'); | |
setTimeout(()=> console.log("setTimeout"), 0); | |
Promise.resolve().then(() => console.log("promise")) | |
fs.readFile('filePath', function() { | |
console.log('readFile'); | |
}); |
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
setImmediate(() => console.log(“setImmediate”)); | |
process.nextTick(() => console.log(“process.nextTick”)); | |
setTimeout(() => console.log(“setTimeout”), 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
const func1 = () => { | |
setImmediate(() => console.log("setImmediate1")); | |
process.nextTick(() => console.log("process.nextTick1")); | |
setTimeout(() => console.log("setTimeout1"), 0); | |
} | |
const func2 = () => { | |
setImmediate(() => console.log("setImmediate2")); | |
process.nextTick(() => console.log("process.nextTick2")); | |
setTimeout(() => console.log("setTimeout2"), 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
let arr = [1,2,3,4,5]; | |
arr.forEach(function(word) { | |
console.log(word); | |
}); | |
// 1 | |
// 2 | |
// 3 | |
// 4 | |
// 5 |
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
Array.prototype.pForEach = function(callback) { | |
for (let i = 0; i < this.length; i++) { | |
callback(this[i], i, this); | |
} | |
} |
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
const arr = [1,2,3,4]; | |
const newArr = arr.map(elem => { | |
return elem * 2 | |
}); | |
console.log(newArr); | |
// [2, 4, 6, 8] |
OlderNewer