JavaScript二十道经典面试题+答案解析

1. 下面代码的输出是什么? +true;!"Lydia";

    * A: 1 and false

    * B: false and NaN

    * C: false and false

 

2. 下面代码的输出是什么?function sayHi() {  console.log(name);  console.log(age);

     var name = "Lydia";  let age = 21;}sayHi();

    * A: Lydia 和 undefined

    * B: Lydia 和 ReferenceError

    * C: ReferenceError 和 21

    * D: undefined 和 ReferenceError

 3. 下面代码的输出是什么?

for (var i = 0; i < 3; i++) {  

     setTimeout(() => console.log(i), 1);

}

for (let i = 0; i < 3; i++) {

      setTimeout(() => console.log(i), 1);

}

    * A: 0 1 2 and 0 1 2

    * B: 0 1 2 and 3 3 3

    * C: 3 3 3 and 0 1 2

 

4. 下面代码的输出是什么?

const shape = {  

       radius: 10,  

       diameter() {    

              return this.radius * 2;

       },

      perimeter: () => 2 * Math.PI * this.radius

};

shape.diameter();

shape.perimeter();

    * A: 20 and 62.83185307179586

    * B: 20 and NaN

    * C: 20 and 63

    * D: NaN and 63

 

5. 当我们这样做时会发生什么?

function bark() {  

    console.log("Woof!");

 }

bark.animal = "dog";

    * A: Nothing, this is totally fine!

    * B: SyntaxError. You cannot add properties to a function this way.

    * C: undefined

    * D: ReferenceError

 

 

6. 下面代码的输出是什么?

 let greeting;greetign = {};

 // Typo!console.log(greetign);

    * A: {}

    * B: ReferenceError: greetign is not defined

    * C: undefined

 

7. 下面代码的输出是什么?

function sum(a, b) {

     return a + b;

}

sum(1, "2");

    * A: NaN

    * B: TypeError

    * C: "12"

    * D: 3

 

8. 下面代码的输出是什么?

function getPersonInfo(one, two, three) {  

    console.log(one);  

    console.log(two);

    console.log(three);

}

const person = "Lydia";

const age = 21;

getPersonInfo`${person} is ${age} years old`;

    * A: Lydia 21 ["", "is", "years old"]

    * B: ["", "is", "years old"] Lydia 21

    * C: Lydia ["", "is", "years old"] 21

 

9. 下面代码的输出是什么?

function getAge() {

      "use strict";  

      age = 21;  

      console.log(age);

}

getAge();

    * A: 21

    * B: undefined

    * C: ReferenceError

    * D: TypeError

 

10. 下面代码的输出是什么?

var num = 8;

var num = 10;

console.log(num);

    * A: 8

    * B: 10

    * C: SyntaxError

    * D: ReferenceError

 

11. 下面代码的输出是什么?

const obj = { a: "one", b: "two", a: "three" };

console.log(obj);

    * A: { a: "one", b: "two" }

    * B: { b: "two", a: "three" }

    * C: { a: "three", b: "two" }

    * D: SyntaxError

 

12. 下面代码的输出是什么?

 const a = {};

 const b = { key: "b" };

 const c = { key: "c" };

 a[b] = 123;

 a[c] = 456;

 console.log(a[b]);

    * A: 123

    * B: 456

    * C: undefined

    * D: ReferenceError

 

13. 单击下面的html片段打印的内容是什么?

<div οnclick="console.log('div')">  

     <p οnclick="console.log('p')">    Click here!   </p>

</div>

    * A: p div

    * B: div p

    * C: p

    * D: div

 

14. 下面这些值哪些是假值?0;new Number(0);("");(" ");new Boolean(false);undefined;

    * A: 0, '', undefined

    * B: 0, new Number(0), '', new Boolean(false), undefined

    * C: 0, '', new Boolean(false), undefined

    * D: 所有都是假值

 

15. 下面代码的输出是什么?

 (() => {  

      let x, y;

      try {    

         throw new Error();

     } catch (x) {

         (x = 1), (y = 2);  

          console.log(x);

     }  

     console.log(x);

     console.log(y);})();

    * A: 1 undefined 2

    * B: undefined undefined undefined

    * C: 1 1 2

    * D: 1 undefined undefined

 

16. 下面代码的输出是什么?!!null;!!"";!!1;

    * A: false true false

    * B: false false true

    * C: false true true

    * D: true true false

 

17. 下面代码的输出是什么?

function* generator(i){

     yield i;

     yield i *2;

 }

const gen = generator(10);  

console.log(gen.next().value);

console.log(gen.next().value);

    * A: [0,10],[10,20]

    * B: 20,20

    * C: 10,20

    * D: 0,10and10,20

 

18. 下面代码的输出是什么?

let person ={ name:"Lydia"};

const members =[person];

person =null;

console.log(members);

    * A: null

    * B: [null]

    * C: [{}]

    * D: [{name:"Lydia"}]

 

19. num的值是什么?

    const num = parseInt("7*6",10);

    * A: 42

    * B: "42"

    * C: 7

    * D: NaN

 

20. 下面代码的输出是什么?

 [1,2,3].map(num =>{

     if(typeof num ==="number")return;

       return num *2;

     }

);

    * A: []

    * B: [null,null,null]

    * C: [undefined,undefined,undefined]

    * D: [3x empty]

 

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值