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]