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") })
以下代码输出
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