每日3题#25以下代码执行后,控制台中的输出内容为?#leta={i:0,[Symbol.toPrimitive]:()=>++a.i,};console.log(a==1&&a==2&&a==3);26变量a会被GC吗,为什么?#functiontest(){
每日3题#
25 以下代码执行后,控制台中的输出内容为?#
| let a = { |
| i: 0, |
| [Symbol.toPrimitive]: () => ++a.i, |
| }; |
| console.log(a == 1 && a == 2 && a == 3); |
26 变量 a 会被 GC 吗,为什么?#
| function test(){ |
| var a = 1; |
| return function(){ |
| eval("") |
| } |
| } |
| |
| test(); |
27 以下代码执行后,控制台中的输出内容为?#
| console.log([2, 1, 0].reduce(Math.pow)); |
| console.log([].reduce(Math.pow)); |
公众号【今天也要写bug】, 获取更多前端面试题
答案与解析#
25#
| |
| |
| |
| |
| let a = { |
| i: 0, |
| [Symbol.toPrimitive]: () => ++a.i, |
| }; |
| console.log(a == 1 && a == 2 && a == 3); |
| |
| |
| |
26#
| |
| |
| |
| |
| |
| |
| function test() { |
| var a = 1; |
| return function () { |
| eval(""); |
| }; |
| } |
| |
| test(); |
27#
| |
| |
| |
| |
| |
| |
| console.log([2, 1, 0].reduce(Math.pow)); |
| |
| |
| |
| console.log([].reduce(Math.pow)); |
| |