Javascript的复习题
- num的值是什么?
C:数值转换 parseInt(字符串) 提取开头数字
const num = parseInt("7*6",10);
A: 42
B: “42”
C: 7
D: NaN
- 下面代码的输出是什么?
B:浅拷贝,members复制person地址,person改变,members改变
运行后答案为D:引用类型的数据地址赋值 members复制person原地址,person引用类型的地址指向null,members仍指向person原来地址
let person = { name:"Lydia" };
const members = [person];
person = null;
console.log(members);
A: null
B: [null]
C: [{ }]
D: [{ name:“Lydia” }]
3.下面代码的输出是什么?
B
function Car(){
this.make = "AAA";
return { make:"BBB" };
}
const myCar = new Car();
console.log(myCar.make);
A: “AAA”
B: “BBB”
C: ReferenceError
D: TypeError
4.下面代码的输出是什么?
A :y=10 全局作用 let x=y 块级作用
(() => {
let x = (y = 10);
})();
console.log(typeof x);
console.log(typeof y);
A: “undefined”,“number”
B: “number”,“number”
C: “object”,“number”
D: “number”,undefined
5.下面代码的输出是什么?
A:delete删除对象原型属性,再调用时报错
class Dog {
constructor(name){
this.name = name
}
}
Dog.prototype.bark = function(){
console.log(`Woof I am ${this.name}`);
};
const pet = new Dog("Mara");
pet.bark();
delete Dog.prototype.bark;
pet.bark();
A: “Woof I am Mara”,TypeError
B: “Woof I am Mara”,“Woof I am Mara”
C: “Woof I am Mara”,undefined
D: TypeError,TypeError
6.下面代码的输出是什么?
D:set去重
const set = new Set([1,1,2,3,4]);
console.log(set);
A: [1,1,2,3,4]
B: [1,2,3,4]
C: {1,1,2,3,4}
D: {1,2,3,4}
7.下面代码的输出是什么?
D:导出:export default 变量名 导入:import 变量名/新变量名 from 路径
运行后答案为C:引入的模块是只读的,不能修改
// counter.js
let counter = 10;
export default counter;
// index.js
import myCounter from './counter';
myCounter += 1;
console.log(myCounter);
A: 10
B: 11
C: Error
D: NaN
8.下面代码的输出是什么?
A:delete关键字:返回布尔值,删除成功返回true
1.删除对象的属性,删除不存在的属性,返回true
2.删除没有使用var关键字声明的全局变量
使用let和const声明的变量不能从作用域范围被delete
3.删除数组元素
4.不能删除内置对象的属性
5.不能直接删除从原型上继承的属性
const name = "Lydia";
age = 21;
console.log(delete name);
console.log(delete age);
A: false,true
B: “Lydia”,21
C: true,true
D: undefined,undefined
9.下面代码的输出是什么?
C:数组的解构赋值
const numbers = [1,2,3,4,5];
const [y] = numbers;
console.log(y);
A: [ [1,2,3,4,5] ]
B: [1,2,3,4,5]
C: 1
D: [1]
10.下面代码的输出是什么?
B:…展开对象变成键值对列表
const user = { name:"Lydia",age:21 };
const admin = { admin:true,...user };
console.log(admin)
A: { admin:true,user:{ name:“Lydia”,age:21 } }
B: { admin:true,name:“Lydia”,age:21 }
C: { admin:true,user:[“Lydia”,21] }
D: { admin:true }
11.下面代码的输出是什么?
B:defineProperty定义新属性,enumerable默认false,循环得不到
const person = { name:"Lydia" };
Object.defineProperty(person,"age",{ value:21 });
console.log(person);
console.log(Object.keys(person));
A: { name:“Lydia”,age:21 },[“name”,“age”]
B: { name:“Lydia”,age:21 },[“name”]
C: { name:“Lydia” },[“name”,“age”]
D: { name:“Lydia” },[“age”]
12.下面代码的输出是什么?
A:JSON.stringify 转换为JSON字符串,settings-要转换的值 [ ]-转换结果
const settings = {
username:"lydiahallie",
level:19,
health:90
};
const data = JSON.stringify(settings,["level","health"]);
console.log(data);
A: “{“level”:19, “health”:90}”
B: “{“username”: “lydiahallie”}”
C: “[“level”, “health”]”
D: “{“username”: “lydiahallie”, “level”:19, “health”:90}”
13.下面代码的输出是什么?
A:num++ 先返回值再自增
let num = 10;
const increaseNumber = () => num++;
const increasePassedNumber = number => number++;
const num1 = increaseNumber();
const num2 = increasePassedNumber(num1);
console.log(num1);
console.log(num2);
A: 10,10
B: 10,11
C: 11,11
D: 11,12
14.下面代码的输出是什么?
C:multiply()中x赋值为…value,multiply(value)中value赋值为…value,后续计算改变value
const value = { number:10 };
const multiply = (x = { ...value } => {
console.log(x.number *= 2)
});
multiply();
multiply();
multiply(value);
multiply(value);
A: 20,40,80,160
B: 20,41,20,40
C: 20,20,20,40
D: NaN,NaN,20,40
15.下面代码的输出是什么?
D:array.reduce(function(total,currentValue)) total初始值 currentValue当前元素
[1,2,3,4].reduce((x,y) => console.log(x,y))
A: 1 2 , 3 3 , 6 4
B: 1 2 , 2 3 , 3 4
C: 1 undefined , 2 undefined , 3 undefined , 4 undefined
D: 1 2 , undefined 3 , undefined 4
16.使用哪个构造函数可以成功继承 Dog类?
B:子类constructor()必须包含父类constructor()参数
子类constructor()内部顶部必须执行一次super()方法
class Dog {
constructor(name){
this.name = name
}
};
class Labrador extends Dog {
//1
constructor(name,size){
this.size = size
}
//2
constructor(name,size){
super(name);
this.size = size;
}
//3
constructor(size){
super(name);
this.size = size;
}
//4
constructor(name,size){
this.name = name;
this.size = size;
}
};
A: 1
B: 2
C: 3
D: 4
17.下面代码的输出是什么?
B:先运行sum.js,再运行index.js
//index.js
console.log('running index.js');
import { sum } from './sum.js';
console.log(sum(1,2));
//sum.js
console.log('running sum.js');
export const sum = (a,b) => a + b;
A: running index.js , running sum.js , 3
B: running sum.js , running index.js , 3
C: running sum.js , 3 , running index.js
D: running index.js , undefined , running sum.js
18.下面代码的输出是什么?
A:Symbol值唯一
console.log(Number(2) === Number(2))
console.log(Boolean(false) === Boolean(false))
console.log(Symbol('foo') === Symbol('foo'))
A: true , true , false
B: false , true , false
C: true , false , true
D: true , true , true
19.下面代码的输出是什么?
C:前面补空格补全13位,前面补一个空格;补全长度小于原长度不补全
const name = "Lydia Hallie"
console.log(name.padStart(13))
console.log(name.padStart(2))
A: “Lydia Hallie” , “Lydia Hallie”
B: " Lydia Hallie" , " Lydia Hallie" ( “[13x whitespace]Lydia Hallie”, “[2x whitespace]Lydia Hallie”)
C: " Lydia Hallie" , “Lydia Hallie” ( “[1x whitespace]Lydia Hallie”, “Lydia Hallie”)
D: “Lydia Hallie” , “Lyd”
20.下面代码的输出是什么?
C:Promise.resolve返回Promise对象,没有resolved状态
await等待promise解决,返回挂起状态,调用.then()方法后可输出结果
async function getData(){
return await Promise.resolve("I made it!");
}
const data = getData();
console.log(data);
A: “I made it!”
B: Promise { : “I made it!” }
C: Promise{ }
D: undefined
21.下面代码的输出是什么?
B:将apple push到数组中,push返回数组长度
function addToList(item,list){
return list.push(item)
}
const result = addToList("apple",["banana"]);
console.log(result);
A: [‘apple’,‘banana’]
B: 2
C: true
D: undefined