for(var i=0; i<6; i++) { setTimeout(() => { console.log(i) }) }
输出什么
async function async1 (){ console.log("async1") await async2() console.log("async1 end") } console.log("scripts start") async1() async function async2() { await console.log("async2") } new Promise((resolve,reject)=>{ console.log("promise1") resolve() }).then(()=>{ console.log("promise2") }) setTimeout(()=>{ console.log("setTimeout") })
输出什么
setTimeout(()=> console.log(1)) new Promise(resolve => { resolve() console.log(2) }).then(_ => { console.log(3) Promise.resolve().then(_ => { console.log(4) }).then(_ => { Promise.resolve().then(_ => { console.log(5) }) }) }) console.log(6)
以下代码输出
var a = function(){ this.b = 3 } var c = new a() a.prototype.b = 10 var b = 7 a() console.log(b)//3 console.log(c.b)//3
代码输出什么
function Foo() { getName = function () { console.log(1); } } var getName = function () { console.log(4); }; function getName() { console.log(5); } Foo.getName = function () { console.log(2) } Foo.prototype.getName = function () { console.log(3); } Foo.getName() getName() new Foo.getName()
if ([]) console.log(1); if ([].length) console.log(2); if ([] == 0) console.log(3); if ({} === {}) console.log(4);
function repeat(func, times, wait){ ... } var rp = repeat(alert, 4, 3) rp('helloWorld')
// 'A' => 1 // 'B' => 2 // 'AA' => 27
[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
{ a: { b: { c: null } } }