1. 输出结果是:
(true+false)>2+true
结果是:
false
分析:
(true+false)被转换成了(1+0)=1;
1>3为false
2.下述代码的输出结果:
代码:
<script>
console.log("1");
setTimeout(function(){console.log("2")},0);
new Promise(function(resolve,reject){
resolve();
console.log("hehe");
}).then(function(){
console.log("then ok");
});
console.log("end");
</script>
输出结果为:
1
hehe
end
then ok
2
3.问下列代码的输出结果:
代码:
var a=1;
var obj={
a:'hello',
b:{
a:'end',
c:function(){
console.log(this.a)
}
}
};
obj.b.c();
输出结果为:
end
分析:在这个问题中this会指向距离它最近的,调用它的对象。
4.问题:
代码:
var a="coocaa";
var b=a+'';
console.log(a===b);
结果:
true
5:输出的正确结果:
代码:
(function(){
try{
throw new Error();
}catch(x){
var x=1,y=2;
console.log(x);
}
console.log(x);
console.log(y);
})();
运行结果为:
1
undefined
2
问题分析:try-catch的运行机制