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 ]

原文链接:https://github.com/lydiahallie/javascript-questions/blob/master/zh-CN/README-zh_CN.md

Javascript小白经典题型(一)的更多相关文章

  1. Javascript小白经典题型(二)

    51. 输出的是什么? function getInfo(member, year) { member.name = "Lydia"; year = "1998" ...

  2. 针对JS经典题型对全局变量及局部变量的理解浅谈

    第一次写博,还蛮激动... 看到了三题经典题型,就我目前的认识对此题进行总结.如有错误,敬请指正 首先,我们先明确一下JS引擎的工作步骤: js引擎工作分为两步: 1.将这个js中的变量和函数声明保存 ...

  3. 用原生javascript模拟经典FC游戏公路争霸

    #用原生javascript模拟经典FC游戏公路争霸 前几天看了园子里面的随笔 [原生javascript开发仿微信打飞机小游戏](http://www.cnblogs.com/Mr-Nobody/p ...

  4. 《JavaScript网页经典特效300例》

    <JavaScript网页经典特效300例> 基础篇 进阶篇 高级篇

  5. 《Javascript网页经典特性300例》

    <Javascript网页经典特性300例> 基础篇 第1章:网页特性 刷新.后退.前进.关闭.标题.跳转禁止网页放入框架动态加载js避免浏览器使用缓存加载页面 第2章:DOM操作 根据n ...

  6. javascript常用经典算法实例详解

    javascript常用经典算法实例详解 这篇文章主要介绍了javascript常用算法,结合实例形式较为详细的分析总结了JavaScript中常见的各种排序算法以及堆.栈.链表等数据结构的相关实现与 ...

  7. javascript入门经典(第五版)-清华出版社之“经典”错误

    学校教材太烂,于是自己买书. 果然是入门经典,开篇就把我惊着了~ 第九页≯1.4/ch1_example2.html / <script> //script block 2 documen ...

  8. JavaScript设计模式经典-面向对象中六大原则

    作者 | Jeskson来源 | 达达前端小酒馆 1 主要学习JavaScript中的六大原则.那么六大原则还记得是什么了吗?六大原则指:单一职责原则(SRP),开放封闭原则(OCP),里氏替换原则( ...

  9. 小白经典CNN论文复现系列(一):LeNet1989

    小白的经典CNN复现系列(一):LeNet-1989 之前的浙大AI作业的那个系列,因为后面的NLP的东西我最近大概是不会接触到,所以我们先换一个系列开始更新博客,就是现在这个经典的CNN复现啦(。・ ...

随机推荐

  1. 模块化Vs组件化

    模块化&组件化 原因 图解 模块化Module 概念 使用 目的 依赖 架构定位 内容:组件内的Script 组件化 概念 使用 目的:复用,解耦 依赖 架构定位 内容:template.st ...

  2. 微信公众号无法使用css3的多行省略

    解决通过伪元素 .text{ width: 100%; position:relative; overflow:hidden; height: 20px /* overflow : hidden; t ...

  3. Python--day20--序列化模块

    序列化:转向一个字符串数据类型 序列   ———— 字符串 序列化和反序列化的概念: 序列化三种方法:json pickle shelve json模块:json模块提供了四个方法dumps和load ...

  4. halcon坐标转换(机器人坐标转换用)

    #图像坐标r:=[431, 355, 507, 53, 507]c:=[505, 543, 316, 127, 883]#物理坐标(例如机器人坐标)r1:=[0, 2.0, -2.0, 10, -2. ...

  5. Native memory allocation (mmap) failed to map xxx bytes for committing reserved memory

    遇到问题 在服务器上运行 nexus 出现Native memory allocation (mmap) failed to map 838860800 bytes for committing re ...

  6. Springboot-webscoket with sockjs

    新建springboot maven工程,引入以下包 <dependency> <groupId>org.springframework.boot</groupId> ...

  7. P1055 连通块问题

    题目描述 给出一个n行m列的地图,'.'代表陆地,'W'代表水.现在需要你计算地图中有多少个水块.八个方向可以连通 比如:4*6的地图 ...WWW ...WW. WW.... .....W 中有3个 ...

  8. java 反射实现框架功能

    框架与框架要解决的核心问题 我做房子卖给用户住,由用户自己安装门窗和空调,我做的房子就是框架,用户需要使用我的框架,把门窗插入进我提供的框架中.框架与工具类有区别,工具类被用户的类调用,而框架则是调用 ...

  9. vue-learning:33 - component - 内置组件 - 过渡组件transition

    vue内置过渡组件transition 目录 什么是过渡 基本过渡或动画实现的语法 css过渡动画:transition / animation js过渡:特定事件钩子函数 各种情形下的过渡实现,使用 ...

  10. AutoHotKey 用打码的快捷键

    本文告诉大家如何使用 AutoHotKey 将 - 键默认输入的时候是下划线,因为使用下划线在写代码的时候是用在私有字段,而 - 很少使用 我打码经常需要使用下划线_而下划线需要按shift+- 两个 ...