检验你的js知识,选择题,填空。(持续更新)

3,222 阅读4分钟

答案

介意先做一遍再去看答案, 答案 请点击这里跳转

js对象知识的考查

1.哪一个是正确的?

const bird = {
  size: 'small'
}

const mouse = {
  name: 'Mickey',
  small: true
}
  • A: mouse.bird.size是无效的
  • B: mouse[bird.size]是无效的
  • C: mouse[bird["size"]]是无效的
  • D: 以上三个选项都是有效的

2.输出是什么


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

3.下面打印出什么

var obj = {}; 
console.log(delete obj.p)
  • A: true
  • B:false
  • c:报错
  • D:undefined

4.下面的值打印出什么

let obj = {name:'jimmy',age:18}
let obj1 = obj;
obj.name = "chimmy"
console.log(obj1)
obj1 = {}
obj.age = 22

console.log(obj1)

  • A:{name:'jimmy',age:18},{name:'jimmy',age:18}
  • B: {name:'chimmy',age:18},{}
  • C: {name:'chimmy',age:18},{name:'chimmy',age:18}
  • D: {name:'chimmy',age:18},{name:'chimmy',age:22}

4.1 输出是什么

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

以上五道题考察的是对象的基础知识,如果没有全对的,可以去看看我的这篇文章 js 对象基础知识,回顾下js对象的基础知识。

数据类型以及转换相关知识点

5.请写出下面的答案

1. js截至目前有多少种数据类型,请手写出。
2. NaN === NaN 
3. typeof NaN
4. typeof null
5. typeof typeof 1
6. null == undefined
7. ""== 0
8. 1 + null
9. '1' + null
10. Number(null)
11. Number("")
12. []==0
13. []==![]
14. []==false

上面这道题考察的是数据类型强制转换和隐式转换等关于数据类型相关的知识点,如果你掌握的不是很好,可以看看我的这篇文章js数据类型知多少

包装对象相关知识

6.输出是什么?

let a = 3
let b = new Number(3)
let c = 3

console.log(a == b)
console.log(a === b)
console.log(b === c)
  • A: true false true
  • B: false false true
  • C: true false false
  • D: false true true

7.那些值是false

0
new Number(0)
('')
new Boolean(false)
undefined
new Boolean(false).valueOf()
  • A: 0''undefinednew Boolean(false).valueOf()
  • B: 0new Number(0)''new Boolean(false)undefined
  • C: 0''new Boolean(false)undefined
  • D: 全是false 上面这道题考察的是包装对象相关的知识点,如果你掌握的不是很好,可以看看我的这篇文章

数组length 知识点

8.下面说法正确的是

let arr = [1,2,3,4,5];
let arr2 = [1, , 3]
  • A:执行arr.length = 3,此时数组为 [1,2,3]
  • B:执行arr[10] = 11;此时arr.length为6
  • C: 执行delete arr[2];此时arr.length为4,数组为[1,2,4,5]
  • D: arr2.length 的长度为2 上面这道题考察的是数组length相关的知识点,如果你掌握的不是很好,可以看看我的这篇js 数组

函数知识点

9.下面打印正确的是

var f = function () { console.log('1'); } 
function f() { console.log('2'); } 
f()
  • A:1
  • B:2
  • C:报错
  • D:undefined 考察的是函数名提升的知识点,完整解析请参考js函数

10.下面打印正确的是

var a = 1; 
var x = function () { 
    console.log(a);
};
function f() {
   var a = 2; 
   x();
} 
f() 
  • A:2
  • B:1
  • C: 报错
  • D:undefined

上面这道题考察的是函数作用域相关的知识点,如果你掌握的不是很好,可以看看我的这篇js函数

事件循环知识点

11.下面输出正确的是

console.log('开始执行');
setTimeout(() => {
  console.log('timeout1')
},0);
console.log("结束了")
  • A:开始执行,timeout1,结束了
  • B:timeout1,开始执行,结束了
  • C:开始执行,结束了,timeout1

12.下面输出正确的是

Promise.resolve().then(() => {
  console.log('Promise1')
  setTimeout(function () {
    console.log("setTimeout1")
  }, 10)
})
setTimeout(() => {
  console.log('setTimeout2')
  Promise.resolve().then(() => {
    console.log('Promise2')
  })
}, 10)
  • A:Promise1,setTimeout1,setTimeout2,Promise2
  • B:Promise1,Promise2,setTimeout1,setTimeout2
  • C:Promise1,setTimeout2,setTimeout1,Promise2
  • D:Promise1,setTimeout2,Promise2,setTimeout1

上面这两道题考察的是事件循环(Event Loop)相关的知识点,如果你掌握的不是很好,可以看看我的这篇js Event Loop(事件循环)知多少,文章里有详细的讲解

原型和原型链 相关知识点

13.下面打印的值为

function A(){};
A.prototype.n = 1;
var b = new A();
A.prototype = {
  n: 2,
  m: 3
}
var c = new A();

console.log(b.n);
console.log(b.m);
console.log(c.n);
console.log(c.m);

如果对此知识点不是很理解,请参考我的这篇文章,此题解析在文中最后。

this指向问题知识点

14.下面打印name值是什么

var name = "jimmy";
var a = {
    name: "chimmy",
    fn : function () {
        console.log(this.name); 
    }
}
a.fn();

15 下面打印的值,依次是

var name = 'jimmy';
var student = {
    name: 'chimmy',
    doSth: function(){
      console.log(this.name); 
    },
    doSth2: function(){
       var arrowDoSth = () => {
           console.log(this.name);
       }
       arrowDoSth();
    },
    doSth3: () => {
       console.log(this.name); 
    }
}
student.doSth();
student.doSth2();
student.doSth3();

this指向问题,请参考文章this指向知多少,以上两道题,选自文章里的测试题。

你的点赞,就是我更新的动力。