43道JS面试题
1. 下面代码输出是什么?
function sayHi() {
console.log(name);
console.log(age);
var name = "Lydia";
let age = 21;
}
sayHi();A:
Lydia和undefinedB:
Lydia和ReferenceErrorC:
ReferenceError和21D:
undefined和ReferenceError答案 ```````````` ``````````
关于 let、var和function:
let的’创建’过程被提升了,但是初始化没有提升。var的’创建’和’初始化’都被提升了function的’创建’、’初始化’和’赋值’都被提升了。
2. 下面代码的输出是什么?
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 2and0 1 2B:
0 1 2and3 3 3C:
3 3 3and0 1 2
3. 下面代码的输出是什么?
A:
20and62.83185307179586B:
20andNaNC:
20and63D:
NaNand63
4. 下面代码的输出是什么?
A:
1andfalseB:
falseandNaNC:
falseandfalse
5. 哪个选项是不正确的?
A:
mouse.bird.sizeB:
mouse[bird.size]C:
mouse[bird["size"]]D: All of them are valid
6. 下面代码的输出是什么?
A:
HelloB:
undefinedC:
ReferenceErrorD:
TypeError
7. 下面代码的输出是什么?
8. 下面代码的输出是什么?
A:
orangeB:
purpleC:
greenD:
TypeError
9. 下面代码的输出是什么?
A:
{}B:
ReferenceError: greetign is not definedC:
undefined
10. 当我们这样做时会发生什么?
A:
Nothing, this is totally fine!B:
SyntaxError. You cannot add properties to a function this way.C:
undefinedD:
ReferenceError
11. 下面代码的输出是什么?
A:
TypeErrorB:
SyntaxErrorC:
Lydia HallieD:
undefined undefined
12. 下面代码的输出是什么?
A:
Person {firstName: "Lydia", lastName: "Hallie"} and undefinedB:
Person {firstName: "Lydia", lastName: "Hallie"} and Person {firstName: "Sarah", lastName: "Smith"}C:
Person {firstName: "Lydia", lastName: "Hallie"} and {}D:
Person {firstName: "Lydia", lastName: "Hallie"} and ReferenceError
13. 所有对象都有原型.
A: 对
B: 错误
14. 下面代码的输出是什么?
A:
NaNB:
TypeErrorC:
"12"D:
3
15. 下面代码的输出是什么?
A:
1 1 2B:
1 2 2C:
0 2 2D:
0 1 2
16. 下面代码的输出是什么?
A:
Lydia 21 ["", "is", "years old"]B:
["", "is", "years old"] Lydia 21C:
Lydia ["", "is", "years old"] 21
17. 下面代码的输出是什么?
A:
You are an adult!B:
You are still an adult.C:
Hmm.. You don't have an age I guess
18. 下面代码的输出是什么?
A:
"number"B:
"array"C:
"object"D:
"NaN"
19. 事件传播的三个阶段是什么??
A: 目标 > 捕获 > 冒泡
B: 冒泡 > 目标 > 捕获
C: 目标 > 冒泡 > 捕获
D: 捕获 > 目标 > 冒泡
20. 下面代码的输出是什么?
A:
21B:
undefinedC:
ReferenceErrorD:
TypeError
21. 下面代码的输出是什么?
A:
105B:
"105"C:
TypeErrorD:
"10\*10+5"
22. cool_secret 可以访问多长时间?
A:永远,数据不会丢失。 B:用户关闭选项卡时。 C:当用户关闭整个浏览器时,不仅是选项卡。 D:用户关闭计算机时。
23. 下面代码的输出是什么?
A:
8B:
10C:
SyntaxErrorD:
ReferenceError
24. 下面代码的输出是什么?
A:
false true false trueB:
false true true trueC:
true true false trueD:
true true true true
25. 下面代码的输出是什么?
A:
{ a: "one", b: "two" }B:
{ b: "two", a: "three" }C:
{ a: "three", b: "two" }D:
SyntaxError
26. JavaScript 全局执行上下文为你创建了两个东西:全局对象和 this 关键字.
A: 对
B: 错误
C: 视情况而定
27. 下面代码的输出是什么?
A:
1 2B:
1 2 3C:
1 2 4D:
1 3 4
28. 下面代码的输出是什么?
A:
"Just give Lydia pizza already!"B:
TypeError: not a functionC:
SyntaxErrorD:
undefined
29. 下面代码的输出是什么?
A:
123B:
456C:
undefinedD:
ReferenceError
30. 下面代码的输出是什么?
A:
FirstSecondThirdB:
FirstThirdSecondC:
SecondFirstThirdD:
SecondThirdFirst
31. 单击按钮时 event.target 是什么?
A:
div 外部B:
div 内部C:
buttonD:
所有嵌套元素的数组.
32. 单击下面的 html 片段打印的内容是什么?
A:
pdivB:
divpC:
pD:
div
33. 下面代码的输出是什么?
A:
undefined is 21 Lydia is 21B:
function functionC:
Lydia is 21 Lydia is 21D:
Lydia is 21 function
34. 下面代码的输出是什么?
A:
"object"B:
"number"C:
"function"D:
"undefined"
35. 下面这些值哪些是假值?
A:
0, '', undefinedB:
0, new Number(0), '', new Boolean(false), undefinedC:
0, '', new Boolean(false), undefinedD:
所有都是假值
36. 下面代码的输出是什么?
A:
"number"B:
"string"C:
"object"D:
"undefined"
37. 下面代码的输出是什么?
A:
[1, 2, 3, 7 x null, 11]B:
[1, 2, 3, 11]C:
[1, 2, 3, 7 x empty, 11]D:
SyntaxError
38. 下面代码的输出是什么?
A:
1undefined2B:
undefinedundefinedundefinedC:
112D:
1undefinedundefined
39. JavaScript 中的所有内容都是…
A:原始或对象
B:函数或对象
C:技巧问题!只有对象
D:数字或对象
40. 下面代码的输出是什么?
A:
[0, 1, 2, 3, 1, 2]B:
[6, 1, 2]C:
[1, 2, 0, 1, 2, 3]D:
[1, 2, 6]
41. 下面代码的输出是什么?
A:
falsetruefalseB:
falsefalsetrueC:
falsetruetrueD:
truetruefalse
42. setInterval 方法的返回值什么?
A:一个唯一的 id
B:指定的毫秒数
C:传递的函数
D:undefined
43. 下面代码的返回值是什么?
A:
["L", "y", "d", "i", "a"]B:
["Lydia"]C:
[[], "Lydia"]D:
[["L", "y", "d", "i", "a"]]
最后更新于