Javascript小白经典题型
Posted 一条有梦想的咸鱼
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript小白经典题型相关的知识,希望对你有一定的参考价值。
1. 输出是什么?
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
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 2
和0 1 2
- B:
0 1 2
和3 3 3
- C:
3 3 3
和0 1 2
3. 输出是什么?
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
4. 输出是什么?
+true; !"Lydia";
- A: 1 and false
- B: false and NaN
- C: false and false
5. 哪一个是正确的?
const bird = { size: ‘small‘ } const mouse = { name: ‘Mickey‘, small: true }
- A: mouse.bird.size是无效的
- B: mouse[bird.size]是无效的
- C: mouse[bird["size"]]是无效的
- D: 以上三个选项都是有效的
6. 输出是什么?
let c = { greeting: ‘Hey!‘ } let d d = c c.greeting = ‘Hello‘ console.log(d.greeting)
- A: Hello
- B: undefined
- C: ReferenceError
- D: TypeError
7. 输出是什么?
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
8. 输出是什么?
class Chameleon { static colorChange(newColor) { this.newColor = newColor return this.newColor } constructor({ newColor = ‘green‘ } = {}) { this.newColor = newColor } } const freddie = new Chameleon({ newColor: ‘purple‘ }) freddie.colorChange(‘orange‘)
- A: orange
- B: purple
- C: green
- D: TypeError
9. 输出是什么?
let greeting greetign = {} // Typo! console.log(greetign)
- A: {}
- B: ReferenceError: greetign is not defined
- C: undefined
10. 当我们这么做时,会发生什么?
function bark() {
console.log(‘Woof!‘)
}
bark.animal = ‘dog‘
- A: 正常运行!
- B: SyntaxError. 你不能通过这种方式给函数增加属性。
- C: undefined
- D: ReferenceError
11. 输出是什么?
function Person(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } const member = new Person("Lydia", "Hallie"); Person.getFullName = function () { return `${this.firstName} ${this.lastName}`; } console.log(member.getFullName());
- A: TypeError
- B: SyntaxError
- C: Lydia Hallie
- D: undefined undefined
12. 输出是什么?
function Person(firstName, lastName) { this.firstName = firstName this.lastName = lastName } const lydia = new Person(‘Lydia‘, ‘Hallie‘) const sarah = Person(‘Sarah‘, ‘Smith‘) console.log(lydia) console.log(sarah)
- A: Person {firstName: "Lydia", lastName: "Hallie"} and undefined
- B: 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: Target > Capturing > Bubbling
- B: Bubbling > Target > Capturing
- C: Target > Bubbling > Capturing
- D: Capturing > Target > Bubbling
14. 所有对象都有原型。
- A: true
- B: false
15. 输出是什么?
function sum(a, b) { return a + b } sum(1, ‘2‘)
- A: NaN
- B: TypeError
- C: "12"
- D: 3
16. 输出是什么?
let number = 0 console.log(number++) console.log(++number) console.log(number)
- A: 1 1 2
- B: 1 2 2
- C: 0 2 2
- D: 0 1 2
17. 输出是什么?
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
18. 输出是什么?
function checkAge(data) { if (data === { age: 18 }) { console.log(‘You are an adult!‘) } else if (data == { age: 18 }) { console.log(‘You are still an adult.‘) } else { console.log(`Hmm.. You don‘t have an age I guess`) } } checkAge({ age: 18 })
- A: You are an adult!
- B: You are still an adult.
- C: Hmm.. You don‘t have an age I guess
19. 输出是什么?
function getAge(...args) { console.log(typeof args) } getAge(21)
- A: "number"
- B: "array"
- C: "object"
- D: "NaN"
20. 输出是什么?
function getAge() { ‘use strict‘ age = 21 console.log(age) } getAge()
- A: 21
- B: undefined
- C: ReferenceError
- D: TypeError
21. 输出是什么?
const sum = eval(‘10*10+5‘)
- A: 105
- B: "105"
- C: TypeError
- D: "10*10+5"
22. cool_secret 可访问多长时间?
sessionStorage.setItem(‘cool_secret‘, 123)
- A: 永远,数据不会丢失。
- B: 当用户关掉标签页时。
- C: 当用户关掉整个浏览器,而不只是关掉标签页。
- D: 当用户关闭电脑时。
23. 输出是什么?
var num = 8 var num = 10 console.log(num)
- A: 8
- B: 10
- C: SyntaxError
- D: ReferenceError
24. 输出是什么?
const obj = { 1: ‘a‘, 2: ‘b‘, 3: ‘c‘ } const set = new Set([1, 2, 3, 4, 5]) obj.hasOwnProperty(‘1‘) obj.hasOwnProperty(1) set.has(‘1‘) set.has(1)
- A: false true false true
- B: false true true true
- C: true true false true
- D: true true true true
25. 输出是什么?
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
26. javascript 全局执行上下文为你做了两件事:全局对象和 this 关键字。
- A: true
- B: false
- C: it depends
27. 输出是什么?
for (let i = 1; i < 5; i++) { if (i === 3) continue console.log(i) }
- A: 1 2
- B: 1 2 3
- C: 1 2 4
- D: 1 3 4
28. 输出是什么?
String.prototype.giveLydiaPizza = () => { return ‘Just give Lydia pizza already!‘ } const name = ‘Lydia‘ name.giveLydiaPizza()
- A: "Just give Lydia pizza already!"
- B: TypeError: not a function
- C: SyntaxError
- D: undefined
29. 输出是什么?
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
30. 输出是什么?
const foo = () => console.log(‘First‘) const bar = () => setTimeout(() => console.log(‘Second‘)) const baz = () => console.log(‘Third‘) bar() foo() baz()
- A: First Second Third
- B: First Third Second
- C: Second First Third
- D: Second Third First
31. 当点击按钮时,event.target是什么?
<div onclick="console.log(‘first div‘)"> <div onclick="console.log(‘second div‘)"> <button onclick="console.log(‘button‘)"> Click! </button> </div> </div>
- A: Outer div
- B: Inner div
- C: button
- D: 一个包含所有嵌套元素的数组
32. 当您单击该段落时,日志输出是什么?
<div onclick="console.log(‘div‘)"> <p onclick="console.log(‘p‘)"> Click here! </p> </div>
- A: p div
- B: div p
- C: p
- D: div
33. 输出是什么?
const person = { name: ‘Lydia‘ } function sayHi(age) { console.log(`${this.name} is ${age}`) } sayHi.call(person, 21) sayHi.bind(person, 21)
- A: undefined is 21 Lydia is 21
- B: function function
- C: Lydia is 21 Lydia is 21
- D: Lydia is 21 function
34. 输出是什么?
function sayHi() { return (() => 0)() } typeof sayHi()
- A: "object"
- B: "number"
- C: "function"
- D: "undefined"
35. 下面哪些值是 falsy?
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: All of them are falsy
36. 输出是什么?
console.log(typeof typeof 1)
- A: "number"
- B: "string"
- C: "object"
- D: "undefined"
37. 输出是什么?
const numbers = [1, 2, 3] numbers[10] = 11 console.log(numbers)
- A: [1, 2, 3, 7 x null, 11]
- B: [1, 2, 3, 11]
- C: [1, 2, 3, 7 x empty, 11]
- D: SyntaxError
38. 输出是什么?
(() => { 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
39. JavaScript 中的一切都是?
- A: 基本类型与对象
- B: 函数与对象
- C: 只有对象
- D: 数字与对象
40. 输出是什么?
[[0, 1], [2, 3]].reduce( (acc, cur) => { return acc.concat(cur) }, [1, 2] )
- A: [0, 1, 2, 3, 1, 2]
- B: [6, 1, 2]
- C: [1, 2, 0, 1, 2, 3]
- D: [1, 2, 6]
41. 输出是什么?
!!null
!!‘‘
!!1
- A: false true false
- B: false false true
- C: false true true
- D: true true false
42. setInterval 方法的返回值是什么?
setInterval(() => console.log(‘Hi‘), 1000)
- A: 一个唯一的id
- B: 该方法指定的毫秒数
- C: 传递的函数
- D: undefined
43. 输出是什么?
[...‘Lydia‘]
- A: ["L", "y", "d", "i", "a"]
- B: ["Lydia"]
- C: [[], "Lydia"]
- D: [["L", "y", "d", "i", "a"]]
44. 输出是什么?
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, 10 and 10, 20
45. 返回值是什么?
const firstPromise = new Promise((res, rej) => { setTimeout(res, 500, "one"); }); const secondPromise = new Promise((res, rej) => { setTimeout(res, 100, "two"); }); Promise.race([firstPromise, secondPromise]).then(res => console.log(res));
- A: "one"
- B: "two"
- C: "two" "one"
- D: "one" "two"
46. 输出是什么?
let person = { name: "Lydia" }; const members = [person]; person = null; console.log(members);
- A: null
- B: [null]
- C: [{}]
- D: [{ name: "Lydia" }]
47. 输出是什么?
const person = { name: "Lydia", age: 21 }; for (const item in person) { console.log(item); }
- A: { name: "Lydia" }, { age: 21 }
- B: "name", "age"
- C: "Lydia", 21
- D: ["name", "Lydia"], ["age", 21]
48. 输出是什么?
console.log(3 + 4 + "5");
- A: "345"
- B: "75"
- C: 12
- D: "12"
49. num的值是什么?
const num = parseInt("7*6", 10);
- A: 42
- B: "42"
- C: 7
- D: NaN
50. 输出是什么?
[1, 2, 3].map(num => { if (typeof num === "number") return; return num * 2; });
- A: []
- B: [null, null, null]
- C: [undefined, undefined, undefined]
- D: [ 3 x empty ]
以上是关于Javascript小白经典题型的主要内容,如果未能解决你的问题,请参考以下文章