text: (window.webpackJsonp=window.webpackJsonp||[]).push([[12],{362:function(s,t,a){"use strict";a.r(t);var n=a(43),e=Object(n.a)({},(function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[a("h1",{attrs:{id:"每日一题"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#每日一题"}},[s._v("#")]),s._v(" 每日一题  💌")]),s._v(" "),a("p",[s._v("原repo地址: "),a("a",{attrs:{href:"https://github.com/lydiahallie/javascript-questions",target:"_blank",rel:"noopener noreferrer"}},[s._v("javascript-questions"),a("OutboundLink")],1)]),s._v(" "),a("h2",{attrs:{id:"简介"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#简介"}},[s._v("#")]),s._v(" 简介")]),s._v(" "),a("p",[s._v("从基础到进阶，测试你有多了解 JavaScript，刷新你的知识，或者帮助你的 coding 面试！\n💪 🚀 我每周都会在这个仓库下更新新的问题。")]),s._v(" "),a("p",[s._v("答案在问题下方的折叠部分，点击即可展开问题。祝你好运 ❤️")]),s._v(" "),a("hr"),s._v(" "),a("h2",{attrs:{id:"question-1-20"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#question-1-20"}},[s._v("#")]),s._v(" question: 1-20")]),s._v(" "),a("h4",{attrs:{id:"_1-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_1-输出是什么？"}},[s._v("#")]),s._v(" 1. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("age"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("var")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Lydia'")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" age "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("Lydia")]),s._v(" 和 "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Lydia")]),s._v(" 和 "),a("code",[s._v("ReferenceError")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("ReferenceError")]),s._v(" 和 "),a("code",[s._v("21")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")]),s._v(" 和 "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("在函数内部，我们首先通过 "),a("code",[s._v("var")]),s._v(" 关键字声明了 "),a("code",[s._v("name")]),s._v(" 变量。这意味着变量被提升了（内存空间在创建阶段就被设置好了），直到程序运行到定义变量位置之前默认值都是 "),a("code",[s._v("undefined")]),s._v("。因为当我们打印 "),a("code",[s._v("name")]),s._v(" 变量时还没有执行到定义变量的位置，因此变量的值保持为 "),a("code",[s._v("undefined")]),s._v("。")]),s._v(" "),a("p",[s._v("通过 "),a("code",[s._v("let")]),s._v(" 和 "),a("code",[s._v("const")]),s._v(" 关键字声明的变量也会提升，但是和 "),a("code",[s._v("var")]),s._v(" 不同，它们不会被"),a("i",[s._v("初始化")]),s._v("。在我们声明（初始化）之前是不能访问它们的。这个行为被称之为暂时性死区。当我们试图在声明之前访问它们时，JavaScript 将会抛出一个 "),a("code",[s._v("ReferenceError")]),s._v(" 错误。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_2-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_2-输出是什么？"}},[s._v("#")]),s._v(" 2. 输出是什么？")]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("var")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setTimeout")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setTimeout")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("0 1 2")]),s._v(" 和 "),a("code",[s._v("0 1 2")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("0 1 2")]),s._v(" 和 "),a("code",[s._v("3 3 3")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("3 3 3")]),s._v(" 和 "),a("code",[s._v("0 1 2")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("由于 JavaScript 的事件循环，"),a("code",[s._v("setTimeout")]),s._v(" 回调会在"),a("em",[s._v("遍历结束后")]),s._v("才执行。因为在第一个遍历中遍历 "),a("code",[s._v("i")]),s._v(" 是通过 "),a("code",[s._v("var")]),s._v(" 关键字声明的，所以这个值是全局作用域下的。在遍历过程中，我们通过一元操作符 "),a("code",[s._v("++")]),s._v(" 来每次递增 "),a("code",[s._v("i")]),s._v(" 的值。当 "),a("code",[s._v("setTimeout")]),s._v(" 回调执行的时候，"),a("code",[s._v("i")]),s._v(" 的值等于 3。")]),s._v(" "),a("p",[s._v("在第二个遍历中，遍历 "),a("code",[s._v("i")]),s._v(" 是通过 "),a("code",[s._v("let")]),s._v(" 关键字声明的：通过 "),a("code",[s._v("let")]),s._v(" 和 "),a("code",[s._v("const")]),s._v(" 关键字声明的变量是拥有块级作用域（指的是任何在 {} 中的内容）。在每次的遍历过程中，"),a("code",[s._v("i")]),s._v(" 都有一个新值，并且每个值都在循环内的作用域中。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_3-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_3-输出是什么？"}},[s._v("#")]),s._v(" 3. 输出是什么？")]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" shape "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  radius"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("diameter")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("radius "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("perimeter")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" Math"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token constant"}},[s._v("PI")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("radius\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nshape"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("diameter")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nshape"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("perimeter")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("20")]),s._v(" and "),a("code",[s._v("62.83185307179586")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("20")]),s._v(" and "),a("code",[s._v("NaN")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("20")]),s._v(" and "),a("code",[s._v("63")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("NaN")]),s._v(" and "),a("code",[s._v("63")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("注意 "),a("code",[s._v("diameter")]),s._v(" 的值是一个常规函数，但是 "),a("code",[s._v("perimeter")]),s._v(" 的值是一个箭头函数。")]),s._v(" "),a("p",[s._v("对于箭头函数，"),a("code",[s._v("this")]),s._v(" 关键字指向的是它当前周围作用域（简单来说是包含箭头函数的常规函数，如果没有常规函数的话就是全局对象），这个行为和常规函数不同。这意味着当我们调用 "),a("code",[s._v("perimeter")]),s._v(" 时，"),a("code",[s._v("this")]),s._v(" 不是指向 "),a("code",[s._v("shape")]),s._v(" 对象，而是它的周围作用域（在例子中是 "),a("code",[s._v("window")]),s._v("）。")]),s._v(" "),a("p",[s._v("在 "),a("code",[s._v("window")]),s._v(" 中没有 "),a("code",[s._v("radius")]),s._v(" 这个属性，因此返回 "),a("code",[s._v("undefined")]),s._v("。")]),s._v(" "),a("p"),s._v(" "),a("p"),a("blockquote",[a("p",[a("em",[a("strong",[s._v("执行上下文")])]),s._v(" 是评估和执行 JavaScript 代码的环境的抽象概念。每当 Javascript 代码在运行的时候，它都是在执行上下文中运行。\nJavaScript 中有三种执行上下文类型:")]),s._v(" "),a("p",[s._v("1."),a("strong",[s._v("全局执行上下文")]),s._v(" — 这是默认或者说基础的上下文，任何不在函数内部的代码都在全局上下文中。它会执行两件事：创建一个全局的 window 对象（浏览器的情况下），并且设置 this 的值等于这个全局对象。一个程序中只会有一个全局执行上下文。")]),s._v(" "),a("p",[s._v("2."),a("strong",[s._v("函数执行上下文")]),s._v(" — 每当一个函数被调用时, 都会为该函数创建一个新的上下文。每个函数都有它自己的执行上下文，不过是在函数被调用时创建的。函数上下文可以有任意多个。每当一个新的执行上下文被创建，它会按定义的顺序（将在后文讨论）执行一系列步骤。")]),s._v(" "),a("p",[s._v("3."),a("strong",[s._v("Eval 函数执行上下文")]),s._v(" — 执行在 eval 函数内部的代码也会有它属于自己的执行上下文，但由于 JavaScript 开发者并不经常使用 eval，所以在这里我不会讨论它。")]),s._v(" "),a("p",[a("a",{attrs:{href:"https://juejin.im/post/5ba32171f265da0ab719a6d7",target:"_blank",rel:"noopener noreferrer"}},[s._v("关于执行上下文和执行栈的传送门"),a("OutboundLink")],1)])]),s._v(" "),a("blockquote",[a("blockquote",[a("p",[s._v("回到本题，箭头函数的"),a("code",[s._v("this")]),s._v("指向的是它的执行上下文，简而言之要么是包含剪头函数的常规函数，要么是全局对象，上述"),a("code",[s._v("perimeter")]),s._v("的"),a("code",[s._v("this")]),s._v("则是指向的是全局执行上下文"),a("code",[s._v("window")])]),a("p")])])]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_4-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_4-输出是什么？"}},[s._v("#")]),s._v(" 4. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("true")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Lydia'")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("1")]),s._v(" and "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("false")]),s._v(" and "),a("code",[s._v("NaN")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("false")]),s._v(" and "),a("code",[s._v("false")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("一元操作符加号尝试将 bool 转为 number。"),a("code",[s._v("true")]),s._v(" 转换为 number 的话为 "),a("code",[s._v("1")]),s._v("，"),a("code",[s._v("false")]),s._v(" 为 "),a("code",[s._v("0")]),s._v("。")]),s._v(" "),a("p",[s._v("字符串 "),a("code",[s._v("'Lydia'")]),s._v(" 是一个真值，真值取反那么就返回 "),a("code",[s._v("false")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_5-哪一个是无效的？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_5-哪一个是无效的？"}},[s._v("#")]),s._v(" 5. 哪一个是无效的？")]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" bird "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  size"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'small'")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" mouse "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Mickey'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  small"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("true")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("mouse.bird.size")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("mouse[bird.size]")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('mouse[bird["size"]]')])]),s._v(" "),a("li",[s._v("D: All of them are valid")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-2"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("在 JavaScript 中，所有对象的 keys 都是字符串（除非对象是 Symbol）。尽管我们可能不会定义它们为字符串，但它们在底层总会被转换为字符串。")]),s._v(" "),a("p",[s._v("当我们使用括号语法时（[]），JavaScript 会解释（或者 unboxes）语句。它首先看到第一个开始括号 "),a("code",[s._v("[")]),s._v(" 并继续前进直到找到结束括号 "),a("code",[s._v("]")]),s._v("。只有这样，它才会计算语句的值。")]),s._v(" "),a("p",[a("code",[s._v("mouse[bird.size]")]),s._v("：首先计算 "),a("code",[s._v("bird.size")]),s._v("，这会得到 "),a("code",[s._v("small")]),s._v("。"),a("code",[s._v('mouse["small"]')]),s._v(" 返回 "),a("code",[s._v("true")]),s._v("。")]),s._v(" "),a("p",[s._v("然后使用点语法的话，上面这一切都不会发生。"),a("code",[s._v("mouse")]),s._v(" 没有 "),a("code",[s._v("bird")]),s._v(" 这个 key，这也就意味着 "),a("code",[s._v("mouse.bird")]),s._v(" 是 "),a("code",[s._v("undefined")]),s._v("。然后当我们使用点语法 "),a("code",[s._v("mouse.bird.size")]),s._v(" 时，因为 "),a("code",[s._v("mouse.bird")]),s._v(" 是 "),a("code",[s._v("undefined")]),s._v("，这也就变成了 "),a("code",[s._v("undefined.size")]),s._v("。这个行为是无效的，并且会抛出一个错误类似 "),a("code",[s._v('Cannot read property "size" of undefined')]),s._v("。")]),s._v(" "),a("p"),s._v(" "),a("p"),a("blockquote",[a("p",[a("em",[a("strong",[s._v("Symbol对象")])])]),s._v(" "),a("p",[s._v("ES6 引入了一种新的原始数据类型Symbol，表示独一无二的值。它是 JavaScript 语言的第七种数据类型，前六种是：undefined、null、布尔值（Boolean）、字符串（String）、数值（Number）、对象（Object）。")]),s._v(" "),a("p",[s._v("Symbol 值通过Symbol函数生成。这就是说，对象的属性名现在可以有两种类型，一种是原来就有的字符串，另一种就是新增的 Symbol 类型。凡是属性名属于 Symbol 类型，就都是独一无二的，可以保证不会与其他属性名产生冲突。")]),s._v(" "),a("ul",[a("li",[s._v("Symbol 值作为对象属性名时，不能用点运算符")]),s._v(" "),a("li",[s._v("在对象的内部，使用 Symbol 值定义属性时，Symbol 值必须放在方括号之中。")]),s._v(" "),a("li",[s._v("消除魔术字符串，减少耦合")]),s._v(" "),a("li",[s._v("遍历：symbol属性名不能被诸如"),a("code",[s._v("for..in、Object.keys()、Object.getOwnPropertyNames()、JSON.stringify()")]),s._v("等遍历到，需要使用 "),a("code",[s._v("Object.getOwnPropertySymbols(obj)")]),s._v("，一个新的 API，"),a("code",[s._v("Reflect.ownKeys(obj)")]),s._v("方法可以返回所有类型的键名，包括常规键名和 Symbol 键名,该方法与"),a("code",[s._v("Object.keys(obj)")]),s._v("类似")])]),s._v(" "),a("p",[a("a",{attrs:{href:"http://es6.ruanyifeng.com/#docs/symbol",target:"_blank",rel:"noopener noreferrer"}},[s._v("symbol传送门"),a("OutboundLink")],1)]),a("p")])]),s._v(" "),a("h4",{attrs:{id:"_6-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_6-输出是什么？"}},[s._v("#")]),s._v(" 6. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" c "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" greeting"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Hey!'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" d\n\nd "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" c\nc"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("greeting "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Hello'")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("d"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("greeting"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("Hello")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("ReferenceError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("TypeError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-3"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-3"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("在 JavaScript 中，当设置两个对象彼此相等时，它们会通过"),a("em",[s._v("引用")]),s._v("进行交互。")]),s._v(" "),a("p",[s._v("首先，变量 "),a("code",[s._v("c")]),s._v(" 的值是一个对象。接下来，我们给 "),a("code",[s._v("d")]),s._v(" 分配了一个和 "),a("code",[s._v("c")]),s._v(" 对象相同的引用。")]),s._v(" "),a("img",{attrs:{src:"https://camo.githubusercontent.com/bd30403debc9a753512d0097f47958808974525c/68747470733a2f2f692e696d6775722e636f6d2f6b6f356b3066732e706e67",width:"200"}}),s._v(" "),a("p",[s._v("因此当我们改变其中一个对象时，其实是改变了所有的对象。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_7-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_7-输出是什么？"}},[s._v("#")]),s._v(" 7. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" a "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" b "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Number")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" c "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("a "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("==")]),s._v(" b"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("a "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" b"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("b "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" c"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("true")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-2"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[a("code",[s._v("new Number()")]),s._v(" 是一个内建的函数构造器。虽然它看着像是一个 number，但它实际上并不是一个真实的 number：它有一堆额外的功能并且它是一个对象。")]),s._v(" "),a("p",[s._v("当我们使用 "),a("code",[s._v("==")]),s._v(" 操作符时，它只会检查两者是否拥有相同的"),a("em",[s._v("值")]),s._v("。因为它们的值都是 "),a("code",[s._v("3")]),s._v("，因此返回 "),a("code",[s._v("true")]),s._v("。")]),s._v(" "),a("p",[s._v("然后，当我们使用 "),a("code",[s._v("===")]),s._v(" 操作符时，两者的值以及"),a("em",[s._v("类型")]),s._v("都应该是相同的。"),a("code",[s._v("new Number()")]),s._v(" 是一个对象而不是 number，因此返回 "),a("code",[s._v("false")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_8-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_8-输出是什么？"}},[s._v("#")]),s._v(" 8. 输出是什么？")]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Chameleon")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("static")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("colorChange")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("newColor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("newColor "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" newColor\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("newColor\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" newColor "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'green'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("newColor "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" newColor\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" freddie "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Chameleon")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" newColor"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'purple'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nfreddie"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("colorChange")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'orange'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("orange")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("purple")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("green")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("TypeError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-2"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[a("code",[s._v("colorChange")]),s._v(" 是一个静态方法。静态方法被设计为只能被创建它们的构造器使用（也就是 "),a("code",[s._v("Chameleon")]),s._v("），并且不能传递给实例。因为 "),a("code",[s._v("freddie")]),s._v(" 是一个实例，静态方法不能被实例使用，因此抛出了 "),a("code",[s._v("TypeError")]),s._v(" 错误。")]),s._v(" "),a("p"),s._v(" "),a("p"),a("blockquote",[a("p",[a("RouterLink",{attrs:{to:"/article/JavaScript/Class.html"}},[s._v("Class基础传送门")])],1)]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_9-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_9-输出是什么？"}},[s._v("#")]),s._v(" 9. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" greeting\ngreetign "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// Typo!")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("greetign"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("{}")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("ReferenceError: greetign is not defined")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-4"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-4"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("代码打印出了一个对象，这是因为我们在全局对象上创建了一个空对象！当我们将 "),a("code",[s._v("greeting")]),s._v(" 写错成 "),a("code",[s._v("greetign")]),s._v(" 时，JS 解释器实际在上浏览器中将它视为 "),a("code",[s._v("global.greetign = {}")]),s._v(" （或者 "),a("code",[s._v("window.greetign = {}")]),s._v("）。")]),s._v(" "),a("p",[s._v('为了避免这个为题，我们可以使用 `"use strict"。这能确保当你声明变量时必须赋值。')]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_10-当我们这么做时，会发生什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_10-当我们这么做时，会发生什么？"}},[s._v("#")]),s._v(" 10. 当我们这么做时，会发生什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("bark")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Woof!'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nbark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("animal "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'dog'")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: 正常运行!")]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("SyntaxError")]),s._v(". 你不能通过这种方式给函数增加属性。")]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-5"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-5"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("这在 JavaScript 中是可以的，因为函数是对象！（除了基本类型之外其他都是对象）")]),s._v(" "),a("p",[s._v("函数是一个特殊的对象。你写的这个代码其实不是一个实际的函数。函数是一个拥有属性的对象，并且属性也可被调用。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_11-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_11-输出是什么？"}},[s._v("#")]),s._v(" 11. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Person")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("firstName"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" lastName")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("firstName "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" firstName"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("lastName "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" lastName"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" member "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Person")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Hallie"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nPerson"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("getFullName")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("firstName"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v(" ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("lastName"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("member"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getFullName")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("TypeError")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("SyntaxError")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Lydia Hallie")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-6"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-6"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("你不能像常规对象那样，给构造函数添加属性。如果你想一次性给所有实例添加特性，你应该使用原型。因此本例中，使用如下方式：")]),s._v(" "),a("div",{staticClass:"language-js line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Person")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("prototype"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("getFullName")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("firstName"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v(" ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("lastName"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("p",[s._v("这才会使 "),a("code",[s._v("member.getFullName()")]),s._v(" 起作用。为什么这么做有益的？假设我们将这个方法添加到构造函数本身里。也许不是每个 "),a("code",[s._v("Person")]),s._v(" 实例都需要这个方法。这将浪费大量内存空间，因为它们仍然具有该属性，这将占用每个实例的内存空间。相反，如果我们只将它添加到原型中，那么它只存在于内存中的一个位置，但是所有实例都可以访问它！")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_12-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_12-输出是什么？"}},[s._v("#")]),s._v(" 12. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Person")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("firstName"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" lastName")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("firstName "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" firstName\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("lastName "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" lastName\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" lydia "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Person")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Lydia'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Hallie'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" sarah "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Person")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Sarah'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Smith'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("lydia"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("sarah"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),s._v(" and "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),s._v(" and "),a("code",[s._v('Person {firstName: "Sarah", lastName: "Smith"}')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),s._v(" and "),a("code",[s._v("{}")])]),s._v(" "),a("li",[s._v("D:"),a("code",[s._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),s._v(" and "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-7"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-7"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("对于 "),a("code",[s._v("sarah")]),s._v("，我们没有使用 "),a("code",[s._v("new")]),s._v(" 关键字。当使用 "),a("code",[s._v("new")]),s._v(" 时，"),a("code",[s._v("this")]),s._v(" 引用我们创建的空对象。当未使用 "),a("code",[s._v("new")]),s._v(" 时，"),a("code",[s._v("this")]),s._v(" 引用的是"),a("strong",[s._v("全局对象")]),s._v("（global object）。")]),s._v(" "),a("p",[s._v("我们说 "),a("code",[s._v("this.firstName")]),s._v(" 等于 "),a("code",[s._v('"Sarah"')]),s._v("，并且 "),a("code",[s._v("this.lastName")]),s._v(" 等于 "),a("code",[s._v('"Smith"')]),s._v("。实际上我们做的是，定义了 "),a("code",[s._v("global.firstName = 'Sarah'")]),s._v(" 和 "),a("code",[s._v("global.lastName = 'Smith'")]),s._v("。而 "),a("code",[s._v("sarah")]),s._v(" 本身是 "),a("code",[s._v("undefined")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_13-事件传播的三个阶段是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_13-事件传播的三个阶段是什么？"}},[s._v("#")]),s._v(" 13. 事件传播的三个阶段是什么？")]),s._v(" "),a("ul",[a("li",[s._v("A: Target > Capturing > Bubbling")]),s._v(" "),a("li",[s._v("B: Bubbling > Target > Capturing")]),s._v(" "),a("li",[s._v("C: Target > Bubbling > Capturing")]),s._v(" "),a("li",[s._v("D: Capturing > Target > Bubbling")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-3"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-3"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("在"),a("strong",[s._v("捕获")]),s._v("（capturing）阶段中，事件从祖先元素向下传播到目标元素。当事件达到"),a("strong",[s._v("目标")]),s._v("（target）元素后，"),a("strong",[s._v("冒泡")]),s._v("（bubbling）才开始。")]),s._v(" "),a("p",[a("img",{attrs:{src:"https://camo.githubusercontent.com/1e3f6d3b059bbfcacaf2e694a46c5b81cae333f4/68747470733a2f2f692e696d6775722e636f6d2f4e31386f5267642e706e67",alt:"Capturing > Target > Bubbling"}})]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_14-所有对象都有原型。"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_14-所有对象都有原型。"}},[s._v("#")]),s._v(" 14. 所有对象都有原型。")]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("ul",[a("li",[s._v("A: true")]),s._v(" "),a("li",[s._v("B: false")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-2"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-2"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("除了"),a("strong",[s._v("基本对象")]),s._v("（base object），所有对象都有原型。基本对象可以访问一些方法和属性，比如 "),a("code",[s._v(".tostring")]),s._v("。这就是为什么你可以使用内置的 JavaScript 方法！所有这些方法在原型上都是可用的。虽然 JavaScript 不能直接在对象上找到这些方法，但 JavaScript 会沿着原型链找到它们，以便于你使用。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_15-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_15-输出是什么？"}},[s._v("#")]),s._v(" 15. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sum")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("a"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" b")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" a "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" b\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sum")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'2'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("NaN")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("TypeError")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"12"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("3")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-3"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-3"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("JavaScript 是一种"),a("strong",[s._v("动态类型语言")]),s._v("：我们不指定某些变量的类型。值可以在你不知道的情况下自动转换成另一种类型，这种类型称为"),a("strong",[s._v("隐式类型转换")]),s._v("（implicit type coercion）。"),a("strong",[s._v("Coercion")]),s._v(" 是指将一种类型转换为另一种类型。")]),s._v(" "),a("p",[s._v("在本例中，JavaScript 将数字 "),a("code",[s._v("1")]),s._v(" 转换为字符串，以便函数有意义并返回一个值。在数字类型（"),a("code",[s._v("1")]),s._v("）和字符串类型（"),a("code",[s._v("'2'")]),s._v("）相加时，该数字被视为字符串。我们可以连接字符串，比如 "),a("code",[s._v('"Hello" + "World"')]),s._v("，这里发生的是 "),a("code",[s._v('"1" + "2"')]),s._v("，它返回 "),a("code",[s._v('"12"')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_16-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_16-输出是什么？"}},[s._v("#")]),s._v(" 16. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" number "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("number"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),s._v("number"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("number"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("2")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("0")]),s._v(" "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("2")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("0")]),s._v(" "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-4"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-4"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("一元"),a("strong",[s._v("后自增")]),s._v("运算符 "),a("code",[s._v("++")]),s._v("：")]),s._v(" "),a("ol",[a("li",[s._v("返回值（返回 "),a("code",[s._v("0")]),s._v("）")]),s._v(" "),a("li",[s._v("值自增（number 现在是 "),a("code",[s._v("1")]),s._v("）")])]),s._v(" "),a("p",[s._v("一元"),a("strong",[s._v("前自增")]),s._v("运算符 "),a("code",[s._v("++")]),s._v("：")]),s._v(" "),a("ol",[a("li",[s._v("值自增（number 现在是 "),a("code",[s._v("2")]),s._v("）")]),s._v(" "),a("li",[s._v("返回值（返回 "),a("code",[s._v("2")]),s._v("）")])]),s._v(" "),a("p",[s._v("结果是 "),a("code",[s._v("0 2 2")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_17-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_17-输出是什么？"}},[s._v("#")]),s._v(" 17. 输出是什么？")]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getPersonInfo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("one"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" two"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" three")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("one"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("two"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("three"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Lydia'")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" age "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v("\n\ngetPersonInfo"),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v(" is ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),s._v("age"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v(" years old")]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"Lydia"')]),s._v(" "),a("code",[s._v("21")]),s._v(" "),a("code",[s._v('["", " is ", " years old"]')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('["", " is ", " years old"]')]),s._v(" "),a("code",[s._v('"Lydia"')]),s._v(" "),a("code",[s._v("21")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"Lydia"')]),s._v(" "),a("code",[s._v('["", " is ", " years old"]')]),s._v(" "),a("code",[s._v("21")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-3"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-3"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("标签函数的语法是函数名后面直接带一个模板字符串，并从模板字符串中的插值表达式中获取参数。第一个参数的值总是包含字符串的数组。其余的参数获取的是传递的表达式的值！")]),s._v(" "),a("p",[s._v("上述例子第一个参数数组的第一个是"),a("code",[s._v("${person}")]),s._v("前的空格。")]),s._v(" "),a("p",[a("a",{attrs:{href:"https://zhuanlan.zhihu.com/p/31687266",target:"_blank",rel:"noopener noreferrer"}},[s._v("标签函数"),a("OutboundLink")],1)]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_18-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_18-输出是什么？"}},[s._v("#")]),s._v(" 18. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("checkAge")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("data")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("if")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("data "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("18")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'You are an adult!'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("else")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("if")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("data "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("==")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("18")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'You are still an adult.'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("else")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("Hmm.. You don't have an age I guess")]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("checkAge")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("18")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("You are an adult!")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("You are still an adult.")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Hmm.. You don't have an age I guess")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-5"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-5"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("在测试相等性时，基本类型通过它们的值（value）进行比较，而对象通过它们的引用（reference）进行比较。JavaScript 检查对象是否具有对内存中相同位置的引用。")]),s._v(" "),a("p",[s._v("题目中我们正在比较的两个对象不是同一个引用：作为参数传递的对象引用的内存位置，与用于判断相等的对象所引用的内存位置并不同。")]),s._v(" "),a("p",[s._v("这也是 "),a("code",[s._v("{ age: 18 } === { age: 18 }")]),s._v(" 和 "),a("code",[s._v("{ age: 18 } == { age: 18 }")]),s._v(" 都返回 "),a("code",[s._v("false")]),s._v(" 的原因。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_19-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_19-输出是什么？"}},[s._v("#")]),s._v(" 19. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getAge")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("args")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" args"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getAge")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"number"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"array"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"object"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"NaN"')])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-6"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-6"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("扩展运算符（"),a("code",[s._v("...args")]),s._v("）会返回实参组成的数组。而数组是对象，因此 "),a("code",[s._v("typeof args")]),s._v(" 返回 "),a("code",[s._v('"object"')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_20-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_20-输出是什么？"}},[s._v("#")]),s._v(" 20. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getAge")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'use strict'")]),s._v("\n  age "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("age"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getAge")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("21")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("ReferenceError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("TypeError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-7"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-7"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("使用 "),a("code",[s._v('"use strict"')]),s._v("，你可以确保不会意外地声明全局变量。我们从来没有声明变量 "),a("code",[s._v("age")]),s._v("，因为我们使用 "),a("code",[s._v('"use strict"')]),s._v("，它将抛出一个引用错误。如果我们不使用 "),a("code",[s._v('"use strict"')]),s._v("，它就会工作，因为属性 "),a("code",[s._v("age")]),s._v(" 会被添加到全局对象中了。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h2",{attrs:{id:"question-21-40"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#question-21-40"}},[s._v("#")]),s._v(" question: 21-40")]),s._v(" "),a("h4",{attrs:{id:"_21-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_21-输出是什么？"}},[s._v("#")]),s._v(" 21. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" sum "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("eval")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'10*10+5'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("105")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"105"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("TypeError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"10*10+5"')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-8"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-8"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("代码以字符串形式传递进来，"),a("code",[s._v("eval")]),s._v(" 对其求值。如果它是一个表达式，就像本例中那样，它对表达式求值。表达式是 "),a("code",[s._v("10 * 10 + 5")]),s._v("。这将返回数字 "),a("code",[s._v("105")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_22-cool-secret-可访问多长时间？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_22-cool-secret-可访问多长时间？"}},[s._v("#")]),s._v(" 22. cool_secret 可访问多长时间？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("sessionStorage"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setItem")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'cool_secret'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("123")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: 永远，数据不会丢失。")]),s._v(" "),a("li",[s._v("B: 当用户关掉标签页时。")]),s._v(" "),a("li",[s._v("C: 当用户关掉整个浏览器，而不只是关掉标签页。")]),s._v(" "),a("li",[s._v("D: 当用户关闭电脑时。")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-4"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-4"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("关闭 "),a("strong",[s._v("tab 标签页")]),s._v(" 后，"),a("code",[s._v("sessionStorage")]),s._v(" 存储的数据才会删除。")]),s._v(" "),a("p",[s._v("如果使用 "),a("code",[s._v("localStorage")]),s._v("，那么数据将永远在那里，除非调用了 "),a("code",[s._v("localStorage.clear()")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_23-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_23-输出是什么？"}},[s._v("#")]),s._v(" 23. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("var")]),s._v(" num "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("8")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("var")]),s._v(" num "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("num"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("8")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("10")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("SyntaxError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-5"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-5"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("使用 "),a("code",[s._v("var")]),s._v(" 关键字，你可以用相同的名称声明多个变量。然后变量将保存最新的值。")]),s._v(" "),a("p",[s._v("你不能使用 "),a("code",[s._v("let")]),s._v(" 或 "),a("code",[s._v("const")]),s._v(" 来实现这一点，因为它们是块作用域的。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_24-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_24-输出是什么？"}},[s._v("#")]),s._v(" 24. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" obj "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'a'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'b'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'c'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("5")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\nobj"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("hasOwnProperty")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'1'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nobj"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("hasOwnProperty")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("has")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'1'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("has")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("true")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-8"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-8"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("所有对象的键（不包括 Symbol）在底层都是字符串，即使你自己没有将其作为字符串输入。这就是为什么 "),a("code",[s._v("obj.hasOwnProperty('1')")]),s._v(" 也返回 "),a("code",[s._v("true")]),s._v("。")]),s._v(" "),a("p",[s._v("对于集合，它不是这样工作的。在我们的集合中没有 "),a("code",[s._v("'1'")]),s._v("："),a("code",[s._v("set.has('1')")]),s._v(" 返回 "),a("code",[s._v("false")]),s._v("。它有数字类型为 "),a("code",[s._v("1")]),s._v("，"),a("code",[s._v("set.has(1)")]),s._v(" 返回 "),a("code",[s._v("true")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_25-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_25-输出是什么？"}},[s._v("#")]),s._v(" 25. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" obj "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" a"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'one'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" b"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'two'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" a"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'three'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("obj"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('{ a: "one", b: "two" }')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('{ b: "two", a: "three" }')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('{ a: "three", b: "two" }')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("SyntaxError")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-9"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-9"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("如果你有两个名称相同的键，则键会被替换掉。它仍然位于第一个键出现的位置，但是值是最后出现那个键的值。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_26-javascript-全局执行上下文为你做了两件事：全局对象和-this-关键字。"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_26-javascript-全局执行上下文为你做了两件事：全局对象和-this-关键字。"}},[s._v("#")]),s._v(" 26. JavaScript 全局执行上下文为你做了两件事：全局对象和 this 关键字。")]),s._v(" "),a("ul",[a("li",[s._v("A: true")]),s._v(" "),a("li",[s._v("B: false")]),s._v(" "),a("li",[s._v("C: it depends")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("h4",{attrs:{id:"答案-a-9"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-9"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("基本执行上下文是全局执行上下文：它是代码中随处可访问的内容。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_27-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_27-输出是什么？"}},[s._v("#")]),s._v(" 27. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("5")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("if")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("continue")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("3")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("4")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("3")]),s._v(" "),a("code",[s._v("4")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-10"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-10"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("如果某个条件返回 "),a("code",[s._v("true")]),s._v("，则 "),a("code",[s._v("continue")]),s._v(" 语句跳过本次迭代。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_28-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_28-输出是什么？"}},[s._v("#")]),s._v(" 28. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("String")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("prototype"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("giveLydiaPizza")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Just give Lydia pizza already!'")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Lydia'")]),s._v("\n\nname"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("giveLydiaPizza")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"Just give Lydia pizza already!"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("TypeError: not a function")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("SyntaxError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-10"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-10"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[a("code",[s._v("String")]),s._v(" 是内置的构造函数，我们可以向它添加属性。我只是在它的原型中添加了一个方法。基本类型字符串被自动转换为字符串对象，由字符串原型函数生成。因此，所有 string(string 对象)都可以访问该方法！")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_29-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_29-输出是什么？"}},[s._v("#")]),s._v(" 29. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" a "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" b "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" key"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'b'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" c "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" key"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'c'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\na"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("b"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("123")]),s._v("\na"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("c"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("456")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("a"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("b"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("123")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("456")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-6"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-6"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("对象的键被自动转换为字符串。我们试图将一个对象 "),a("code",[s._v("b")]),s._v(" 设置为对象 "),a("code",[s._v("a")]),s._v(" 的键，且相应的值为 "),a("code",[s._v("123")]),s._v("。")]),s._v(" "),a("p",[s._v("然而，当字符串化一个对象时，它会变成 "),a("code",[s._v('"[object Object]"')]),s._v("。因此这里说的是，"),a("code",[s._v('a["[object Object]"] = 123')]),s._v("。然后，我们再一次做了同样的事情，"),a("code",[s._v("c")]),s._v(" 是另外一个对象，这里也有隐式字符串化，于是，"),a("code",[s._v('a["[object Object]"] = 456')]),s._v("。")]),s._v(" "),a("p",[s._v("然后，我们打印 "),a("code",[s._v("a[b]")]),s._v("，也就是 "),a("code",[s._v('a["[object Object]"]')]),s._v("。之前刚设置为 "),a("code",[s._v("456")]),s._v("，因此返回的是 "),a("code",[s._v("456")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_30-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_30-输出是什么？"}},[s._v("#")]),s._v(" 30. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("foo")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'First'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("bar")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setTimeout")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Second'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("baz")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Third'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("bar")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("foo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("baz")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("First")]),s._v(" "),a("code",[s._v("Second")]),s._v(" "),a("code",[s._v("Third")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("First")]),s._v(" "),a("code",[s._v("Third")]),s._v(" "),a("code",[s._v("Second")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Second")]),s._v(" "),a("code",[s._v("First")]),s._v(" "),a("code",[s._v("Third")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Second")]),s._v(" "),a("code",[s._v("Third")]),s._v(" "),a("code",[s._v("First")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-7"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-7"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("我们有一个 "),a("code",[s._v("setTimeout")]),s._v(" 函数，并首先调用它。然而，它是最后打印日志的。")]),s._v(" "),a("p",[s._v("这是因为在浏览器中，我们不仅有运行时引擎，还有一个叫做 "),a("code",[s._v("WebAPI")]),s._v(" 的东西。"),a("code",[s._v("WebAPI")]),s._v(" 提供了 "),a("code",[s._v("setTimeout")]),s._v(" 函数，也包含其他的，例如 DOM。")]),s._v(" "),a("p",[s._v("将 "),a("em",[s._v("callback")]),s._v(" 推送到 WebAPI 后，"),a("code",[s._v("setTimeout")]),s._v(" 函数本身(但不是回调！)将从栈中弹出。")]),s._v(" "),a("img",{attrs:{src:"https://camo.githubusercontent.com/335a3d02ffb7f822628886c480a9584ace2ff931/68747470733a2f2f692e696d6775722e636f6d2f58357773484f672e706e67",width:"300"}}),s._v(" "),a("p",[s._v("现在，"),a("code",[s._v("foo")]),s._v(" 被调用，打印 "),a("code",[s._v('"First"')]),s._v("。")]),s._v(" "),a("img",{attrs:{src:"https://camo.githubusercontent.com/cf5f8bd460361ccee8bd2534026adbb22e2596e5/68747470733a2f2f692e696d6775722e636f6d2f507663306447712e706e67",width:"300"}}),s._v(" "),a("p",[a("code",[s._v("foo")]),s._v(" 从栈中弹出，"),a("code",[s._v("baz")]),s._v(" 被调用. 打印 "),a("code",[s._v('"Third"')]),s._v("。")]),s._v(" "),a("img",{attrs:{src:"https://camo.githubusercontent.com/1b97d5c5a796735746aafd7dc0119c236863eb57/68747470733a2f2f692e696d6775722e636f6d2f576841326243502e706e67",width:"300"}}),s._v(" "),a("p",[s._v("WebAPI 不能随时向栈内添加内容。相反，它将回调函数推到名为 "),a("em",[s._v("queue")]),s._v(" 的地方。")]),s._v(" "),a("img",{attrs:{src:"https://camo.githubusercontent.com/030dfcad68efec405301a5870e217fb374069645/68747470733a2f2f692e696d6775722e636f6d2f4e536e445a6d552e706e67",width:"300"}}),s._v(" "),a("p",[s._v("这就是事件循环开始工作的地方。一个"),a("strong",[s._v("事件循环")]),s._v("查看栈和任务队列。如果栈是空的，它接受队列上的第一个元素并将其推入栈。")]),s._v(" "),a("img",{attrs:{src:"https://camo.githubusercontent.com/8371c584d1456dea5fbe13c8c0554d75e147ea6b/68747470733a2f2f692e696d6775722e636f6d2f757969536341492e706e67",width:"300"}}),s._v(" "),a("p",[a("code",[s._v("bar")]),s._v(" 被调用，打印 "),a("code",[s._v('"Second"')]),s._v("，然后它被栈弹出。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_31-当点击按钮时，event-target是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_31-当点击按钮时，event-target是什么？"}},[s._v("#")]),s._v(" 31. 当点击按钮时，event.target是什么？")]),s._v(" "),a("div",{staticClass:"language-html line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-html"}},[a("code",[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("<")]),s._v("div")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token attr-name"}},[s._v("onclick")]),a("span",{pre:!0,attrs:{class:"token attr-value"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v('"')]),s._v("console.log('first div')"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v('"')])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(">")])]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("<")]),s._v("div")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token attr-name"}},[s._v("onclick")]),a("span",{pre:!0,attrs:{class:"token attr-value"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v('"')]),s._v("console.log('second div')"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v('"')])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(">")])]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("<")]),s._v("button")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token attr-name"}},[s._v("onclick")]),a("span",{pre:!0,attrs:{class:"token attr-value"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v('"')]),s._v("console.log('button')"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v('"')])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(">")])]),s._v("\n      Click!\n    "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("</")]),s._v("button")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(">")])]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("</")]),s._v("div")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(">")])]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("</")]),s._v("div")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(">")])]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: Outer "),a("code",[s._v("div")])]),s._v(" "),a("li",[s._v("B: Inner "),a("code",[s._v("div")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("button")])]),s._v(" "),a("li",[s._v("D: 一个包含所有嵌套元素的数组。")])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-11"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-11"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("导致事件的最深嵌套的元素是事件的 target。你可以通过 "),a("code",[s._v("event.stopPropagation")]),s._v(" 来停止冒泡。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_32-当您单击该段落时，日志输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_32-当您单击该段落时，日志输出是什么？"}},[s._v("#")]),s._v(" 32. 当您单击该段落时，日志输出是什么？")]),s._v(" "),a("div",{staticClass:"language-html line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-html"}},[a("code",[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("<")]),s._v("div")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token attr-name"}},[s._v("onclick")]),a("span",{pre:!0,attrs:{class:"token attr-value"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v('"')]),s._v("console.log('div')"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v('"')])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(">")])]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("<")]),s._v("p")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token attr-name"}},[s._v("onclick")]),a("span",{pre:!0,attrs:{class:"token attr-value"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("=")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v('"')]),s._v("console.log('p')"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v('"')])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(">")])]),s._v("\n    Click here!\n  "),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("</")]),s._v("p")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(">")])]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token tag"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("</")]),s._v("div")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(">")])]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("p")]),s._v(" "),a("code",[s._v("div")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("div")]),s._v(" "),a("code",[s._v("p")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("p")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("div")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-11"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-11"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("如果我们点击 "),a("code",[s._v("p")]),s._v("，我们会看到两个日志："),a("code",[s._v("p")]),s._v(" 和 "),a("code",[s._v("div")]),s._v("。在事件传播期间，有三个阶段：捕获、目标和冒泡。默认情况下，事件处理程序在冒泡阶段执行（除非将 "),a("code",[s._v("useCapture")]),s._v(" 设置为 "),a("code",[s._v("true")]),s._v("）。它从嵌套最深的元素向外传播。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_33-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_33-输出是什么？"}},[s._v("#")]),s._v(" 33. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Lydia'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("age")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v(" is ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),s._v("age"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("call")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("bind")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("undefined is 21")]),s._v(" "),a("code",[s._v("Lydia is 21")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("function")]),s._v(" "),a("code",[s._v("function")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Lydia is 21")]),s._v(" "),a("code",[s._v("Lydia is 21")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Lydia is 21")]),s._v(" "),a("code",[s._v("function")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-4"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-4"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("使用这两种方法，我们都可以传递我们希望 "),a("code",[s._v("this")]),s._v(" 关键字引用的对象。但是，"),a("code",[s._v(".call")]),s._v(" 是"),a("strong",[s._v("立即执行")]),s._v("的。")]),s._v(" "),a("p",[a("code",[s._v(".bind")]),s._v(" 返回函数的"),a("strong",[s._v("副本")]),s._v("，但带有绑定上下文！它不是立即执行的。")]),s._v(" "),a("p",[s._v("bind之后手动调用"),a("code",[s._v("sayHi.bind(person, 21)()")]),s._v("即可输出"),a("code",[s._v("Lydia is 21")])]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_34-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_34-输出是什么？"}},[s._v("#")]),s._v(" 34. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"object"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"number"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"function"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"undefined"')])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-8"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-8"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[a("code",[s._v("sayHi")]),s._v(" 方法返回的是立即执行函数(IIFE)的返回值.此立即执行函数的返回值是 "),a("code",[s._v("0")]),s._v("， 类型是 "),a("code",[s._v("number")])]),s._v(" "),a("p",[a("code",[s._v("(() => 0)()")]),s._v("是立即执行函数。")]),s._v(" "),a("p",[s._v("参考：只有7种内置类型："),a("code",[s._v("null")]),s._v("，"),a("code",[s._v("undefined")]),s._v("，"),a("code",[s._v("boolean")]),s._v("，"),a("code",[s._v("number")]),s._v("，"),a("code",[s._v("string")]),s._v("，"),a("code",[s._v("object")]),s._v(" 和 "),a("code",[s._v("symbol")]),s._v("。 "),a("code",[s._v("function")]),s._v(" 不是一种类型，函数是对象，它的类型是"),a("code",[s._v("object")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_35-下面哪些值是-falsy"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_35-下面哪些值是-falsy"}},[s._v("#")]),s._v(" 35. 下面哪些值是 falsy?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Number")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("''")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("' '")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Boolean")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("false")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("undefined")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("0")]),s._v(", "),a("code",[s._v("''")]),s._v(", "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("0")]),s._v(", "),a("code",[s._v("new Number(0)")]),s._v(", "),a("code",[s._v("''")]),s._v(", "),a("code",[s._v("new Boolean(false)")]),s._v(", "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("0")]),s._v(", "),a("code",[s._v("''")]),s._v(", "),a("code",[s._v("new Boolean(false)")]),s._v(", "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: All of them are falsy")])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-12"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-12"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("只有 6 种 "),a("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy",target:"_blank",rel:"noopener noreferrer"}},[s._v("falsy"),a("OutboundLink")],1),s._v(" 值:")]),s._v(" "),a("ul",[a("li",[a("code",[s._v("undefined")])]),s._v(" "),a("li",[a("code",[s._v("null")])]),s._v(" "),a("li",[a("code",[s._v("NaN")])]),s._v(" "),a("li",[a("code",[s._v("0")])]),s._v(" "),a("li",[a("code",[s._v("''")]),s._v(" (empty string)")]),s._v(" "),a("li",[a("code",[s._v("false")])])]),s._v(" "),a("p",[a("code",[s._v("Function")]),s._v(" 构造函数, 比如 "),a("code",[s._v("new Number")]),s._v(" 和 "),a("code",[s._v("new Boolean")]),s._v("，是 "),a("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy",target:"_blank",rel:"noopener noreferrer"}},[s._v("truthy"),a("OutboundLink")],1),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_36-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_36-输出是什么？"}},[s._v("#")]),s._v(" 36. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"number"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"string"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"object"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"undefined"')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-9"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-9"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[a("code",[s._v("typeof 1")]),s._v(" 返回 "),a("code",[s._v('"number"')]),s._v("。\n"),a("code",[s._v('typeof "number"')]),s._v(" 返回 "),a("code",[s._v('"string"')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_37-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_37-输出是什么？"}},[s._v("#")]),s._v(" 37. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" numbers "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\nnumbers"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("11")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("numbers"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("[1, 2, 3, 7 x null, 11]")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("[1, 2, 3, 11]")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("[1, 2, 3, 7 x empty, 11]")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("SyntaxError")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-12"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-12"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v('当你为数组设置超过数组长度的值的时候， JavaScript 会创建名为 "empty slots" 的东西。它们的值实际上是 '),a("code",[s._v("undefined")]),s._v("。你会看到以下场景：")]),s._v(" "),a("p",[a("code",[s._v("[1, 2, 3, 7 x empty, 11]")])]),s._v(" "),a("p",[s._v("这取决于你的运行环境（每个浏览器，以及 node 环境，都有可能不同）")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_38-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_38-输出是什么？"}},[s._v("#")]),s._v(" 38. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("try")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("throw")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Error")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("catch")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("y "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n    console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("2")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-13"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-13"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[a("code",[s._v("catch")]),s._v(" 代码块接收参数 "),a("code",[s._v("x")]),s._v("。当我们传递参数时，这与之前定义的变量 "),a("code",[s._v("x")]),s._v(" 不同 。这个 "),a("code",[s._v("x")]),s._v(" 是属于 "),a("code",[s._v("catch")]),s._v(" 块级作用域的。")]),s._v(" "),a("p",[s._v("然后，我们将块级作用域中的变量赋值为 "),a("code",[s._v("1")]),s._v("，同时也设置了变量 "),a("code",[s._v("y")]),s._v(" 的值。现在，我们打印块级作用域中的变量 "),a("code",[s._v("x")]),s._v("，值为 "),a("code",[s._v("1")]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v("catch")]),s._v(" 块之外的变量 "),a("code",[s._v("x")]),s._v(" 的值仍为 "),a("code",[s._v("undefined")]),s._v("， "),a("code",[s._v("y")]),s._v(" 的值为 "),a("code",[s._v("2")]),s._v("。当我们在 "),a("code",[s._v("catch")]),s._v(" 块之外执行 "),a("code",[s._v("console.log(x)")]),s._v(" 时，返回 "),a("code",[s._v("undefined")]),s._v("，"),a("code",[s._v("y")]),s._v(" 返回 "),a("code",[s._v("2")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_39-javascript-中的一切都是？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_39-javascript-中的一切都是？"}},[s._v("#")]),s._v(" 39. JavaScript 中的一切都是？")]),s._v(" "),a("ul",[a("li",[s._v("A: 基本类型与对象")]),s._v(" "),a("li",[s._v("B: 函数与对象")]),s._v(" "),a("li",[s._v("C: 只有对象")]),s._v(" "),a("li",[s._v("D: 数字与对象")])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-14"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-14"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("JavaScript 只有基本类型和对象。")]),s._v(" "),a("p",[s._v("基本类型包括 "),a("code",[s._v("boolean")]),s._v(", "),a("code",[s._v("null")]),s._v(", "),a("code",[s._v("undefined")]),s._v(", "),a("code",[s._v("bigint")]),s._v(", "),a("code",[s._v("number")]),s._v(", "),a("code",[s._v("string")]),s._v(", "),a("code",[s._v("symbol")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_40-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_40-输出是什么？"}},[s._v("#")]),s._v(" 40. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("reduce")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("acc"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" cur")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" acc"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("concat")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("cur"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("[0, 1, 2, 3, 1, 2]")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("[6, 1, 2]")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("[1, 2, 0, 1, 2, 3]")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("[1, 2, 6]")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-13"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-13"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[a("code",[s._v("[1, 2]")]),s._v("是初始值。初始值将会作为首次调用时第一个参数 "),a("code",[s._v("acc")]),s._v(" 的值。在第一次执行时， "),a("code",[s._v("acc")]),s._v(" 的值是 "),a("code",[s._v("[1, 2]")]),s._v("， "),a("code",[s._v("cur")]),s._v(" 的值是 "),a("code",[s._v("[0, 1]")]),s._v("。合并它们，结果为 "),a("code",[s._v("[1, 2, 0, 1]")]),s._v("。\n第二次执行， "),a("code",[s._v("acc")]),s._v(" 的值是 "),a("code",[s._v("[1, 2, 0, 1]")]),s._v("， "),a("code",[s._v("cur")]),s._v(" 的值是 "),a("code",[s._v("[2, 3]")]),s._v("。合并它们，最终结果为 "),a("code",[s._v("[1, 2, 0, 1, 2, 3]")])]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h2",{attrs:{id:"question-41-60"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#question-41-60"}},[s._v("#")]),s._v(" question: 41-60")]),s._v(" "),a("h4",{attrs:{id:"_41-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_41-输出是什么？"}},[s._v("#")]),s._v(" 41. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("null")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("''")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-10"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-10"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[a("code",[s._v("null")]),s._v(" 是 "),a("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy",target:"_blank",rel:"noopener noreferrer"}},[s._v("falsy"),a("OutboundLink")],1),s._v("。 "),a("code",[s._v("!null")]),s._v(" 的值是 "),a("code",[s._v("true")]),s._v("。 "),a("code",[s._v("!true")]),s._v(" 的值是 "),a("code",[s._v("false")]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v('""')]),s._v(" 是 "),a("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy",target:"_blank",rel:"noopener noreferrer"}},[s._v("falsy"),a("OutboundLink")],1),s._v("。 "),a("code",[s._v('!""')]),s._v(" 的值是 "),a("code",[s._v("true")]),s._v("。  "),a("code",[s._v("!true")]),s._v(" 的值是 "),a("code",[s._v("false")]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v("1")]),s._v(" 是 "),a("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy",target:"_blank",rel:"noopener noreferrer"}},[s._v("truthy"),a("OutboundLink")],1),s._v("。 "),a("code",[s._v("!1")]),s._v(" 的值是 "),a("code",[s._v("false")]),s._v("。 "),a("code",[s._v("!false")]),s._v(" 的值是 "),a("code",[s._v("true")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_42-setinterval-方法的返回值是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_42-setinterval-方法的返回值是什么？"}},[s._v("#")]),s._v(" 42. "),a("code",[s._v("setInterval")]),s._v(" 方法的返回值是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setInterval")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Hi'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1000")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: 一个唯一的id")]),s._v(" "),a("li",[s._v("B: 该方法指定的毫秒数")]),s._v(" "),a("li",[s._v("C: 传递的函数")]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-15"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-15"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[a("code",[s._v("setInterval")]),s._v(" 返回一个唯一的 id。此 id 可被用于 "),a("code",[s._v("clearInterval")]),s._v(" 函数来取消定时。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_43-输出是什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_43-输出是什么？"}},[s._v("#")]),s._v(" 43. 输出是什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Lydia'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('["L", "y", "d", "i", "a"]')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('["Lydia"]')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('[[], "Lydia"]')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('[["L", "y", "d", "i", "a"]]')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-16"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-16"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("string 类型是可迭代的。扩展运算符将迭代的每个字符映射成一个元素。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_44-输出是什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_44-输出是什么"}},[s._v("#")]),s._v(" 44. 输出是什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("generator")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("i")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("yield")]),s._v(" i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("yield")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" gen "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("generator")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("gen"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("gen"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("[0, 10], [10, 20]")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("20, 20")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("10, 20")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("0, 10 and 10, 20")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-14"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-14"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("常规函数调用后不能中途停止，但是，generator函数是可以中途“停止”的，然后从停止的地方继续。每次generator函数遇到"),a("code",[s._v("yield")]),s._v("关键字时，该函数都会生成其后指定的值。注意，这种情况下generator函数不返回值，而是生成值。")]),s._v(" "),a("p",[s._v("首先，用"),a("code",[s._v("i")]),s._v("等于"),a("code",[s._v("10")]),s._v("来初始化generator函数。我们通过"),a("code",[s._v("next()")]),s._v("方法来调用该generator函数，第一次调用时"),a("code",[s._v("i")]),s._v("等于 "),a("code",[s._v("10")]),s._v("，当遇到第一个"),a("code",[s._v("yield")]),s._v("关键字时：它产生了 "),a("code",[s._v("i")]),s._v("的值，函数暂停，同时打印出"),a("code",[s._v("10")]),s._v("。")]),s._v(" "),a("p",[s._v("然后，通过 "),a("code",[s._v("next()")]),s._v("方法再次调用该函数，它将从之前停止的地方继续,此时 "),a("code",[s._v("i")]),s._v("依然为"),a("code",[s._v("10")]),s._v("。这时它遇到第二个"),a("code",[s._v("yield")]),s._v("关键字，并产生"),a("code",[s._v("i * 2")]),s._v("的值，所以它返回"),a("code",[s._v("10 * 2")]),s._v("，即"),a("code",[s._v("20")]),s._v("。结果为"),a("code",[s._v("10, 20")]),s._v("。")]),s._v(" "),a("p",[s._v("Generator")]),s._v(" "),a("p",[s._v("Generator 函数有多种理解角度。语法上，首先可以把它理解成，Generator 函数是一个状态机，封装了多个内部状态。")]),s._v(" "),a("p",[s._v("执行 Generator 函数会返回一个遍历器对象，也就是说，Generator 函数除了状态机，还是一个遍历器对象生成函数。返回的遍历器对象，可以依次遍历 Generator 函数内部的每一个状态。\n形式上，Generator 函数是一个普通函数，但是有两个特征。一是，function关键字与函数名之间有一个星号；二是，函数体内部使用yield表达式，定义不同的内部状态（yield在英语里的意思就是“产出”）。")]),s._v(" "),a("div",{staticClass:"language-js line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("helloWorldGenerator")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("yield")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'hello'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("yield")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'world'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'ending'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("var")]),s._v(" hw "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("helloWorldGenerator")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("p",[s._v("上面代码定义了一个 Generator 函数helloWorldGenerator，它内部有两个yield表达式（hello和world），即该函数有三个状态：hello，world 和 return 语句（结束执行）\n调用 Generator 函数后，该函数并不执行，返回的也不是函数运行结果，而是一个指向内部状态的指针对象,也就是遍历器对象。")]),s._v(" "),a("p",[s._v("下一步，必须调用遍历器对象的next方法，使得指针移向下一个状态。也就是说，每次调用next方法，内部指针就从函数头部或上一次停下来的地方开始执行，直到遇到下一个yield表达式（或return语句）为止。换言之，Generator 函数是分段执行的，yield表达式是暂停执行的标记，而next方法可以恢复执行。")]),s._v(" "),a("div",{staticClass:"language-js line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[s._v("hw"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// { value: 'hello', done: false }")]),s._v("\n\nhw"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// { value: 'world', done: false }")]),s._v("\n\nhw"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// { value: 'ending', done: true }")]),s._v("\n\nhw"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// { value: undefined, done: true }")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("p",[a("a",{attrs:{href:"http://es6.ruanyifeng.com/#docs/generator",target:"_blank",rel:"noopener noreferrer"}},[s._v("generator传送门"),a("OutboundLink")],1)]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_45-返回什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_45-返回什么"}},[s._v("#")]),s._v(" 45. 返回什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" firstPromise "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Promise")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" rej")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setTimeout")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("500")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"one"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" secondPromise "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Promise")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" rej")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setTimeout")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("100")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"two"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nPromise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("race")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("firstPromise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" secondPromise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("then")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("res")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"one"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"two"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"two" "one"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"one" "two"')])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-11"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-11"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[a("code",[s._v("Promise.race(iterable)")]),s._v(" 方法返回一个promise，当我们给其传递多个promise时，一旦其中某个promise解决或拒绝，返回的promise就会解决或拒绝，始终采用第一个解决/拒绝的promise的值作为它的返回值。\n对于 "),a("code",[s._v("setTimeout")]),s._v(" 方法，第一个promise("),a("code",[s._v("firstPromise")]),s._v(")的delay时长是500ms，第二个promise("),a("code",[s._v("secondPromise")]),s._v(")的delay时长是100ms，这意味着"),a("code",[s._v("secondPromise")]),s._v("将会先完成并且返回值为"),a("code",[s._v("'two'")]),s._v("，此时打印出的就是"),a("code",[s._v("'two'")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_46-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_46-输出什么"}},[s._v("#")]),s._v(" 46. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" members "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nperson "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("null")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("members"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("null")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("[null]")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("[{}]")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('[{ name: "Lydia" }]')])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-5"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-5"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("首先，我们声明一个变量 "),a("code",[s._v("person")]),s._v("，并给其赋值一个包含"),a("code",[s._v("name")]),s._v("属性的对象。")]),s._v(" "),a("img",{attrs:{src:"https://camo.githubusercontent.com/18ec11730a406fb1ea8fe7e4f0cea77d8fe33dd0/68747470733a2f2f692e696d6775722e636f6d2f544d4c314d62532e706e67",width:"200"}}),s._v(" "),a("p",[s._v("然后，我们声明了一个变量 "),a("code",[s._v("members")]),s._v("，并将该数组的第一个元素赋值为"),a("code",[s._v("person")]),s._v("变量。对于基本类型，赋值是值的拷贝，而对于引用类型，赋值则是引用地址的拷贝，注意拷贝后的引用地址和原引用地址不是同一个，二者只是指向同一个引用类型。")]),s._v(" "),a("img",{attrs:{src:"https://camo.githubusercontent.com/a775ede4cce9b143614b05f06e4afac49ee4aab0/68747470733a2f2f692e696d6775722e636f6d2f465347354b33462e706e67",width:"300"}}),s._v(" "),a("p",[s._v("然后我们将变量 "),a("code",[s._v("person")]),s._v(" 再次赋值为"),a("code",[s._v("null")]),s._v("。")]),s._v(" "),a("img",{attrs:{src:"https://camo.githubusercontent.com/a13998111c61325f557b40db37d77a054fa76407/68747470733a2f2f692e696d6775722e636f6d2f73596a63734d542e706e67",width:"300"}}),s._v(" "),a("p",[s._v("我们改变了 "),a("code",[s._v("person")]),s._v(" 变量的引用地址，使其不再指向包含"),a("code",[s._v("name")]),s._v("属性的对象，而 "),a("code",[s._v("members")]),s._v(" 数组中第一个元素的引用地址和 "),a("code",[s._v("person")]),s._v(" 变量是不同的，它仍然指向原对象，所以当我们打印时 "),a("code",[s._v("members")]),s._v("，包含"),a("code",[s._v("name")]),s._v("属性的对象将被打印。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_47-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_47-输出什么"}},[s._v("#")]),s._v(" 47. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" item "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("in")]),s._v(" person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("item"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('{ name: "Lydia" }, { age: 21 }')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"name", "age"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"Lydia", 21')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('["name", "Lydia"], ["age", 21]')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-12"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-12"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("for-in")]),s._v("循环，我们可以遍历对象的键，在本例中为"),a("code",[s._v("name")]),s._v("和"),a("code",[s._v("age")]),s._v("，在js引擎中，对象的键是字符串（如果它们不是Symbol），在每个循环中，我们将"),a("code",[s._v("item")]),s._v("的值设置为它迭代的当前键。 首先，"),a("code",[s._v("item")]),s._v("等于"),a("code",[s._v("name")]),s._v("，并记录，然后，"),a("code",[s._v("item")]),s._v("等于"),a("code",[s._v("age")]),s._v("，并被记录。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_48-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_48-输出什么"}},[s._v("#")]),s._v(" 48. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"5"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"345"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"75"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("12")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"12"')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-13"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-13"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("当所有运算符的优先级相同时，计算表达式需要确定运算符的结合顺序，即从右到左还是从左往右。在这个例子中，我们只有一类运算符"),a("code",[s._v("+")]),s._v("，对于加法来说，结合顺序就是从左到右。")]),s._v(" "),a("p",[a("code",[s._v("3 + 4")]),s._v("先被计算，值为"),a("code",[s._v("7")]),s._v("。"),a("code",[s._v("7 + '5'")]),s._v(" 结果为 "),a("code",[s._v('"75"')]),s._v("，因为不同类型相加时存在强制转换，当number类型与string类型相加时，number类型将会被转换为string，因此数值"),a("code",[s._v("7")]),s._v("将会被转换为"),a("code",[s._v("'7'")]),s._v("，参照第十五题。字符串可以通过"),a("code",[s._v("+")]),s._v("号来连接，因此"),a("code",[s._v('"7" + "5"')]),s._v(" 结果为 "),a("code",[s._v('"75"')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_49-num的值是多少"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_49-num的值是多少"}},[s._v("#")]),s._v(" 49. "),a("code",[s._v("num")]),s._v("的值是多少?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" num "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("parseInt")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"7*6"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("42")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"42"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("7")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("NaN")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-15"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-15"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("只有字符串中的第一个有效数字将会基于基数被转换， "),a("code",[s._v("parseInt(string, radix)")]),s._v("的第二个参数"),a("code",[s._v("radix")]),s._v("，其指定了第一个参数"),a("code",[s._v("string")]),s._v("的基数，可能是二进制，八进制，十六进制等等，但是返回值始终是十进制。\n该方法会检查字符串中的字符是否有效，一旦遇到一个非有效数字的字符，就会停止解析并直接忽略后面的字符。")]),s._v(" "),a("p",[a("code",[s._v("*")]),s._v("号不是一个有效数字，所以只会将字符"),a("code",[s._v('"7"')]),s._v("转换为十进制的"),a("code",[s._v("7")]),s._v("，所以"),a("code",[s._v("num")]),s._v(" 的值是 "),a("code",[s._v("7")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_50-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_50-输出什么"}},[s._v("#")]),s._v(" 50. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("map")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("num")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("if")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" num "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"number"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" num "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("[]")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("[null, null, null]")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("[undefined, undefined, undefined]")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("[ 3 x empty ]")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-16"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-16"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("映射数组时，"),a("code",[s._v("num")]),s._v("的值等于它当前循环的元素。上述数组中元素是数字，因此if语句"),a("code",[s._v("typeof num === “number”")]),s._v("的条件为"),a("code",[s._v("true")]),s._v("，map函数将创建一个新数组并插入从函数返回的值。")]),s._v(" "),a("p",[s._v("但是，我们没有返回值，当不从函数返回值时，函数默认返回"),a("code",[s._v("undefined")]),s._v("。 对于数组中的每个元素，都会调用函数块，因此对于每个元素，都返回的是"),a("code",[s._v("undefined")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_51-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_51-输出什么"}},[s._v("#")]),s._v(" 51. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getInfo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("member"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" year")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  member"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  year "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"1998"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Sarah"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" birthYear "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"1997"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getInfo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" birthYear"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" birthYear"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('{ name: "Lydia" }, "1997"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('{ name: "Sarah" }, "1998"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('{ name: "Lydia" }, "1998"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('{ name: "Sarah" }, "1997"')])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-17"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-17"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("函数参数的传值类似于赋值，如果参数是基本类型，传参时传的是值，如果参数是引用类型，那么传参时传的则是引用地址（参见第46题）")]),s._v(" "),a("p",[s._v("变量 "),a("code",[s._v("birthYear")]),s._v(" 引用了值"),a("code",[s._v('"1997"')]),s._v("，参数"),a("code",[s._v("year")]),s._v("也引用了值"),a("code",[s._v("“1997”")]),s._v("，但"),a("code",[s._v("year")]),s._v("与"),a("code",[s._v("birthYear")]),s._v("引用的值不是同一个。 当我们通过将"),a("code",[s._v("year")]),s._v("设置为"),a("code",[s._v("“1998”")]),s._v("来更新"),a("code",[s._v("year")]),s._v("的值时，我们只更新"),a("code",[s._v("year")]),s._v("的值。 "),a("code",[s._v("birthYear")]),s._v("仍然等于"),a("code",[s._v("“1997”")]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v("person")]),s._v("是个对象，属于引用类型。参数 "),a("code",[s._v("member")]),s._v(" 的引用是从 "),a("code",[s._v("person")]),s._v(" 拷贝过来的，因此二者指向的是同一个对象，我们通过任何一个引用去修改该对象，另一个获取到的都将是修改后的。因此当我们通过 "),a("code",[s._v("member")]),s._v(" 修改该对象属性时， "),a("code",[s._v("person")]),s._v(" 的属性也被修改， 所以"),a("code",[s._v("person")]),s._v("对象的"),a("code",[s._v("name")]),s._v(" 属性是"),a("code",[s._v('"Lydia"')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_52-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_52-输出什么"}},[s._v("#")]),s._v(" 52. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("greeting")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("throw")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Hello world!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("try")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" data "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("greeting")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n    console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"It worked!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" data"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("catch")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("e"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Oh no an error!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" e"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"It worked! Hello world!"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"Oh no an error: undefined')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("SyntaxError: can only throw Error objects")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"Oh no an error: Hello world!')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-6"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-6"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("通过 "),a("code",[s._v("throw")]),s._v(" 语句，我们可以创建自定义错误。使用该语句，你可以抛出异常，异常可能是一个"),a("b",[s._v("string")]),s._v("、"),a("b",[s._v("number")]),s._v("、"),a("b",[s._v("boolean")]),s._v(" 或者 "),a("b",[s._v("object")]),s._v("，上述异常是字符串"),a("code",[s._v("'Hello world'")]),s._v("。")]),s._v(" "),a("p",[s._v("通过 "),a("code",[s._v("catch")]),s._v(" 语句，我们可以指定在 "),a("code",[s._v("try")]),s._v(" 语句中抛出异常时怎么做。上述例子中，一个字符串的异常 "),a("code",[s._v("'Hello world'")]),s._v(" 被抛出， "),a("code",[s._v("catch")]),s._v(" 中的 "),a("code",[s._v("e")]),s._v(" 即指该字符串，所以打印出 "),a("code",[s._v("'Oh an error: Hello world'")])]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_53-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_53-输出什么"}},[s._v("#")]),s._v(" 53. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Car")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("make "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lamborghini"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" make"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Maserati"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" myCar "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Car")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("myCar"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("make"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"Lamborghini"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"Maserati"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("ReferenceError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("TypeError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-14"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-14"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("返回属性时，属性的值等于_returned_的值，而不是构造函数中设置的值。 我们返回的是字符串 "),a("code",[s._v('"Maserati"')]),s._v("，所以 "),a("code",[s._v("myCar.make")]),s._v(" 为 "),a("code",[s._v('"Maserati"')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_54-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_54-输出什么"}},[s._v("#")]),s._v(" 54. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("y "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"undefined", "number"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"number", "number"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"object", "number"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"number", "undefined"')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-18"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-18"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[a("code",[s._v("let x = y = 10;")]),s._v(" 实际上是以下的简写:")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("y "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("当我们给 "),a("code",[s._v("y")]),s._v(" 赋值为 "),a("code",[s._v("10")]),s._v(" 时，实际上是给全局对象(浏览器中为 "),a("code",[s._v("window")]),s._v(", Node下为 "),a("code",[s._v("global")]),s._v(" ）添加了一个属性 "),a("code",[s._v("y")]),s._v(", 在浏览器中时，此时"),a("code",[s._v("window.y")]),s._v("为 "),a("code",[s._v("10")]),s._v("。")]),s._v(" "),a("p",[s._v("然后，我们声明了一个变量 "),a("code",[s._v("x")]),s._v(" ，其值为 "),a("code",[s._v("y")]),s._v("，即 "),a("code",[s._v("10")]),s._v("。使用 "),a("code",[s._v("let")]),s._v(" 声明的变量是一个块级作用域变量，仅在声明其的块级作用域中可用，上述例子的块级作用域是一个立即执行函数 (IIFE)。当使用操作符 "),a("code",[s._v("typeof")]),s._v(" 时，我们是在试图在 "),a("code",[s._v("x")]),s._v(" 的声明块之外访问 "),a("code",[s._v("x")]),s._v(" ，当然 "),a("code",[s._v("x")]),s._v(" 是未定义的。对于尚未定义或尚未赋值的变量， "),a("code",[s._v("console.log（typeof x）")]),s._v("将返回"),a("code",[s._v("“undefined”")]),s._v("。")]),s._v(" "),a("p",[s._v("当然，我们创建了全局变量 "),a("code",[s._v("y")]),s._v(" 且其值为 "),a("code",[s._v("10")]),s._v(", 该变量在我们代码中的任务位置都可用，所以"),a("code",[s._v("console.log(typeof y)")]),s._v(" 打印出的事 "),a("code",[s._v('"number"')])]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_55-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_55-输出什么"}},[s._v("#")]),s._v(" 55. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Dog")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("name")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Dog")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("prototype"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("bark")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("Woof I am ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" pet "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Dog")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Mara"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\npet"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("bark")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("delete")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Dog")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("prototype"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("bark"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\npet"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("bark")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br"),a("span",{staticClass:"line-number"},[s._v("16")]),a("br"),a("span",{staticClass:"line-number"},[s._v("17")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"Woof I am Mara"')]),s._v(", "),a("code",[s._v("TypeError")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"Woof I am Mara"')]),s._v(","),a("code",[s._v('"Woof I am Mara"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"Woof I am Mara"')]),s._v(", "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("TypeError")]),s._v(", "),a("code",[s._v("TypeError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-19"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-19"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("我们可以用"),a("code",[s._v("delete")]),s._v("关键字删除对象的属性，对原型也是适用的。删除了原型的属性后，该属性在原型链上就不可用了。在本例中，函数"),a("code",[s._v("bark")]),s._v("在执行了"),a("code",[s._v("delete Dog.prototype.bark")]),s._v("后不可用, 然而后面的代码还在调用它。")]),s._v(" "),a("p",[s._v("当我们尝试调用一个不存在的函数时"),a("code",[s._v("TypeError")]),s._v("异常会被抛出。在本例中就是 "),a("code",[s._v("TypeError: pet.bark is not a function")]),s._v("，因为"),a("code",[s._v("pet.bark")]),s._v("是"),a("code",[s._v("undefined")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_56-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_56-输出什么"}},[s._v("#")]),s._v(" 56. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("[1, 1, 2, 3, 4]")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("[1, 2, 3, 4]")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("{1, 1, 2, 3, 4}")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("{1, 2, 3, 4}")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-7"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-7"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[a("code",[s._v("Set")]),s._v("对象是一个独一无二值的集合：即同一个值在其中仅出现一次。")]),s._v(" "),a("p",[s._v("我们传入了数组"),a("code",[s._v("[1, 1, 2, 3, 4]")]),s._v("，它有一个重复值"),a("code",[s._v("1")]),s._v("。因为一个集合里不能有两个重复的值，其中一个就被移除了。所以结果是 "),a("code",[s._v("{1, 2, 3, 4}")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_57-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_57-输出什么"}},[s._v("#")]),s._v(" 57. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// counter.js")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" counter "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("export")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("default")]),s._v(" counter"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// index.js")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("import")]),s._v(" myCounter "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("from")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"./counter"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nmyCounter "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("myCounter"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("10")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("11")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Error")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("NaN")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-17"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-17"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("通过"),a("code",[s._v("import")]),s._v("命令加载的变量是只读的，"),a("code",[s._v("import")]),s._v("的本质是引入接口，不允许在加载模块的脚本里改写接口。")]),s._v(" "),a("p",[s._v("当我们给"),a("code",[s._v("myCounter")]),s._v("增加一个值的时候会抛出一个异常： "),a("code",[s._v("myCounter")]),s._v("是只读的，不能被修改。")]),s._v(" "),a("div",{staticClass:"language-js line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("import")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("a"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("from")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'./xxx.js'")]),s._v("\n\na "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// Syntax Error : 'a' is read-only;")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("p",[s._v("上面代码中，脚本加载了变量a，对其重新赋值就会报错，因为a是一个只读的接口。但是，如果a是一个对象，改写a的属性是允许的。")]),s._v(" "),a("div",{staticClass:"language-js line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("import")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("a"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("from")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'./xxx.js'")]),s._v("\n\na"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("foo "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'hello'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 合法操作")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("p",[s._v("上面代码中，a的属性可以成功改写，并且其他模块也可以读到改写后的值。不过，这种写法很难查错，建议凡是输入的变量，都当作完全只读，轻易不要改变它的属性。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_58-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_58-输出什么"}},[s._v("#")]),s._v(" 58. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nage "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("delete")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("delete")]),s._v(" age"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("false")]),s._v(", "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"Lydia"')]),s._v(", "),a("code",[s._v("21")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("true")]),s._v(", "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")]),s._v(", "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-20"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-20"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[a("code",[s._v("delete")]),s._v(" 操作符用于删除对象的某个属性, 它返回一个布尔值："),a("code",[s._v("true")]),s._v("指删除成功，否则返回"),a("code",[s._v("false")]),s._v("。通过 "),a("code",[s._v("var")]),s._v(", "),a("code",[s._v("const")]),s._v(" 或 "),a("code",[s._v("let")]),s._v(" 关键字声明的变量不能用 "),a("code",[s._v("delete")]),s._v(" 操作符来删除。")]),s._v(" "),a("p",[a("code",[s._v("name")]),s._v("变量由"),a("code",[s._v("const")]),s._v("关键字声明，所以删除不成功:返回 "),a("code",[s._v("false")]),s._v("。而我们设定"),a("code",[s._v("age")]),s._v("等于"),a("code",[s._v("21")]),s._v("时,我们实际上添加了一个名为"),a("code",[s._v("age")]),s._v("的属性给全局对象。对象中的属性是可以删除的，所以"),a("code",[s._v("delete age")]),s._v("返回"),a("code",[s._v("true")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_59-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_59-输出什么"}},[s._v("#")]),s._v(" 59. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" numbers "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("5")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" numbers"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("[[1, 2, 3, 4, 5]]")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("[1, 2, 3, 4, 5]")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("1")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("[1]")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-18"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-18"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("我们可以通过解构赋值来解析来自数组或对象属性的值，比如说：")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("a"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" b"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("img",{attrs:{src:"https://camo.githubusercontent.com/8903a861b474f8b63da9d0d46d14a74d9e2db039/68747470733a2f2f692e696d6775722e636f6d2f41444670566f702e706e67",width:"200"}}),s._v(" "),a("p",[a("code",[s._v("a")]),s._v("的值现在是"),a("code",[s._v("1")]),s._v("，"),a("code",[s._v("b")]),s._v("的值现在是"),a("code",[s._v("2")]),s._v("。上述例子中:")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("5")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("img",{attrs:{src:"https://camo.githubusercontent.com/3474488027d64c5fc9955ab5be7c3a88d1254449/68747470733a2f2f692e696d6775722e636f6d2f4e7a476b4d4e6b2e706e67",width:"200"}}),s._v(" "),a("p",[s._v("也就是说，"),a("code",[s._v("y")]),s._v("等于数组的第一个值就是数字"),a("code",[s._v("1")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_60-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_60-输出什么"}},[s._v("#")]),s._v(" 60. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" user "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" admin "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" admin"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("user "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("admin"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('{ admin: true, user: { name: "Lydia", age: 21 } }')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('{ admin: true, name: "Lydia", age: 21 }')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('{ admin: true, user: ["Lydia", 21] }')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("{ admin: true }")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-15"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-15"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("扩展运算符"),a("code",[s._v("...")]),s._v("为对象的组合提供了可能。你可以复制对象中的键值对，然后把它们加到另一个对象里去。在本例中，我们复制了"),a("code",[s._v("user")]),s._v("对象键值对，然后把它们加入到"),a("code",[s._v("admin")]),s._v("对象中。"),a("code",[s._v("admin")]),s._v("对象就拥有了这些键值对，所以结果为"),a("code",[s._v('{ admin: true, name: "Lydia", age: 21 }')])]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h2",{attrs:{id:"question-61-80"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#question-61-80"}},[s._v("#")]),s._v(" question: 61-80")]),s._v(" "),a("h4",{attrs:{id:"_61-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_61-输出什么"}},[s._v("#")]),s._v(" 61. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nObject"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("defineProperty")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"age"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" value"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("Object"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("keys")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('{ name: "Lydia", age: 21 }')]),s._v(", "),a("code",[s._v('["name", "age"]')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('{ name: "Lydia", age: 21 }')]),s._v(", "),a("code",[s._v('["name"]')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('{ name: "Lydia"}')]),s._v(", "),a("code",[s._v('["name", "age"]')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('{ name: "Lydia"}')]),s._v(", "),a("code",[s._v('["age"]')])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-16"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-16"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("通过"),a("code",[s._v("defineProperty")]),s._v("方法，我们可以给对象添加一个新属性，或者修改已经存在的属性。通过"),a("code",[s._v("defineProperty")]),s._v("方法给对象添加的属性默认为 "),a("em",[s._v("不可枚举(not enumerable)")]),s._v(" ，"),a("code",[s._v("Object.keys")]),s._v("方法仅返回对象中 "),a("em",[s._v("可枚举(enumerable)")]),s._v(" 的属性，因此只打印了"),a("code",[s._v('"name"')]),s._v(".")]),s._v(" "),a("p",[s._v("用"),a("code",[s._v("defineProperty")]),s._v("方法添加的属性默认不可变。你可以通过"),a("code",[s._v("writable")]),s._v(", "),a("code",[s._v("configurable")]),s._v(" 和 "),a("code",[s._v("enumerable")]),s._v("属性来改变这一行为。这样的话， 相比于自己添加的属性，"),a("code",[s._v("defineProperty")]),s._v("方法添加的属性有了更多的控制权。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_62-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_62-输出什么"}},[s._v("#")]),s._v(" 62. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" settings "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  username"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"lydiahallie"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  level"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("19")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  health"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("90")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" data "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token constant"}},[s._v("JSON")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("stringify")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("settings"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"level"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"health"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("data"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"{"level":19, "health":90}"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"{"username": "lydiahallie"}"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"["level", "health"]"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"{"username": "lydiahallie", "level":19, "health":90}"')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-21"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-21"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[a("code",[s._v("JSON.stringify(value[, replacer)")]),s._v("的第二个参数可以是个函数或数组，用以控制哪些值如何被转换为字符串。\nThe second argument of "),a("code",[s._v("JSON.stringify")]),s._v(" is the "),a("em",[s._v("replacer")]),s._v(". The replacer can either be a function or an array, and lets you control what and how the values should be stringified.")]),s._v(" "),a("p",[s._v("如果"),a("code",[s._v("replacer")]),s._v("是个数组，那么就只有包含在数组中的属性将会被转化为字符串。在本例中，只有名为"),a("code",[s._v('"level"')]),s._v(" 和 "),a("code",[s._v('"health"')]),s._v(" 的属性被包括进来， "),a("code",[s._v('"username"')]),s._v("则被排除在外。 "),a("code",[s._v("data")]),s._v(" 就等于 "),a("code",[s._v('"{"level":19, "health":90}"')])]),s._v(" "),a("p",[s._v("如果 "),a("code",[s._v("replacer")]),s._v(" 是个函数，则在序列化过程中，被序列化的值的每个属性都会经过该函数的转换和处理，函数返回的值会成为这个属性的值，最终体现在转化后的JSON字符串中。如果函数返回值为"),a("code",[s._v("undefined")]),s._v("，则该属性会被排除在外。（译者注：Chrome下，经过实验，如果所有属性均返回同一个值的时候有异常，会直接将返回值作为结果输出而不会输出JSON字符串）")]),s._v(" "),a("p",[s._v("如果该参数为null或者未提供，则对象所有的属性都会被序列化。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_63-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_63-输出什么"}},[s._v("#")]),s._v(" 63. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" num "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("increaseNumber")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" num"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("increasePassedNumber")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("number")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" number"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" num1 "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("increaseNumber")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" num2 "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("increasePassedNumber")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("num1"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("num1"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("num2"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("10")]),s._v(", "),a("code",[s._v("10")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("10")]),s._v(", "),a("code",[s._v("11")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("11")]),s._v(", "),a("code",[s._v("11")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("11")]),s._v(", "),a("code",[s._v("12")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-22"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-22"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("一元操作符 "),a("code",[s._v("++")]),s._v(" 先返回操作值, 再累加操作值。"),a("code",[s._v("num1")]),s._v("的值是"),a("code",[s._v("10")]),s._v(", 因为"),a("code",[s._v("increaseNumber")]),s._v("函数首先返回"),a("code",[s._v("num")]),s._v("的值，也就是"),a("code",[s._v("10")]),s._v("，随后再进行 "),a("code",[s._v("num")]),s._v("的累加。")]),s._v(" "),a("p",[a("code",[s._v("num2")]),s._v("是"),a("code",[s._v("10")]),s._v("因为我们将 "),a("code",[s._v("num1")]),s._v("传入"),a("code",[s._v("increasePassedNumber")]),s._v(". "),a("code",[s._v("number")]),s._v("等于"),a("code",[s._v("10")]),s._v("（"),a("code",[s._v("num1")]),s._v("的值同上） "),a("code",[s._v("number")]),s._v("是"),a("code",[s._v("10")]),s._v("，所以"),a("code",[s._v("num2")]),s._v("也是"),a("code",[s._v("10")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_64-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_64-输出什么"}},[s._v("#")]),s._v(" 64. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" value "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" number"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("multiply")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("value "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("number "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("multiply")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("multiply")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("multiply")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("multiply")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("20")]),s._v(", "),a("code",[s._v("40")]),s._v(", "),a("code",[s._v("80")]),s._v(", "),a("code",[s._v("160")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("20")]),s._v(", "),a("code",[s._v("40")]),s._v(", "),a("code",[s._v("20")]),s._v(", "),a("code",[s._v("40")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("20")]),s._v(", "),a("code",[s._v("20")]),s._v(", "),a("code",[s._v("20")]),s._v(", "),a("code",[s._v("40")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("NaN")]),s._v(", "),a("code",[s._v("NaN")]),s._v(", "),a("code",[s._v("20")]),s._v(", "),a("code",[s._v("40")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-19"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-19"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("在ES6中，我们可以使用默认值初始化参数。如果没有给函数传参，或者传的参值为 "),a("code",[s._v('"undefined"')]),s._v(" ，那么参数的值将是默认值。上述例子中，我们将 "),a("code",[s._v("value")]),s._v(" 对象进行了解构并传到一个新对象中，因此 "),a("code",[s._v("x")]),s._v(" 的默认值为 "),a("code",[s._v("{number：10}")]),s._v("。")]),s._v(" "),a("p",[s._v("默认参数在调用时才会进行计算，每次调用函数时，都会创建一个新的对象。我们前两次调用 "),a("code",[s._v("multiply")]),s._v(" 函数且不传递值，那么每一次 "),a("code",[s._v("x")]),s._v(" 的默认值都为 "),a("code",[s._v("{number：10}")]),s._v(" ，因此打印出该数字的乘积值为"),a("code",[s._v("20")]),s._v("。")]),s._v(" "),a("p",[s._v("第三次调用 "),a("code",[s._v("multiply")]),s._v(" 时，我们传递了一个参数，即对象"),a("code",[s._v("value")]),s._v("。 "),a("code",[s._v("*=")]),s._v("运算符实际上是"),a("code",[s._v("x.number = x.number * 2")]),s._v("的简写，我们修改了"),a("code",[s._v("x.number")]),s._v("的值，并打印出值"),a("code",[s._v("20")]),s._v("。")]),s._v(" "),a("p",[s._v("第四次，我们再次传递"),a("code",[s._v("value")]),s._v("对象。 "),a("code",[s._v("x.number")]),s._v("之前被修改为"),a("code",[s._v("20")]),s._v("，所以"),a("code",[s._v("x.number * = 2")]),s._v("打印为"),a("code",[s._v("40")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_65-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_65-输出什么"}},[s._v("#")]),s._v(" 65. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("reduce")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" and "),a("code",[s._v("3")]),s._v(" "),a("code",[s._v("3")]),s._v(" and "),a("code",[s._v("6")]),s._v(" "),a("code",[s._v("4")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" and "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("3")]),s._v(" and "),a("code",[s._v("3")]),s._v(" "),a("code",[s._v("4")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" and "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" and "),a("code",[s._v("3")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" and "),a("code",[s._v("4")]),s._v(" "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" and "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("3")]),s._v(" and "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("4")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-8"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-8"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[a("code",[s._v("reducer")]),s._v(" 函数接收4个参数:")]),s._v(" "),a("ol",[a("li",[s._v("Accumulator (acc) (累计器)")]),s._v(" "),a("li",[s._v("Current Value (cur) (当前值)")]),s._v(" "),a("li",[s._v("Current Index (idx) (当前索引)")]),s._v(" "),a("li",[s._v("Source Array (src) (源数组)")])]),s._v(" "),a("p",[a("code",[s._v("reducer")]),s._v(" 函数的返回值将会分配给累计器，该返回值在数组的每个迭代中被记住，并最后成为最终的单个结果值。")]),s._v(" "),a("p",[a("code",[s._v("reducer")]),s._v(" 函数还有一个可选参数"),a("code",[s._v("initialValue")]),s._v(", 该参数将作为第一次调用回调函数时的第一个参数的值。 如果没有提供初始值，则将使用数组中的第一个元素。")]),s._v(" "),a("p",[s._v("在上述例子，"),a("code",[s._v("reduce")]),s._v("方法接收的第一个参数(Accumulator)是"),a("code",[s._v("x")]),s._v(", 第二个参数(Current Value)是"),a("code",[s._v("y")]),s._v("。")]),s._v(" "),a("p",[s._v("在第一次调用时，累加器"),a("code",[s._v("x")]),s._v("为"),a("code",[s._v("1")]),s._v("，当前值"),a("code",[s._v("“y”")]),s._v("为"),a("code",[s._v("2")]),s._v("，打印出累加器和当前值："),a("code",[s._v("1")]),s._v("和"),a("code",[s._v("2")]),s._v("。")]),s._v(" "),a("p",[s._v("例子中我们的回调函数没有返回任何值，只是打印累加器的值和当前值。如果函数没有返回值，则默认返回"),a("code",[s._v("undefined")]),s._v("。 在下一次调用时，累加器为"),a("code",[s._v("undefined")]),s._v("，当前值为“3”, 因此"),a("code",[s._v("undefined")]),s._v("和"),a("code",[s._v("3")]),s._v("被打印出。")]),s._v(" "),a("p",[s._v("在第四次调用时，回调函数依然没有返回值。 累加器再次为 "),a("code",[s._v("undefined")]),s._v(" ，当前值为“4”。 "),a("code",[s._v("undefined")]),s._v("和"),a("code",[s._v("4")]),s._v("被打印出。\n")])]),a("p"),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_66-使用哪个构造函数可以成功继承dog类"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_66-使用哪个构造函数可以成功继承dog类"}},[s._v("#")]),s._v(" 66. 使用哪个构造函数可以成功继承"),a("code",[s._v("Dog")]),s._v("类?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Dog")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("name")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Labrador")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("extends")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Dog")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 1")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" size")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("size "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" size"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 2")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" size")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("super")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("size "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" size"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 3")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("size")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("super")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("size "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" size"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 4")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" size")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("size "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" size"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br"),a("span",{staticClass:"line-number"},[s._v("16")]),a("br"),a("span",{staticClass:"line-number"},[s._v("17")]),a("br"),a("span",{staticClass:"line-number"},[s._v("18")]),a("br"),a("span",{staticClass:"line-number"},[s._v("19")]),a("br"),a("span",{staticClass:"line-number"},[s._v("20")]),a("br"),a("span",{staticClass:"line-number"},[s._v("21")]),a("br"),a("span",{staticClass:"line-number"},[s._v("22")]),a("br"),a("span",{staticClass:"line-number"},[s._v("23")]),a("br"),a("span",{staticClass:"line-number"},[s._v("24")]),a("br"),a("span",{staticClass:"line-number"},[s._v("25")]),a("br"),a("span",{staticClass:"line-number"},[s._v("26")]),a("br"),a("span",{staticClass:"line-number"},[s._v("27")]),a("br"),a("span",{staticClass:"line-number"},[s._v("28")]),a("br")])]),a("ul",[a("li",[s._v("A: 1")]),s._v(" "),a("li",[s._v("B: 2")]),s._v(" "),a("li",[s._v("C: 3")]),s._v(" "),a("li",[s._v("D: 4")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-17"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-17"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("在子类中，在调用"),a("code",[s._v("super")]),s._v("之前不能访问到"),a("code",[s._v("this")]),s._v("关键字。 如果这样做，它将抛出一个"),a("code",[s._v("ReferenceError")]),s._v("：1和4将引发一个引用错误。")]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("super")]),s._v("关键字，需要用给定的参数来调用父类的构造函数。 父类的构造函数接收"),a("code",[s._v("name")]),s._v("参数，因此我们需要将"),a("code",[s._v("name")]),s._v("传递给"),a("code",[s._v("super")]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v("Labrador")]),s._v("类接收两个参数，"),a("code",[s._v("name")]),s._v("参数是由于它继承了"),a("code",[s._v("Dog")]),s._v("，"),a("code",[s._v("size")]),s._v("作为"),a("code",[s._v("Labrador")]),s._v("类的额外属性，它们都需要传递给"),a("code",[s._v("Labrador")]),s._v("的构造函数，因此使用构造函数2正确完成。\n")])]),a("p"),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_67-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_67-输出什么"}},[s._v("#")]),s._v(" 67. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// index.js")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("'running index"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("js"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("import")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" sum "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("from")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'./sum.js'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sum")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// sum.js")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'running sum.js'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("export")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("sum")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("a"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" b")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" a "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" b"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("ul",[a("li",[s._v("A: "),a("code",[s._v("running index.js")]),s._v(", "),a("code",[s._v("running sum.js")]),s._v(", "),a("code",[s._v("3")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("running sum.js")]),s._v(", "),a("code",[s._v("running index.js")]),s._v(", "),a("code",[s._v("3")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("running sum.js")]),s._v(", "),a("code",[s._v("3")]),s._v(", "),a("code",[s._v("running index.js")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("running index.js")]),s._v(", "),a("code",[s._v("undefined")]),s._v(", "),a("code",[s._v("running sum.js")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-18"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-18"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[a("code",[s._v("import")]),s._v("命令是编译阶段执行的，在代码运行之前。因此这意味着被导入的模块会先运行，而导入模块的文件会后执行。")]),s._v(" "),a("p",[s._v("这是CommonJS中"),a("code",[s._v("require（）")]),s._v("和"),a("code",[s._v("import")]),s._v("之间的区别。使用"),a("code",[s._v("require()")]),s._v("，您可以在运行代码时根据需要加载依赖项。 如果我们使用"),a("code",[s._v("require")]),s._v("而不是"),a("code",[s._v("import")]),s._v("，"),a("code",[s._v("running index.js")]),s._v("，"),a("code",[s._v("running sum.js")]),s._v("，"),a("code",[s._v("3")]),s._v("会被依次打印。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_68-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_68-输出什么"}},[s._v("#")]),s._v(" 68. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Number")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Number")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Boolean")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("false")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Boolean")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("false")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Symbol")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'foo'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Symbol")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'foo'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("true")]),s._v(", "),a("code",[s._v("true")]),s._v(", "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("false")]),s._v(", "),a("code",[s._v("true")]),s._v(", "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("true")]),s._v(", "),a("code",[s._v("false")]),s._v(", "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("true")]),s._v(", "),a("code",[s._v("true")]),s._v(", "),a("code",[s._v("true")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-23"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-23"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("每个"),a("code",[s._v("Symbol")]),s._v("都是完全唯一的。传递给"),a("code",[s._v("Symbol")]),s._v("的参数只是给"),a("code",[s._v("Symbol")]),s._v("的一个描述。 "),a("code",[s._v("Symbol")]),s._v("的值不依赖于传递的参数。 当我们测试相等时，我们创建了两个全新的符号：第一个"),a("code",[s._v("Symbol（'foo'）")]),s._v("，第二个"),a("code",[s._v("Symbol（'foo'）")]),s._v(", 这两个值是唯一的，彼此不相等，因此返回"),a("code",[s._v("false")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_69-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_69-输出什么"}},[s._v("#")]),s._v(" 69. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia Hallie"')]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("padStart")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("13")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("padStart")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"Lydia Hallie"')]),s._v(", "),a("code",[s._v('"Lydia Hallie"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('" Lydia Hallie"')]),s._v(", "),a("code",[s._v('" Lydia Hallie"')]),s._v(" ("),a("code",[s._v('"[13x whitespace]Lydia Hallie"')]),s._v(", "),a("code",[s._v('"[2x whitespace]Lydia Hallie"')]),s._v(")")]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('" Lydia Hallie"')]),s._v(", "),a("code",[s._v('"Lydia Hallie"')]),s._v(" ("),a("code",[s._v('"[1x whitespace]Lydia Hallie"')]),s._v(", "),a("code",[s._v('"Lydia Hallie"')]),s._v(")")]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"Lydia Hallie"')]),s._v(", "),a("code",[s._v('"Lyd"')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-20"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-20"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("padStart")]),s._v("方法，我们可以在字符串的开头添加填充。传递给此方法的参数是字符串的总长度（包含填充）。字符串"),a("code",[s._v("Lydia Hallie")]),s._v("的长度为"),a("code",[s._v("12")]),s._v(", 因此"),a("code",[s._v("name.padStart（13）")]),s._v("在字符串的开头只会插入1（"),a("code",[s._v("13 - 12 = 1")]),s._v("）个空格。")]),s._v(" "),a("p",[s._v("如果传递给"),a("code",[s._v("padStart")]),s._v("方法的参数小于字符串的长度，则不会添加填充。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_70-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_70-输出什么"}},[s._v("#")]),s._v(" 70. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🥑"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"💻"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"🥑💻"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("257548")])]),s._v(" "),a("li",[s._v("C: A string containing their code points")]),s._v(" "),a("li",[s._v("D: Error")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-24"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-24"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("+")]),s._v("运算符，您可以连接字符串。 上述情况，我们将字符串"),a("code",[s._v("“🥑”")]),s._v("与字符串"),a("code",[s._v("”💻“")]),s._v("连接起来，产生"),a("code",[s._v("”🥑💻“")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_71-如何能打印出console-log语句后注释掉的值？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_71-如何能打印出console-log语句后注释掉的值？"}},[s._v("#")]),s._v(" 71. 如何能打印出"),a("code",[s._v("console.log")]),s._v("语句后注释掉的值？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("startGame")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" answer "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("yield")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Do you love JavaScript?"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("if")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("answer "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!==")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Yes"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Oh wow... Guess we\'re gone here"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"JavaScript loves you back ❤️"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" game "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("startGame")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("/* 1 */")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// Do you love JavaScript?")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("/* 2 */")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// JavaScript loves you back ❤️")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('game.next("Yes").value')]),s._v(" and "),a("code",[s._v("game.next().value")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('game.next.value("Yes")')]),s._v(" and "),a("code",[s._v("game.next.value()")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("game.next().value")]),s._v(" and "),a("code",[s._v('game.next("Yes").value')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("game.next.value()")]),s._v(" and "),a("code",[s._v('game.next.value("Yes")')])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-21"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-21"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[a("code",[s._v("generator")]),s._v("函数在遇到"),a("code",[s._v("yield")]),s._v("关键字时会“暂停”其执行。 首先，我们需要让函数产生字符串"),a("code",[s._v("Do you love JavaScript?")]),s._v("，这可以通过调用"),a("code",[s._v("game.next().value")]),s._v("来完成。上述函数的第一行就有一个"),a("code",[s._v("yield")]),s._v("关键字，那么运行立即停止了，"),a("code",[s._v("yield")]),s._v("表达式本身没有返回值，或者说总是返回"),a("code",[s._v("undefined")]),s._v(", 这意味着此时变量 "),a("code",[s._v("answer")]),s._v(" 为"),a("code",[s._v("undefined")])]),s._v(" "),a("p",[a("code",[s._v("next")]),s._v("方法可以带一个参数，该参数会被当作上一个 "),a("code",[s._v("yield")]),s._v(" 表达式的返回值。当我们调用"),a("code",[s._v('game.next("Yes").value')]),s._v("时，先前的 "),a("code",[s._v("yield")]),s._v(" 的返回值将被替换为传递给"),a("code",[s._v("next()")]),s._v("函数的参数"),a("code",[s._v('"Yes"')]),s._v("。此时变量 "),a("code",[s._v("answer")]),s._v(" 被赋值为 "),a("code",[s._v('"Yes"')]),s._v("，"),a("code",[s._v("if")]),s._v("语句返回"),a("code",[s._v("false")]),s._v("，所以"),a("code",[s._v("JavaScript loves you back ❤️")]),s._v("被打印。")]),s._v(" "),a("p",[a("code",[s._v("next")]),s._v("方法返回一个对象，它的"),a("code",[s._v("value")]),s._v("属性值是当前"),a("code",[s._v("yield")]),s._v("表达式的值，如上述"),a("code",[s._v('"Do you love JavaScript?"')]),s._v(","),a("code",[s._v("done")]),s._v("属性是一个布尔值，表示是否遍历结束。")]),s._v(" "),a("p",[s._v("Generator函数从上次"),a("code",[s._v("yield")]),s._v("表达式停下的地方，一直执行到return语句（如果没有return语句，就执行到函数结束)。"),a("code",[s._v("next")]),s._v("方法返回的最后一个对象的"),a("code",[s._v("value")]),s._v("属性的值就是紧跟在"),a("code",[s._v("return")]),s._v("语句后面的表达式的值（如果没有"),a("code",[s._v("return")]),s._v("语句，则"),a("code",[s._v("value")]),s._v("属性的值为"),a("code",[s._v("undefined")]),s._v("），此时"),a("code",[s._v("done")]),s._v("属性的值"),a("code",[s._v("true")]),s._v("，表示遍历已经结束。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_72-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_72-输出什么"}},[s._v("#")]),s._v(" 72. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("String"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("raw"),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("Hello\\nworld")]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("Hello world!")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Hello")]),s._v(" "),a("br"),s._v(" "),a("code",[s._v("world")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Hello\\nworld")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Hello\\n")]),s._v(" "),a("br"),s._v(" "),a("code",[s._v("world")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-22"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-22"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[a("code",[s._v("String.raw")]),s._v("函数是用来获取一个模板字符串的原始字符串的，它返回一个字符串，其中忽略了转义符（"),a("code",[s._v("\\n")]),s._v("，"),a("code",[s._v("\\v")]),s._v("，"),a("code",[s._v("\\t")]),s._v("等）。但反斜杠可能造成问题，因为你可能会遇到下面这种类似情况：")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" path "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("C:\\Documents\\Projects\\table.html")]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),s._v("\nString"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("raw"),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),s._v("path"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("这将导致：")]),s._v(" "),a("p",[a("code",[s._v('"C:DocumentsProjects able.html"')])]),s._v(" "),a("p",[s._v("直接使用"),a("code",[s._v("String.raw")])]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("String"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("raw"),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("C:\\Documents\\Projects\\table.html")]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("它会忽略转义字符并打印："),a("code",[s._v("C:\\Documents\\Projects\\table.html")])]),s._v(" "),a("p",[s._v("上述情况，字符串是"),a("code",[s._v("Hello\\nworld")]),s._v("被打印出。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_73-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_73-输出什么"}},[s._v("#")]),s._v(" 73. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("async")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getData")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("await")]),s._v(" Promise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("resolve")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"I made it!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" data "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getData")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("data"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"I made it!"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('Promise {<resolved>: "I made it!"}')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Promise {<pending>}")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-23"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-23"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("异步函数始终返回一个promise。"),a("code",[s._v("await")]),s._v("仍然需要等待promise的解决：当我们调用"),a("code",[s._v("getData()")]),s._v("并将其赋值给"),a("code",[s._v("data")]),s._v("，此时"),a("code",[s._v("data")]),s._v("为"),a("code",[s._v("getData")]),s._v("方法返回的一个挂起的promise，该promise并没有解决。")]),s._v(" "),a("p",[s._v("如果我们想要访问已解决的值"),a("code",[s._v('"I made it!"')]),s._v("，可以在"),a("code",[s._v("data")]),s._v("上使用"),a("code",[s._v(".then()")]),s._v("方法：")]),s._v(" "),a("p",[a("code",[s._v("data.then(res => console.log(res))")])]),s._v(" "),a("p",[s._v("这样将打印 "),a("code",[s._v('"I made it!"')])]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_74-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_74-输出什么"}},[s._v("#")]),s._v(" 74. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("addToList")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("item"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" list")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" list"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("push")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("item"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" result "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("addToList")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"apple"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"banana"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("result"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("['apple', 'banana']")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("2")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-19"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-19"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[a("code",[s._v("push()")]),s._v("方法返回新数组的长度。一开始，数组包含一个元素（字符串"),a("code",[s._v('"banana"')]),s._v("），长度为1。 在数组中添加字符串"),a("code",[s._v('"apple"')]),s._v("后，长度变为2，并将从"),a("code",[s._v("addToList")]),s._v("函数返回。")]),s._v(" "),a("p",[a("code",[s._v("push")]),s._v("方法修改原始数组，如果你想从函数返回数组而不是数组长度，那么应该在push "),a("code",[s._v("item")]),s._v("之后返回"),a("code",[s._v("list")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_75-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_75-输出什么"}},[s._v("#")]),s._v(" 75. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" box "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" x"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("20")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nObject"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("freeze")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("box"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" shape "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" box"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nshape"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("100")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("shape"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("{ x: 100, y: 20 }")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("{ x: 10, y: 20 }")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("{ x: 100 }")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("blockquote",[a("p",[s._v("mark")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-20"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-20"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[a("code",[s._v("Object.freeze")]),s._v("使得无法添加、删除或修改对象的属性（除非属性的值是另一个对象）。")]),s._v(" "),a("p",[s._v("当我们创建变量"),a("code",[s._v("shape")]),s._v("并将其设置为等于冻结对象"),a("code",[s._v("box")]),s._v("时，"),a("code",[s._v("shape")]),s._v("指向的也是冻结对象。你可以使用"),a("code",[s._v("Object.isFrozen")]),s._v("检查一个对象是否被冻结，上述情况，"),a("code",[s._v("Object.isFrozen（shape）")]),s._v("将返回"),a("code",[s._v("true")]),s._v("。")]),s._v(" "),a("p",[s._v("由于"),a("code",[s._v("shape")]),s._v("被冻结，并且"),a("code",[s._v("x")]),s._v("的值不是对象，所以我们不能修改属性"),a("code",[s._v("x")]),s._v("。 "),a("code",[s._v("x")]),s._v("仍然等于"),a("code",[s._v("10")]),s._v("，"),a("code",[s._v("{x：10，y：20}")]),s._v("被打印。")]),s._v(" "),a("p",[s._v("注意，上述例子我们对属性"),a("code",[s._v("x")]),s._v("进行修改，可能会导致抛出TypeError异常（最常见但不仅限于严格模式下时）。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_76-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_76-输出什么"}},[s._v("#")]),s._v(" 76. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" myName "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"Lydia"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"myName"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-9"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-9"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("当我们从右侧的对象解构属性"),a("code",[s._v("name")]),s._v("时，我们将其值"),a("code",[s._v("Lydia")]),s._v("分配给名为"),a("code",[s._v("myName")]),s._v("的变量。")]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("{name：myName}")]),s._v("，我们是在告诉JavaScript我们要创建一个名为"),a("code",[s._v("myName")]),s._v("的新变量，并且其值是右侧对象的"),a("code",[s._v("name")]),s._v("属性的值。")]),s._v(" "),a("p",[s._v("当我们尝试打印"),a("code",[s._v("name")]),s._v("，一个未定义的变量时，就会引发"),a("code",[s._v("ReferenceError")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_77-以下是个纯函数么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_77-以下是个纯函数么"}},[s._v("#")]),s._v(" 77. 以下是个纯函数么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sum")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("a"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" b")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" a "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" b"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: Yes")]),s._v(" "),a("li",[s._v("B: No")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-25"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-25"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("纯函数一种若输入参数相同，则永远会得到相同输出的函数。")]),s._v(" "),a("p",[a("code",[s._v("sum")]),s._v("函数总是返回相同的结果。 如果我们传递"),a("code",[s._v("1")]),s._v("和"),a("code",[s._v("2")]),s._v("，它将总是返回"),a("code",[s._v("3")]),s._v("而没有副作用。 如果我们传递"),a("code",[s._v("5")]),s._v("和"),a("code",[s._v("10")]),s._v("，它将总是返回"),a("code",[s._v("15")]),s._v("，依此类推，这是纯函数的定义。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_78-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_78-输出什么"}},[s._v("#")]),s._v(" 78. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("add")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" cache "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("num")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("if")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("num "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("in")]),s._v(" cache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n      "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("From cache! ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),s._v("cache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("num"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("else")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n      "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" result "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" num "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n      cache"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("num"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" result"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n      "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("Calculated! ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),s._v("result"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" addFunction "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("addFunction")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("addFunction")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("addFunction")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("5")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br"),a("span",{staticClass:"line-number"},[s._v("16")]),a("br"),a("span",{staticClass:"line-number"},[s._v("17")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("Calculated! 20")]),s._v(" "),a("code",[s._v("Calculated! 20")]),s._v(" "),a("code",[s._v("Calculated! 20")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Calculated! 20")]),s._v(" "),a("code",[s._v("From cache! 20")]),s._v(" "),a("code",[s._v("Calculated! 20")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Calculated! 20")]),s._v(" "),a("code",[s._v("From cache! 20")]),s._v(" "),a("code",[s._v("From cache! 20")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Calculated! 20")]),s._v(" "),a("code",[s._v("From cache! 20")]),s._v(" "),a("code",[s._v("Error")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-24"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-24"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[a("code",[s._v("add")]),s._v("函数是一个记忆函数。 通过记忆化，我们可以缓存函数的结果，以加快其执行速度。上述情况，我们创建一个"),a("code",[s._v("cache")]),s._v("对象，用于存储先前返回过的值。")]),s._v(" "),a("p",[s._v("如果我们使用相同的参数多次调用"),a("code",[s._v("addFunction")]),s._v("函数，它首先检查缓存中是否已有该值，如果有，则返回缓存值，这将节省执行时间。如果没有，那么它将计算该值，并存储在缓存中。")]),s._v(" "),a("p",[s._v("我们用相同的值三次调用了"),a("code",[s._v("addFunction")]),s._v("函数：")]),s._v(" "),a("p",[s._v("在第一次调用，"),a("code",[s._v("num")]),s._v("等于"),a("code",[s._v("10")]),s._v("时函数的值尚未缓存，if语句"),a("code",[s._v("num in cache")]),s._v("返回"),a("code",[s._v("false")]),s._v("，else块的代码被执行："),a("code",[s._v("Calculated! 20")]),s._v("，并且其结果被添加到缓存对象，"),a("code",[s._v("cache")]),s._v("现在看起来像"),a("code",[s._v("{10：20}")]),s._v("。")]),s._v(" "),a("p",[s._v("第二次，"),a("code",[s._v("cache")]),s._v("对象包含"),a("code",[s._v("10")]),s._v("的返回值。 if语句 "),a("code",[s._v("num in cache")]),s._v(" 返回"),a("code",[s._v("true")]),s._v("，"),a("code",[s._v("From cache! 20")]),s._v("被打印。")]),s._v(" "),a("p",[s._v("第三次，我们将"),a("code",[s._v("5 * 2")]),s._v("(值为10)传递给函数。 "),a("code",[s._v("cache")]),s._v("对象包含"),a("code",[s._v("10")]),s._v("的返回值。 if语句 "),a("code",[s._v("num in cache")]),s._v(" 返回"),a("code",[s._v("true")]),s._v("，"),a("code",[s._v("From cache! 20")]),s._v("被打印。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_79-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_79-输出什么"}},[s._v("#")]),s._v(" "),a("a",{attrs:{name:"20190726"}}),s._v("79. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" myLifeSummedUp "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"☕"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"💻"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🍷"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🍫"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" item "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("in")]),s._v(" myLifeSummedUp"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("item"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" item "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("of")]),s._v(" myLifeSummedUp"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("item"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("0")]),s._v(" "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("3")]),s._v(" and "),a("code",[s._v('"☕"')]),s._v(" "),a("code",[s._v('"💻"')]),s._v(" "),a("code",[s._v('"🍷"')]),s._v(" "),a("code",[s._v('"🍫"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"☕"')]),s._v(" "),a("code",[s._v('"💻"')]),s._v(" "),a("code",[s._v('"🍷"')]),s._v(" "),a("code",[s._v('"🍫"')]),s._v(" and "),a("code",[s._v('"☕"')]),s._v(" "),a("code",[s._v('"💻"')]),s._v(" "),a("code",[s._v('"🍷"')]),s._v(" "),a("code",[s._v('"🍫"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"☕"')]),s._v(" "),a("code",[s._v('"💻"')]),s._v(" "),a("code",[s._v('"🍷"')]),s._v(" "),a("code",[s._v('"🍫"')]),s._v(" and "),a("code",[s._v("0")]),s._v(" "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("3")])]),s._v(" "),a("li",[s._v("D:  "),a("code",[s._v("0")]),s._v(" "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("3")]),s._v(" and "),a("code",[s._v('{0: "☕", 1: "💻", 2: "🍷", 3: "🍫"}')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-26"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-26"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("通过"),a("code",[s._v("for-in")]),s._v("循环，我们可以遍历一个对象"),a("strong",[s._v("自有的")]),s._v("、"),a("strong",[s._v("继承的")]),s._v("、"),a("strong",[s._v("可枚举的")]),s._v("、"),a("strong",[s._v("非Symbol的")]),s._v("属性。 在数组中，可枚举属性是数组元素的“键”， 即它们的索引。 类似于下面这个对象：")]),s._v(" "),a("p",[a("code",[s._v('{0: "☕", 1: "💻", 2: "🍷", 3: "🍫"}')])]),s._v(" "),a("p",[s._v("其中键则是可枚举属性，因此 "),a("code",[s._v("0")]),s._v("，"),a("code",[s._v("1")]),s._v("，"),a("code",[s._v("2")]),s._v("，"),a("code",[s._v("3")]),s._v("被记录。")]),s._v(" "),a("p",[s._v("通过"),a("code",[s._v("for-of")]),s._v("循环，我们可以迭代"),a("strong",[s._v("可迭代对象")]),s._v("（包括 "),a("code",[s._v("Array")]),s._v("，"),a("code",[s._v("Map")]),s._v("，"),a("code",[s._v("Set")]),s._v("，"),a("code",[s._v("String")]),s._v("，"),a("code",[s._v("arguments")]),s._v("等）。当我们迭代数组时，在每次迭代中，不同属性的值将被分配给变量"),a("code",[s._v("item")]),s._v(", 因此"),a("code",[s._v("“☕”")]),s._v("，"),a("code",[s._v("“💻“")]),s._v("，"),a("code",[s._v("”🍷”")]),s._v("，"),a("code",[s._v("“🍫“")]),s._v("被打印。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_80-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_80-输出什么"}},[s._v("#")]),s._v(" 80. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" list "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("/")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("list"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('["1 + 2", "1 * 2", "1 / 2"]')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('["12", 2, 0.5]')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("[3, 2, 0.5]")])]),s._v(" "),a("li",[s._v("D:  "),a("code",[s._v("[1, 1, 1]")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-25"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-25"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("数组元素可以包含任何值。 数字，字符串，布尔值，对象，数组，"),a("code",[s._v("null")]),s._v("，"),a("code",[s._v("undeifned")]),s._v(", 以及其他表达式，如日期，函数和计算。")]),s._v(" "),a("p",[s._v("元素将等于返回的值。 "),a("code",[s._v("1 + 2")]),s._v("返回"),a("code",[s._v("3")]),s._v("，"),a("code",[s._v("1 * 2")]),s._v("返回'2"),a("code",[s._v("，'1 / 2")]),s._v("返回"),a("code",[s._v("0.5")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h2",{attrs:{id:"question-81-100"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#question-81-100"}},[s._v("#")]),s._v(" question: 81-100")]),s._v(" "),a("h4",{attrs:{id:"_81-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_81-输出什么"}},[s._v("#")]),s._v(" 81. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("name")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("Hi there, ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sayHi")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("Hi there,")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Hi there, undefined")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Hi there, null")])]),s._v(" "),a("li",[s._v("D:  "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-21"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-21"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("默认情况下，如果不给函数传参，参数的值将为"),a("code",[s._v("undefined")]),s._v("。 上述情况，我们没有给参数"),a("code",[s._v("name")]),s._v("传值。 "),a("code",[s._v("name")]),s._v("等于"),a("code",[s._v("undefined")]),s._v("，并被打印。")]),s._v(" "),a("p",[s._v("在ES6中，我们可以使用默认参数覆盖此默认的"),a("code",[s._v("undefined")]),s._v("值。 例如：")]),s._v(" "),a("p",[a("code",[s._v("function sayHi（name =“Lydia”）{...}")])]),s._v(" "),a("p",[s._v("在这种情况下，如果我们没有传递值或者如果我们传递"),a("code",[s._v("undefined")]),s._v("，"),a("code",[s._v("name")]),s._v("总是等于字符串"),a("code",[s._v("Lydia")])]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_82-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_82-输出什么"}},[s._v("#")]),s._v(" 82. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("var")]),s._v(" status "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"😎"')]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setTimeout")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" status "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"😍"')]),s._v("\n\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" data "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    status"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🥑"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getStatus")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n      "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("status\n    "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("data"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getStatus")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("data"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getStatus")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("call")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"🥑"')]),s._v(" and "),a("code",[s._v('"😍"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"🥑"')]),s._v(" and "),a("code",[s._v('"😎"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"😍"')]),s._v(" and "),a("code",[s._v('"😎"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"😎"')]),s._v(" and "),a("code",[s._v('"😎"')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-22"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-22"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[a("code",[s._v("this")]),s._v("关键字的指向取决于使用它的位置。 在"),a("strong",[s._v("函数")]),s._v("中，比如"),a("code",[s._v("getStatus")]),s._v("，"),a("code",[s._v("this")]),s._v("指向的是调用它的对象，上述例子中"),a("code",[s._v("data")]),s._v("对象调用了"),a("code",[s._v("getStatus")]),s._v("，因此"),a("code",[s._v("this")]),s._v("指向的就是"),a("code",[s._v("data")]),s._v("对象。 当我们打印"),a("code",[s._v("this.status")]),s._v("时，"),a("code",[s._v("data")]),s._v("对象的"),a("code",[s._v("status")]),s._v("属性被打印，即"),a("code",[s._v("”🥑“")]),s._v("。")]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("call")]),s._v("方法，可以更改"),a("code",[s._v("this")]),s._v("指向的对象。"),a("code",[s._v("data.getStatus.call(this)")]),s._v("是将"),a("code",[s._v("this")]),s._v("的指向由"),a("code",[s._v("data")]),s._v("对象更改为全局对象。在全局对象上，有一个名为"),a("code",[s._v("status")]),s._v("的变量，其值为"),a("code",[s._v("”😎“")]),s._v("。 因此打印"),a("code",[s._v("this.status")]),s._v("时，会打印"),a("code",[s._v("“😎”")]),s._v("。\n")])]),a("p"),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_83-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_83-输出什么"}},[s._v("#")]),s._v(" 83. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" city "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("city\ncity "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Amsterdam"')]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('{ name: "Lydia", age: 21 }')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('{ name: "Lydia", age: 21, city: "Amsterdam" }')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('{ name: "Lydia", age: 21, city: undefined }')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"Amsterdam"')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-27"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-27"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("我们将变量"),a("code",[s._v("city")]),s._v("设置为等于"),a("code",[s._v("person")]),s._v("对象上名为"),a("code",[s._v("city")]),s._v("的属性的值。 这个对象上没有名为"),a("code",[s._v("city")]),s._v("的属性，因此变量"),a("code",[s._v("city")]),s._v("的值为"),a("code",[s._v("undefined")]),s._v("。")]),s._v(" "),a("p",[s._v("请注意，我们没有引用"),a("code",[s._v("person")]),s._v("对象本身，只是将变量"),a("code",[s._v("city")]),s._v("设置为等于"),a("code",[s._v("person")]),s._v("对象上"),a("code",[s._v("city")]),s._v("属性的当前值。")]),s._v(" "),a("p",[s._v("然后，我们将"),a("code",[s._v("city")]),s._v("设置为等于字符串"),a("code",[s._v("“Amsterdam”")]),s._v("。 这不会更改person对象：没有对该对象的引用。")]),s._v(" "),a("p",[s._v("因此打印"),a("code",[s._v("person")]),s._v("对象时，会返回未修改的对象。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_84-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_84-输出什么"}},[s._v("#")]),s._v(" 84. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("checkAge")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("age")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("if")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("age "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("18")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" message "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Sorry, you\'re too young."')]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("else")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" message "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Yay! You\'re old enough!"')]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" message\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("checkAge")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"Sorry, you\'re too young."')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"Yay! You\'re old enough!"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("ReferenceError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-26"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-26"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[a("code",[s._v("const")]),s._v("和"),a("code",[s._v("let")]),s._v("声明的变量是具有"),a("strong",[s._v("块级作用域")]),s._v("的，块是大括号（"),a("code",[s._v("{}")]),s._v("）之间的任何东西, 即上述情况"),a("code",[s._v("if / else")]),s._v("语句的花括号。 由于块级作用域，我们无法在声明的块之外引用变量，因此抛出"),a("code",[s._v("ReferenceError")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_85-什么样的信息将被打印"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_85-什么样的信息将被打印"}},[s._v("#")]),s._v(" 85. 什么样的信息将被打印?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("fetch")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'https://www.website.com/api/user/1'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("then")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("res")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("json")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("then")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("res")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("fetch")]),s._v("方法的结果")]),s._v(" "),a("li",[s._v("B: 第二次调用"),a("code",[s._v("fetch")]),s._v("方法的结果")]),s._v(" "),a("li",[s._v("C: 前一个"),a("code",[s._v(".then()")]),s._v("中回调方法返回的结果")]),s._v(" "),a("li",[s._v("D: 总是"),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-27"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-27"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("第二个"),a("code",[s._v(".then")]),s._v("中"),a("code",[s._v("res")]),s._v("的值等于前一个"),a("code",[s._v(".then")]),s._v("中的回调函数返回的值。 你可以像这样继续链接"),a("code",[s._v(".then")]),s._v("，将值传递给下一个处理程序。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_86-哪个选项是将hasname设置为true的方法，前提是不能将true作为参数传递"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_86-哪个选项是将hasname设置为true的方法，前提是不能将true作为参数传递"}},[s._v("#")]),s._v(" 86. 哪个选项是将"),a("code",[s._v("hasName")]),s._v("设置为"),a("code",[s._v("true")]),s._v("的方法，前提是不能将"),a("code",[s._v("true")]),s._v("作为参数传递?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getName")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("name")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" hasName "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("//")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("!!name")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("name")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("new Boolean(name)")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("name.length")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-28"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-28"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("使用逻辑非运算符"),a("code",[s._v("!")]),s._v("，将返回一个布尔值，使用"),a("code",[s._v("!! name")]),s._v("，我们可以确定"),a("code",[s._v("name")]),s._v("的值是真的还是假的。 如果"),a("code",[s._v("name")]),s._v("是真实的，那么"),a("code",[s._v("!name")]),s._v("返回"),a("code",[s._v("false")]),s._v("。 "),a("code",[s._v("!false")]),s._v("返回"),a("code",[s._v("true")]),s._v("。")]),s._v(" "),a("p",[s._v("通过将"),a("code",[s._v("hasName")]),s._v("设置为"),a("code",[s._v("name")]),s._v("，可以将"),a("code",[s._v("hasName")]),s._v("设置为等于传递给"),a("code",[s._v("getName")]),s._v("函数的值，而不是布尔值"),a("code",[s._v("true")]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v("new Boolean（true）")]),s._v("返回一个对象包装器，而不是布尔值本身。")]),s._v(" "),a("p",[a("code",[s._v("name.length")]),s._v("返回传递的参数的长度，而不是布尔值"),a("code",[s._v("true")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_87-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_87-输出什么"}},[s._v("#")]),s._v(" 87. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"I want pizza"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"""')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"I"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("SyntaxError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-23"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-23"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("可以使用方括号表示法获取字符串中特定索引的字符，字符串中的第一个字符具有索引0，依此类推。 在这种情况下，我们想要得到索引为0的元素，字符"),a("code",[s._v("'I'")]),s._v("被记录。")]),s._v(" "),a("p",[s._v("请注意，IE7及更低版本不支持此方法。 在这种情况下，应该使用"),a("code",[s._v(".charAt（）")])]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_88-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_88-输出什么"}},[s._v("#")]),s._v(" 88. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sum")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("num1"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" num2 "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" num1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("num1 "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" num2"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sum")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("NaN")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("20")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("ReferenceError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-24"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-24"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("您可以将默认参数的值设置为函数的另一个参数，只要另一个参数定义在其之前即可。 我们将值"),a("code",[s._v("10")]),s._v("传递给"),a("code",[s._v("sum")]),s._v("函数。 如果"),a("code",[s._v("sum")]),s._v("函数只接收1个参数，则意味着没有传递"),a("code",[s._v("num2")]),s._v("的值，这种情况下，"),a("code",[s._v("num1")]),s._v("的值等于传递的值"),a("code",[s._v("10")]),s._v("。 "),a("code",[s._v("num2")]),s._v("的默认值是"),a("code",[s._v("num1")]),s._v("的值，即"),a("code",[s._v("10")]),s._v("。 "),a("code",[s._v("num1 + num2")]),s._v("返回"),a("code",[s._v("20")]),s._v("。")]),s._v(" "),a("p",[s._v("如果您尝试将默认参数的值设置为后面定义的参数，则可能导致参数的值尚未初始化，从而引发错误。比如：")]),s._v(" "),a("div",{staticClass:"language-js line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-js"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("test")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("m "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" n "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("m"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("test")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// Uncaught ReferenceError: Cannot access 'n' before initialization")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("test")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 3 2")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("test")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 3 4")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_89-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_89-输出什么"}},[s._v("#")]),s._v(" 89. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// module.js")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("export")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("default")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Hello world"')]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("export")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// index.js")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("import")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("as")]),s._v(" data "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("from")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"./module"')]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("data"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('{ default: function default(), name: "Lydia" }')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("{ default: function default() }")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('{ default: "Hello world", name: "Lydia" }')])]),s._v(" "),a("li",[s._v("D: Global object of "),a("code",[s._v("module.js")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-29"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-29"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("import * as name")]),s._v("语法，我们将"),a("code",[s._v("module.js")]),s._v("文件中所有"),a("code",[s._v("export")]),s._v("导入到"),a("code",[s._v("index.js")]),s._v("文件中，并且创建了一个名为"),a("code",[s._v("data")]),s._v("的新对象。 在"),a("code",[s._v("module.js")]),s._v("文件中，有两个导出：默认导出和命名导出。 默认导出是一个返回字符串“Hello World”的函数，命名导出是一个名为"),a("code",[s._v("name")]),s._v("的变量，其值为字符串"),a("code",[s._v("“Lydia”")]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v("data")]),s._v("对象具有默认导出的"),a("code",[s._v("default")]),s._v("属性，其他属性具有指定exports的名称及其对应的值。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_90-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_90-输出什么"}},[s._v("#")]),s._v(" 90. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Person")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("name")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" name\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" member "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Person")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"John"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" member"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"class"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"function"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('"object"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"string"')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-28"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-28"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("类是构造函数的语法糖，如果用构造函数的方式来重写"),a("code",[s._v("Person")]),s._v("类则将是：")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Person")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" name\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("p",[s._v("通过"),a("code",[s._v("new")]),s._v("来调用构造函数，将会生成构造函数"),a("code",[s._v("Person")]),s._v("的实例，对实例执行"),a("code",[s._v("typeof")]),s._v("关键字将返回"),a("code",[s._v('"object"')]),s._v("，上述情况打印出"),a("code",[s._v('"object"')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_91-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_91-输出什么"}},[s._v("#")]),s._v(" 91. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" newList "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("push")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("newList"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("push")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("5")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("[1, 2, 3, 4, 5]")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("[1, 2, 3, 5]")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("[1, 2, 3, 4]")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Error")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-10"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-10"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[a("code",[s._v(".push")]),s._v("方法返回数组的长度，而不是数组本身！ 通过将"),a("code",[s._v("newList")]),s._v("设置为"),a("code",[s._v("[1,2,3].push(4)")]),s._v("，实际上"),a("code",[s._v("newList")]),s._v("等于数组的新长度："),a("code",[s._v("4")]),s._v("。")]),s._v(" "),a("p",[s._v("然后，尝试在"),a("code",[s._v("newList")]),s._v("上使用"),a("code",[s._v(".push")]),s._v("方法。 由于"),a("code",[s._v("newList")]),s._v("是数值"),a("code",[s._v("4")]),s._v("，抛出TypeError。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_92-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_92-输出什么"}},[s._v("#")]),s._v(" 92. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("giveLydiaPizza")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Here is pizza!"')]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("giveLydiaChocolate")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Here\'s chocolate... now go hit the gym already."')]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("giveLydiaPizza"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("prototype"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("giveLydiaChocolate"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("prototype"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("{ constructor: ...}")]),s._v(" "),a("code",[s._v("{ constructor: ...}")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("{}")]),s._v(" "),a("code",[s._v("{ constructor: ...}")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("{ constructor: ...}")]),s._v(" "),a("code",[s._v("{}")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("{ constructor: ...}")]),s._v(" "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-11"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-11"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("常规函数，例如"),a("code",[s._v("giveLydiaPizza")]),s._v("函数，有一个"),a("code",[s._v("prototype")]),s._v("属性，它是一个带有"),a("code",[s._v("constructor")]),s._v("属性的对象（原型对象）。 然而，箭头函数，例如"),a("code",[s._v("giveLydiaChocolate")]),s._v("函数，没有这个"),a("code",[s._v("prototype")]),s._v("属性。 尝试使用"),a("code",[s._v("giveLydiaChocolate.prototype")]),s._v("访问"),a("code",[s._v("prototype")]),s._v("属性时会返回"),a("code",[s._v("undefined")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_93-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_93-输出什么"}},[s._v("#")]),s._v(" 93. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("of")]),s._v(" Object"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("entries")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("name")]),s._v(" "),a("code",[s._v("Lydia")]),s._v(" and "),a("code",[s._v("age")]),s._v(" "),a("code",[s._v("21")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('["name", "Lydia"]')]),s._v(" and "),a("code",[s._v('["age", 21]')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('["name", "age"]')]),s._v(" and "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Error")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-30"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-30"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[a("code",[s._v("Object.entries()")]),s._v("方法返回一个给定对象自身可枚举属性的键值对数组，上述情况返回一个二维数组，数组每个元素是一个包含键和值的数组：")]),s._v(" "),a("p",[a("code",[s._v("[['name'，'Lydia']，['age'，21]]")])]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("for-of")]),s._v("循环，我们可以迭代数组中的每个元素，上述情况是子数组。 我们可以使用"),a("code",[s._v("const [x，y]")]),s._v("在"),a("code",[s._v("for-of")]),s._v("循环中解构子数组。 "),a("code",[s._v("x")]),s._v("等于子数组中的第一个元素，"),a("code",[s._v("y")]),s._v("等于子数组中的第二个元素。")]),s._v(" "),a("p",[s._v("第一个子阵列是"),a("code",[s._v("[“name”，“Lydia”]")]),s._v("，其中"),a("code",[s._v("x")]),s._v("等于"),a("code",[s._v("name")]),s._v("，而"),a("code",[s._v("y")]),s._v("等于"),a("code",[s._v("Lydia")]),s._v("。\n第二个子阵列是"),a("code",[s._v("[“age”，21]")]),s._v("，其中"),a("code",[s._v("x")]),s._v("等于"),a("code",[s._v("age")]),s._v("，而"),a("code",[s._v("y")]),s._v("等于"),a("code",[s._v("21")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_94-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_94-输出什么"}},[s._v("#")]),s._v(" 94. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getItems")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("fruitList"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("args"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" favoriteFruit")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("fruitList"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("args"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" favoriteFruit"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getItems")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"banana"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"apple"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"pear"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"orange"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('["banana", "apple", "pear", "orange"]')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('[["banana", "apple"], "pear", "orange"]')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('["banana", "apple", ["pear"], "orange"]')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("SyntaxError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-12"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-12"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[a("code",[s._v("... args")]),s._v("是剩余参数，剩余参数的值是一个包含所有剩余参数的数组，"),a("strong",[s._v("并且只能作为最后一个参数")]),s._v("。上述示例中，剩余参数是第二个参数，这是不可能的，并会抛出语法错误。")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getItems")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("fruitList"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" favoriteFruit"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("args")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("fruitList"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("args"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" favoriteFruit"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getItems")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"banana"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"apple"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"pear"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"orange"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("p",[s._v("上述例子是有效的，将会返回数组："),a("code",[s._v("[ 'banana', 'apple', 'orange', 'pear' ]")])])]),a("p"),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_95-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_95-输出什么"}},[s._v("#")]),s._v(" "),a("a",{attrs:{name:"20190817"}}),s._v("95. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("nums")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("a"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" b")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("if")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("a "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" b"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'a is bigger'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("else")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'b is bigger'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v("\n  a "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" b\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("nums")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("nums")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("a is bigger")]),s._v(", "),a("code",[s._v("6")]),s._v(" and "),a("code",[s._v("b is bigger")]),s._v(", "),a("code",[s._v("3")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("a is bigger")]),s._v(", "),a("code",[s._v("undefined")]),s._v(" and "),a("code",[s._v("b is bigger")]),s._v(", "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("undefined")]),s._v(" and "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("SyntaxError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-25"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-25"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("在JavaScript中，我们不必显式地编写分号("),a("code",[s._v(";")]),s._v(")，但是JavaScript引擎仍然在语句之后自动添加分号。这称为"),a("strong",[s._v("自动分号插入")]),s._v("。例如，一个语句可以是变量，或者像"),a("code",[s._v("throw")]),s._v("、"),a("code",[s._v("return")]),s._v("、"),a("code",[s._v("break")]),s._v("这样的关键字。")]),s._v(" "),a("p",[s._v("在这里，我们在新的一行上写了一个"),a("code",[s._v("return")]),s._v("语句和另一个值"),a("code",[s._v("a + b")]),s._v("。然而，由于它是一个新行，引擎并不知道它实际上是我们想要返回的值。相反，它会在"),a("code",[s._v("return")]),s._v("后面自动添加分号。你可以这样看:")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n  a "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" b\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("这意味着永远不会到达"),a("code",[s._v("a + b")]),s._v("，因为函数在"),a("code",[s._v("return")]),s._v("关键字之后停止运行。如果没有返回值，就像这里，函数返回"),a("code",[s._v("undefined")]),s._v("。注意，在"),a("code",[s._v("if/else")]),s._v("语句之后没有自动插入!")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_96-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_96-输出什么"}},[s._v("#")]),s._v(" 96. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Person")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nPerson "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("AnotherPerson")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Sarah"')]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" member "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Person")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("member"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"Lydia"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"Sarah"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Error: cannot redeclare Person")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("SyntaxError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-26"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-26"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("我们可以将类设置为等于其他类/函数构造函数。 在这种情况下，我们将"),a("code",[s._v("Person")]),s._v("设置为"),a("code",[s._v("AnotherPerson")]),s._v("。 这个构造函数的名字是"),a("code",[s._v("Sarah")]),s._v("，所以新的"),a("code",[s._v("Person")]),s._v("实例"),a("code",[s._v("member")]),s._v("上的name属性是"),a("code",[s._v("Sarah")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_97-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_97-输出什么"}},[s._v("#")]),s._v(" 97. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" info "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("Symbol")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'a'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'b'")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("info"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("Object"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("keys")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("info"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("{Symbol('a'): 'b'}")]),s._v(" and "),a("code",[s._v("[\"{Symbol('a')\"]")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("{}")]),s._v(" and "),a("code",[s._v("[]")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('{ a: "b" }')]),s._v(" and "),a("code",[s._v('["a"]')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("{Symbol('a'): 'b'}")]),s._v(" and "),a("code",[s._v("[]")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-13"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-13"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[a("code",[s._v("Symbol")]),s._v("类型是不可枚举的。"),a("code",[s._v("Object.keys")]),s._v("方法返回对象上的所有可枚举的键属性。"),a("code",[s._v("Symbol")]),s._v("类型是不可见的，并返回一个空数组。 记录整个对象时，所有属性都是可见的，甚至是不可枚举的属性。")]),s._v(" "),a("p",[s._v("这是"),a("code",[s._v("Symbol")]),s._v("的众多特性之一：除了表示完全唯一的值（防止对象意外名称冲突，例如当使用2个想要向同一对象添加属性的库时），您还可以"),a("code",[s._v("隐藏")]),s._v("这种方式对象的属性（尽管不完全。你仍然可以使用"),a("code",[s._v("Object.getOwnPropertySymbols()")]),s._v("方法访问 "),a("code",[s._v("Symbol")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_98-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_98-输出什么"}},[s._v("#")]),s._v(" 98. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("getList")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("getUser")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("user")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" user"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" user"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("age "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" list "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" user "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getList")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("list"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getUser")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("user"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("[1, [2, 3, 4]]")]),s._v(" and "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("[1, [2, 3, 4]]")]),s._v(" and "),a("code",[s._v('{ name: "Lydia", age: 21 }')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("[1, 2, 3, 4]")]),s._v(" and "),a("code",[s._v('{ name: "Lydia", age: 21 }')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Error")]),s._v(" and "),a("code",[s._v('{ name: "Lydia", age: 21 }')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-31"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-31"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[a("code",[s._v("getList")]),s._v("函数接收一个数组作为其参数。 在"),a("code",[s._v("getList")]),s._v("函数的括号之间，我们立即解构这个数组。 您可以将其视为：")]),s._v(" "),a("p",[a("code",[s._v("[x, ...y] = [1, 2, 3, 4]")])]),s._v(" "),a("p",[s._v("使用剩余的参数"),a("code",[s._v("... y")]),s._v("，我们将所有剩余参数放在一个数组中。 在这种情况下，其余的参数是"),a("code",[s._v("2")]),s._v("，"),a("code",[s._v("3")]),s._v("和"),a("code",[s._v("4")]),s._v("。 "),a("code",[s._v("y")]),s._v("的值是一个数组，包含所有其余参数。 在这种情况下，"),a("code",[s._v("x")]),s._v("的值等于"),a("code",[s._v("1")]),s._v("，所以当我们打印"),a("code",[s._v("[x，y]")]),s._v("时，会打印"),a("code",[s._v("[1，[2,3,4]]")]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v("getUser")]),s._v("函数接收一个对象。对于箭头函数，如果只返回一个值，我们不必编写花括号。但是，如果您想从一个箭头函数返回一个对象，您必须在圆括号之间编写它，否则不会返回任何值!下面的函数将返回一个对象:")]),s._v(" "),a("p",[a("code",[s._v("const getUser = user => ({ name: user.name, age: user.age })")])]),s._v(" "),a("p",[s._v("由于在这种情况下不返回任何值，因此该函数返回"),a("code",[s._v("undefined")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_99-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_99-输出什么"}},[s._v("#")]),s._v(" 99. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("name")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("SyntaxError")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("ReferenceError")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("TypeError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-29"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-29"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("变量"),a("code",[s._v("name")]),s._v("保存字符串的值，该字符串不是函数，因此无法调用。")]),s._v(" "),a("p",[s._v("当值不是预期类型时，会抛出"),a("code",[s._v("TypeErrors")]),s._v("。 JavaScript期望"),a("code",[s._v("name")]),s._v("是一个函数，因为我们试图调用它。 但它是一个字符串，因此抛出"),a("code",[s._v("TypeError")]),s._v("："),a("code",[s._v("name is not a function")])]),s._v(" "),a("p",[s._v("当你编写了一些非有效的JavaScript时，会抛出语法错误，例如当你把"),a("code",[s._v("return")]),s._v("这个词写成"),a("code",[s._v("retrun")]),s._v("时。\n当JavaScript无法找到您尝试访问的值的引用时，抛出"),a("code",[s._v("ReferenceErrors")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_100-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_100-输出什么"}},[s._v("#")]),s._v(" 100. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 🎉✨ This is my 100th question! ✨🎉")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" output "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("&&")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Im'")]),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("possible!\nYou should")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("''")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("&&")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("n't")]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v(" see a therapist after so much JavaScript lol")]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("possible! You should see a therapist after so much JavaScript lol")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Impossible! You should see a therapist after so much JavaScript lol")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("possible! You shouldn't see a therapist after so much JavaScript lol")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Impossible! You shouldn't see a therapist after so much JavaScript lol")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-27"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-27"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[a("code",[s._v("[]")]),s._v("是一个真值。 使用"),a("code",[s._v("&&")]),s._v("运算符，如果左侧值是真值，则返回右侧值。 在这种情况下，左侧值"),a("code",[s._v("[]")]),s._v("是一个真值，所以返回"),a("code",[s._v("Im")]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v('""')]),s._v("是一个假值。 如果左侧值是假的，则不返回任何内容。 "),a("code",[s._v("n't")]),s._v("不会被退回。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h2",{attrs:{id:"question-101-120"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#question-101-120"}},[s._v("#")]),s._v(" question: 101-120")]),s._v(" "),a("h4",{attrs:{id:"_101-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_101-输出什么"}},[s._v("#")]),s._v(" 101.输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" one "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("false")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("||")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("||")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("null")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" two "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("null")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("||")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("false")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("||")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('""')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" three "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("||")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("||")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("one"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" two"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" three"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("null")]),s._v(" "),a("code",[s._v("[]")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("null")]),s._v(" "),a("code",[s._v('""')]),s._v(" "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("{}")]),s._v(" "),a("code",[s._v('""')]),s._v(" "),a("code",[s._v("[]")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("null")]),s._v(" "),a("code",[s._v("null")]),s._v(" "),a("code",[s._v("true")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-30"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-30"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("||")]),s._v("运算符，我们可以返回第一个真值。 如果所有值都是假值，则返回最后一个值。")]),s._v(" "),a("p",[a("code",[s._v("（false || {} || null）")]),s._v("：空对象"),a("code",[s._v("{}")]),s._v("是一个真值。 这是第一个（也是唯一的）真值，它将被返回。"),a("code",[s._v("one")]),s._v("等于"),a("code",[s._v("{}")]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v("（null || false ||“”）")]),s._v("：所有值都是假值。 这意味着返回传递的值"),a("code",[s._v('""')]),s._v("。 "),a("code",[s._v("two")]),s._v("等于"),a("code",[s._v('""')]),s._v("。")]),s._v(" "),a("p",[a("code",[s._v("（[] || 0 ||“”）")]),s._v("：空数组"),a("code",[s._v("[]")]),s._v("是一个真值。 这是第一个返回的真值。 "),a("code",[s._v("three")]),s._v("等于"),a("code",[s._v("[]")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_102-依次输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_102-依次输出什么"}},[s._v("#")]),s._v(" 102. 依次输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("myPromise")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" Promise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("resolve")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'I have resolved!'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("firstFunction")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("myPromise")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("then")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("res")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'second'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("async")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("secondFunction")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("await")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("myPromise")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'second'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("firstFunction")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("secondFunction")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("I have resolved!")]),s._v(", "),a("code",[s._v("second")]),s._v(" and "),a("code",[s._v("I have resolved!")]),s._v(", "),a("code",[s._v("second")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("second")]),s._v(", "),a("code",[s._v("I have resolved!")]),s._v(" and "),a("code",[s._v("second")]),s._v(", "),a("code",[s._v("I have resolved!")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("I have resolved!")]),s._v(", "),a("code",[s._v("second")]),s._v(" and "),a("code",[s._v("second")]),s._v(", "),a("code",[s._v("I have resolved!")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("second")]),s._v(", "),a("code",[s._v("I have resolved!")]),s._v(" and "),a("code",[s._v("I have resolved!")]),s._v(", "),a("code",[s._v("second")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-14"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-14"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("有了promise，我们通常会说：当我想要调用某个方法，但是由于它可能需要一段时间，因此暂时将它放在一边。只有当某个值被resolved/rejected，并且执行栈为空时才使用这个值。")]),s._v(" "),a("p",[s._v("我们可以在"),a("code",[s._v("async")]),s._v("函数中通过"),a("code",[s._v(".then")]),s._v("和"),a("code",[s._v("await")]),s._v("关键字获得该值。 尽管我们可以通过"),a("code",[s._v(".then")]),s._v("和"),a("code",[s._v("await")]),s._v("获得promise的价值，但是它们的工作方式有所不同。")]),s._v(" "),a("p",[s._v("在 "),a("code",[s._v("firstFunction")]),s._v("中，当运行到"),a("code",[s._v("myPromise")]),s._v("方法时我们将其放在一边，即promise进入微任务队列，其他后面的代码（"),a("code",[s._v("console.log('second')")]),s._v("）照常运行，因此"),a("code",[s._v("second")]),s._v("被打印出，"),a("code",[s._v("firstFunction")]),s._v("方法到此执行完毕，执行栈中宏任务队列被清空，此时开始执行微任务队列中的任务，"),a("code",[s._v("I have resolved")]),s._v("被打印出。")]),s._v(" "),a("p",[s._v("在"),a("code",[s._v("secondFunction")]),s._v("方法中，我们通过"),a("code",[s._v("await")]),s._v("关键字，暂停了后面代码的执行，直到异步函数的值被解析才开始后面代码的执行。这意味着，它会等着直到 "),a("code",[s._v("myPromise")]),s._v(" 以值"),a("code",[s._v("I have resolved")]),s._v("被解决之后，下一行"),a("code",[s._v("second")]),s._v("才开始执行。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_103-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_103-输出什么"}},[s._v("#")]),s._v(" 103. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" item "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("of")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("item "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("3")]),s._v(", "),a("code",[s._v("NaN")]),s._v(", "),a("code",[s._v("NaN")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("3")]),s._v(", "),a("code",[s._v("7")]),s._v(", "),a("code",[s._v("NaN")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("3")]),s._v(", "),a("code",[s._v("Lydia2")]),s._v(", "),a("code",[s._v("[Object object]2")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('"12"')]),s._v(", "),a("code",[s._v("Lydia2")]),s._v(", "),a("code",[s._v("[Object object]2")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-31"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-31"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("“+”运算符不仅用于添加数值，还可以使用它来连接字符串。 每当JavaScript引擎发现一个或多个值不是数字时，就会将数字强制为字符串。")]),s._v(" "),a("p",[s._v("第一个是数字1。 1 + 2返回数字3。")]),s._v(" "),a("p",[s._v("但是，第二个是字符串“Lydia”。 “Lydia”是一个字符串，2是一个数字：2被强制转换为字符串。 “Lydia”和“2”被连接起来，产生字符串“Lydia2”。")]),s._v(" "),a("p",[a("code",[s._v("{name：“ Lydia”}")]),s._v("是一个对象。 数字和对象都不是字符串，因此将二者都字符串化。 每当我们对常规对象进行字符串化时，它就会变成"),a("code",[s._v("[Object object]")]),s._v("。 与“2”串联的“ [Object object]”成为“[Object object]2”。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_104-结果是什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_104-结果是什么"}},[s._v("#")]),s._v(" 104. 结果是什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("Promise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("resolve")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("5")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("5")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Promise {<pending>: 5}")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Promise {<resolved>: 5}")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Error")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-32"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-32"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("我们可以将我们想要的任何类型的值传递"),a("code",[s._v("Promise.resolve")]),s._v("，无论是否"),a("code",[s._v("promise")]),s._v("。 该方法本身返回带有已解析值的"),a("code",[s._v("Promise")]),s._v("。 如果您传递常规函数，它将是具有常规值的已解决"),a("code",[s._v("promise")]),s._v("。 如果你通过了promise，它将是一个已经resolved的且带有传的值的promise。")]),s._v(" "),a("p",[s._v("上述情况，我们传了数字5，因此返回一个resolved状态的promise，resolve值为"),a("code",[s._v("5")])]),s._v(" "),a("p")]),s._v(" "),a("h4",{attrs:{id:"_105-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_105-输出什么"}},[s._v("#")]),s._v(" 105. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("compareMembers")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("person1"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" person2 "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" person")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("if")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person1 "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!==")]),s._v(" person2"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Not the same!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("else")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"They are the same!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("compareMembers")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("Not the same!")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("They are the same!")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("ReferenceError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("SyntaxError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-28"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-28"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("对象通过引用传递。 当我们检查对象的严格相等性（===）时，我们正在比较它们的引用。")]),s._v(" "),a("p",[s._v("我们将“person2”的默认值设置为“person”对象，并将“person”对象作为“person1”的值传递。")]),s._v(" "),a("p",[s._v("这意味着两个值都引用内存中的同一位置，因此它们是相等的。")]),s._v(" "),a("p",[s._v("运行“ else”语句中的代码块，并记录"),a("code",[s._v("They are the same!")]),s._v(" 。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_106-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_106-输出什么"}},[s._v("#")]),s._v(" 106. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" colorConfig "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  red"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  blue"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("false")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  green"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  black"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("true")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  yellow"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token boolean"}},[s._v("false")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" colors "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"pink"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"red"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"blue"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("colorConfig"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("colors"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("TypeError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-15"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-15"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("在JavaScript中，我们有两种访问对象属性的方法：括号表示法或点表示法。 在此示例中，我们使用点表示法（"),a("code",[s._v("colorConfig.colors")]),s._v("）代替括号表示法（"),a("code",[s._v("colorConfig [“ colors”]")]),s._v("）。")]),s._v(" "),a("p",[s._v("使用点表示法，JavaScript会尝试使用该确切名称在对象上查找属性。 在此示例中，JavaScript尝试在colorconfig对象上找到名为colors的属性。 没有名为“colors”的属性，因此返回“undefined”。\n然后，我们尝试使用"),a("code",[s._v("[1]")]),s._v("访问第一个元素的值。 我们无法对未定义的值执行此操作，因此会抛出"),a("code",[s._v("Cannot read property '1' of undefined")]),s._v("。")]),s._v(" "),a("p",[s._v("JavaScript解释（或取消装箱）语句。 当我们使用方括号表示法时，它会看到第一个左方括号"),a("code",[s._v("[")]),s._v("并一直进行下去，直到找到右方括号"),a("code",[s._v("]")]),s._v("。 只有这样，它才会评估该语句。 如果我们使用了colorConfig [colors [1]]，它将返回colorConfig对象上red属性的值。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_107-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_107-输出什么"}},[s._v("#")]),s._v(" 107. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'❤️'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'❤️'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("false")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-32"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-32"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("在内部，表情符号是unicode。 heat表情符号的unicode是"),a("code",[s._v("“ U + 2764 U + FE0F”")]),s._v("。 对于相同的表情符号，它们总是相同的，因此我们将两个相等的字符串相互比较，这将返回true。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_108-哪些方法修改了原数组"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_108-哪些方法修改了原数组"}},[s._v("#")]),s._v(" 108. 哪些方法修改了原数组?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" emojis "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'✨'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'🥑'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'😍'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n\nemojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("map")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'✨'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nemojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("filter")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!==")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'🥑'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nemojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("find")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!==")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'🥑'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nemojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("reduce")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("acc"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" cur")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" acc "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'✨'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nemojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("slice")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'✨'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nemojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("splice")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'✨'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("All of them")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("map")]),s._v(" "),a("code",[s._v("reduce")]),s._v(" "),a("code",[s._v("slice")]),s._v(" "),a("code",[s._v("splice")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("map")]),s._v(" "),a("code",[s._v("slice")]),s._v(" "),a("code",[s._v("splice")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("splice")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-16"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-16"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("splice")]),s._v("方法，我们通过删除，替换或添加元素来修改原始数组。 在这种情况下，我们从索引1中删除了2个元素（我们删除了"),a("code",[s._v("'🥑'")]),s._v("和"),a("code",[s._v("'😍'")]),s._v("），同时添加了✨emoji表情。")]),s._v(" "),a("p",[a("code",[s._v("map")]),s._v("，"),a("code",[s._v("filter")]),s._v("和"),a("code",[s._v("slice")]),s._v("返回一个新数组，"),a("code",[s._v("find")]),s._v("返回一个元素，而"),a("code",[s._v("reduce")]),s._v("返回一个减小的值。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_109-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_109-输出什么"}},[s._v("#")]),s._v(" "),a("a",{attrs:{name:"20191009"}}),s._v("109. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" food "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'🍕'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'🍫'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'🥑'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'🍔'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" info "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" favoriteFood"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" food"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\ninfo"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("favoriteFood "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'🍝'")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("food"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("['🍕', '🍫', '🥑', '🍔']")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("['🍝', '🍫', '🥑', '🍔']")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("['🍝', '🍕', '🍫', '🥑', '🍔']")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-33"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-33"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("我们将"),a("code",[s._v("info")]),s._v("对象上的"),a("code",[s._v("favoriteFood")]),s._v("属性的值设置为披萨表情符号“🍕”的字符串。字符串是原始数据类型。在JavaScript中，原始数据类型通过值起作用")]),s._v(" "),a("p",[s._v("在这种情况下，我们将"),a("code",[s._v("info")]),s._v("对象上的"),a("code",[s._v("favoriteFood")]),s._v("属性的值设置为等于"),a("code",[s._v("food")]),s._v("数组中的第一个元素的值，字符串为披萨表情符号（"),a("code",[s._v("'🍕'")]),s._v(" ）。字符串是原始数据类型，并且通过值进行交互，我们更改"),a("code",[s._v("info")]),s._v("对象上"),a("code",[s._v("favoriteFood")]),s._v("属性的值。 food数组没有改变，因为favoriteFood的值只是该数组中第一个元素的值的复制，并且与该元素上的元素没有相同的内存引用食物"),a("code",[s._v("[0]")]),s._v("。当我们记录食物时，它仍然是原始数组"),a("code",[s._v("['🍕'，'🍫'，'🥑'，'🍔']")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_110-这个函数干了什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_110-这个函数干了什么"}},[s._v("#")]),s._v(" 110. 这个函数干了什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token constant"}},[s._v("JSON")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("parse")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: Parses JSON to a JavaScript value")]),s._v(" "),a("li",[s._v("B: Parses a JavaScript object to JSON")]),s._v(" "),a("li",[s._v("C: Parses any JavaScript value to JSON")]),s._v(" "),a("li",[s._v("D: Parses JSON to a JavaScript object only")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-34"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-34"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("使用"),a("code",[s._v("JSON.parse()")]),s._v("方法，我们可以将JSON字符串解析为JavaScript值。")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 将数字字符串化为有效的JSON，然后将JSON字符串解析为JavaScript值:")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" jsonNumber "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token constant"}},[s._v("JSON")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("stringify")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// '4'")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token constant"}},[s._v("JSON")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("parse")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("jsonNumber"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 4")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 将数组值字符串化为有效的JSON，然后将JSON字符串解析为JavaScript值:")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" jsonArray "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token constant"}},[s._v("JSON")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("stringify")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// '[1, 2, 3]'")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token constant"}},[s._v("JSON")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("parse")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("jsonArray"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// [1, 2, 3]")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 将对象字符串化为有效的JSON，然后将JSON字符串解析为JavaScript值:")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" jsonArray "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token constant"}},[s._v("JSON")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("stringify")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v('// \'{"name":"Lydia"}\'')]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token constant"}},[s._v("JSON")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("parse")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("jsonArray"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// { name: 'Lydia' }")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_111-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_111-输出什么"}},[s._v("#")]),s._v(" 111. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Lydia'")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getName")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Sarah'")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getName")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: Lydia")]),s._v(" "),a("li",[s._v("B: Sarah")]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-17"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-17"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("每个函数都有其自己的执行上下文。 "),a("code",[s._v("getName")]),s._v("函数首先在其自身的上下文（范围）内查找，以查看其是否包含我们尝试访问的变量"),a("code",[s._v("name")]),s._v("。 上述情况，"),a("code",[s._v("getName")]),s._v("函数包含其自己的"),a("code",[s._v("name")]),s._v("变量：我们用"),a("code",[s._v("let")]),s._v("关键字和"),a("code",[s._v("Sarah")]),s._v("的值声明变量"),a("code",[s._v("name")]),s._v("。")]),s._v(" "),a("p",[s._v("带有"),a("code",[s._v("let")]),s._v("关键字（和"),a("code",[s._v("const")]),s._v("）的变量被提升，但是与"),a("code",[s._v("var")]),s._v("不同，它不会被***初始化***。 在我们声明（初始化）它们之前，无法访问它们。 这称为“暂时性死区”。 当我们尝试在声明变量之前访问变量时，JavaScript会抛出"),a("code",[s._v("ReferenceError: Cannot access 'name' before initialization")]),s._v("。")]),s._v(" "),a("p",[s._v("如果我们不在"),a("code",[s._v("getName")]),s._v("函数中声明"),a("code",[s._v("name")]),s._v("变量，则javascript引擎会查看原型练。会找到其外部作用域有一个名为"),a("code",[s._v("name")]),s._v("的变量，其值为"),a("code",[s._v("Lydia")]),s._v("。 在这种情况下，它将打印"),a("code",[s._v("Lydia")]),s._v("：")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Lydia'")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getName")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getName")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// Lydia")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_112-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_112-输出什么？"}},[s._v("#")]),s._v(" 112. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("generatorOne")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("yield")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'a'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'b'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'c'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("generatorTwo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("yield")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'a'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'b'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'c'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" one "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("generatorOne")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" two "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("generatorTwo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("one"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("two"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("a")]),s._v(" and "),a("code",[s._v("a")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("a")]),s._v(" and "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("['a', 'b', 'c']")]),s._v(" and "),a("code",[s._v("a")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("a")]),s._v(" and "),a("code",[s._v("['a', 'b', 'c']")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-33"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-33"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("通过 "),a("code",[s._v("yield")]),s._v(" 关键字, 我们在 "),a("code",[s._v("Generator")]),s._v(" 函数里执行"),a("code",[s._v("yield")]),s._v("表达式. 通过 "),a("code",[s._v("yield*")]),s._v(" 关键字, 我们可以在一个"),a("code",[s._v("Generator")]),s._v(" 函数里面执行（"),a("code",[s._v("yield")]),s._v("表达式）另一个 "),a("code",[s._v("Generator")]),s._v(" 函数, 或可遍历的对象 (如数组).")]),s._v(" "),a("p",[s._v("在函数 "),a("code",[s._v("generatorOne")]),s._v(" 中, 我们通过 "),a("code",[s._v("yield")]),s._v(" 关键字 yield 了一个完整的数组 "),a("code",[s._v("['a', 'b', 'c']")]),s._v("。函数"),a("code",[s._v("one")]),s._v("通过"),a("code",[s._v("next")]),s._v("方法返回的对象的"),a("code",[s._v("value")]),s._v(" 属性的值 ("),a("code",[s._v("one.next().value")]),s._v(") 等价于数组 "),a("code",[s._v("['a', 'b', 'c']")]),s._v(".")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("one"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// ['a', 'b', 'c']")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("one"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// undefined")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("在函数 "),a("code",[s._v("generatorTwo")]),s._v(" 中, 我们使用 "),a("code",[s._v("yield*")]),s._v(" 关键字。就相当于函数"),a("code",[s._v("two")]),s._v("第一个"),a("code",[s._v("yield")]),s._v("的值, 等价于在迭代器中第一个 "),a("code",[s._v("yield")]),s._v(" 的值。数组"),a("code",[s._v("['a', 'b', 'c']")]),s._v("就是这个迭代器. 第一个 "),a("code",[s._v("yield")]),s._v(" 的值就是 "),a("code",[s._v("a")]),s._v(", 所以我们第一次调用 "),a("code",[s._v("two.next().value")]),s._v("时, 就返回"),a("code",[s._v("a")]),s._v("。")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("two"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 'a'")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("two"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 'b'")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("two"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// 'c'")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("two"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// undefined")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_113-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_113-输出什么？"}},[s._v("#")]),s._v(" 113. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[s._v("console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'I love'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v(" to program")]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("I love to program")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("undefined to program")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("${(x => x)('I love') to program")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("TypeError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-35"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-35"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("带有模板字面量的表达式首先被执行。相当于字符串会包含表达式，这个立即执行函数 "),a("code",[s._v("(x => x)('I love')")]),s._v(" 返回的值. 我们向箭头函数 "),a("code",[s._v("x => x")]),s._v(" 传递 "),a("code",[s._v("'I love'")]),s._v(" 作为参数。"),a("code",[s._v("x")]),s._v(" 等价于返回的 "),a("code",[s._v("'I love'")]),s._v("。这就是结果 "),a("code",[s._v("I love to program")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_114-将会发生什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_114-将会发生什么"}},[s._v("#")]),s._v(" 114. 将会发生什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  alert"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setInterval")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Alert!'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1000")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nconfig "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("null")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("setInterval")]),s._v(" 的回调不会被调用")]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("setInterval")]),s._v(" 的回调被调用一次")]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("setInterval")]),s._v(" 的回调仍然会被每秒钟调用")]),s._v(" "),a("li",[s._v("D: 我们从没调用过 "),a("code",[s._v("config.alert()")]),s._v(", config 为 "),a("code",[s._v("null")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-34"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-34"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("一般情况下当我们将对象赋值为 "),a("code",[s._v("null")]),s._v(", 那些对象会被进行 "),a("em",[s._v("垃圾回收（garbage collected）")]),s._v(" 因为已经没有对这些对象的引用了。然而，"),a("code",[s._v("setInterval")]),s._v("的参数是一个箭头函数（所以上下文绑定到对象 "),a("code",[s._v("config")]),s._v(" 了），回调函数仍然保留着对 "),a("code",[s._v("config")]),s._v("的引用。只要存在引用，对象就不会被垃圾回收。因为没有被垃圾回收，"),a("code",[s._v("setInterval")]),s._v(" 的回调每1000ms (1s)会被调用一次。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_115-哪一个方法会返回-hello-world-？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_115-哪一个方法会返回-hello-world-？"}},[s._v("#")]),s._v(" 115. 哪一个方法会返回 "),a("code",[s._v("'Hello world!'")]),s._v(" ？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" myMap "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Map")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("myFunc")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'greeting'")]),s._v("\n\nmyMap"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("set")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("myFunc"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'Hello world!'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("//1")]),s._v("\nmyMap"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("get")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'greeting'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("//2")]),s._v("\nmyMap"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("get")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("myFunc"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("//3")]),s._v("\nmyMap"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("get")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'greeting'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("ul",[a("li",[s._v("A: 1")]),s._v(" "),a("li",[s._v("B: 2")]),s._v(" "),a("li",[s._v("C: 2 and 3")]),s._v(" "),a("li",[s._v("D: All of them")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-29"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-29"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("当通过 "),a("code",[s._v("set")]),s._v(" 方法添加一个键值对，一个传递给 "),a("code",[s._v("set")]),s._v("方法的参数将会是键名，第二个参数将会是值。在这个case里，键名为 "),a("em",[s._v("函数")]),s._v(" "),a("code",[s._v("() => 'greeting'")]),s._v("，值为"),a("code",[s._v("'Hello world'")]),s._v("。 "),a("code",[s._v("myMap")]),s._v(" 现在就是 "),a("code",[s._v("{ () => 'greeting' => 'Hello world!' }")]),s._v("。")]),s._v(" "),a("p",[s._v("1 是错的，因为键名不是 "),a("code",[s._v("'greeting'")]),s._v(" 而是 "),a("code",[s._v("() => 'greeting'")]),s._v("。\n3 是错的，因为我们给"),a("code",[s._v("get")]),s._v(" 方法传递了一个新的函数。对象受 "),a("em",[s._v("引用")]),s._v(" 影响。函数也是对象，因此两个函数严格上并不等价，尽管他们相同：他们有两个不同的内存引用地址。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_116-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_116-输出什么？"}},[s._v("#")]),s._v(" 116. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("changeAge")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("person "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("age "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("changeAgeAndName")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("person "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("age "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),s._v("\n  x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Sarah"')]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("changeAge")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("changeAgeAndName")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('{name: "Sarah", age: 22}')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('{name: "Sarah", age: 23}')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('{name: "Lydia", age: 22}')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('{name: "Lydia", age: 23}')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-35"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-35"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("函数 "),a("code",[s._v("changeAge")]),s._v(" 和函数 "),a("code",[s._v("changeAgeAndName")]),s._v(" 有着不同的参数，定义一个 "),a("em",[s._v("新")]),s._v(" 生成的对象 "),a("code",[s._v("{ ...person }")]),s._v("。这个对象有着所有 "),a("code",[s._v("person")]),s._v(" 对象 中 k/v 值的副本。")]),s._v(" "),a("p",[s._v("首项, 我们调用 "),a("code",[s._v("changeAge")]),s._v(" 函数并传递 "),a("code",[s._v("person")]),s._v(" 对象作为它的参数。这个函数对 "),a("code",[s._v("age")]),s._v(" 属性进行加一操作。"),a("code",[s._v("person")]),s._v(" 现在是 "),a("code",[s._v('{ name: "Lydia", age: 22 }')]),s._v("。")]),s._v(" "),a("p",[s._v("然后，我们调用函数 "),a("code",[s._v("changeAgeAndName")]),s._v(" ，然而我们没有传递参数。取而代之，"),a("code",[s._v("x")]),s._v(" 的值等价 "),a("em",[s._v("new")]),s._v(" 生成的对象: "),a("code",[s._v("{ ...person }")]),s._v("。因为它是一个新生成的对象，它并不会对对象 "),a("code",[s._v("person")]),s._v(" 造成任何副作用。"),a("code",[s._v("person")]),s._v(" 仍然等价于 "),a("code",[s._v('{ name: "Lydia", age: 22 }')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_117-下面那个选项将会返回-6"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_117-下面那个选项将会返回-6"}},[s._v("#")]),s._v(" 117. 下面那个选项将会返回 "),a("code",[s._v("6")]),s._v("?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sumValues")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" z")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" y "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" z"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("sumValues([...1, 2, 3])")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("sumValues([...[1, 2, 3]])")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("sumValues(...[1, 2, 3])")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("sumValues([1, 2, 3])")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-36"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-36"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("通过展开操作符 "),a("code",[s._v("...")]),s._v("，我们可以 "),a("em",[s._v("暂开")]),s._v(" 单个可迭代的元素。函数 "),a("code",[s._v("sumValues")]),s._v(" function 接收三个参数： "),a("code",[s._v("x")]),s._v(", "),a("code",[s._v("y")]),s._v(" 和 "),a("code",[s._v("z")]),s._v("。"),a("code",[s._v("...[1, 2, 3]")]),s._v(" 的执行结果为 "),a("code",[s._v("1, 2, 3")]),s._v("，将会传递给函数 "),a("code",[s._v("sumValues")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_118-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_118-输出什么？"}},[s._v("#")]),s._v(" 118. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" num "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" list "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🥳"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🤠"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🥰"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🤪"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("list"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("num "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("🤠")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("🥰")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("SyntaxError")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-30"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-30"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("通过 "),a("code",[s._v("+=")]),s._v(" 操作符，我们对值 "),a("code",[s._v("num")]),s._v(" 进行加 "),a("code",[s._v("1")]),s._v(" 操作。 "),a("code",[s._v("num")]),s._v(" 有初始值 "),a("code",[s._v("1")]),s._v("，因此 "),a("code",[s._v("1 + 1")]),s._v(" 的执行结果为 "),a("code",[s._v("2")]),s._v("。数组 "),a("code",[s._v("list")]),s._v(" 的第二项为 🥰，"),a("code",[s._v("console.log(list[2])")]),s._v(" 输出 🥰.")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_119-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_119-输出什么？"}},[s._v("#")]),s._v(" 119. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tfirstName"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n\tlastName"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Hallie"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n\tpet"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\tname"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Mara"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n\t\tbreed"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Dutch Tulip Hound"')]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getFullName")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("firstName"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v(" ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("lastName"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("pet"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("?.")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("pet"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("?.")]),s._v("family"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("?.")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("getFullName"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("?.")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("member"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("getLastName"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("?.")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br"),a("span",{staticClass:"line-number"},[s._v("16")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Mara")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("Lydia Hallie")]),s._v(" "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Mara")]),s._v(" "),a("code",[s._v("null")]),s._v(" "),a("code",[s._v("Lydia Hallie")]),s._v(" "),a("code",[s._v("null")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("null")]),s._v(" "),a("code",[s._v("ReferenceError")]),s._v(" "),a("code",[s._v("null")]),s._v(" "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-31"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-31"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("通过 ES10 或 TS3.7+"),a("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/%E5%8F%AF%E9%80%89%E9%93%BE",target:"_blank",rel:"noopener noreferrer"}},[s._v("可选链操作符 "),a("code",[s._v("?.")]),a("OutboundLink")],1),s._v("，我们不再需要显式检测更深层的嵌套值是否有效。如果我们尝试获取 "),a("code",[s._v("undefined")]),s._v(" 或 "),a("code",[s._v("null")]),s._v(" 的值 ("),a("em",[s._v("nullish")]),s._v(")，表达将会短路并返回 "),a("code",[s._v("undefined")]),s._v(".")]),s._v(" "),a("p",[a("code",[s._v("person.pet?.name")]),s._v("： "),a("code",[s._v("person")]),s._v(" 有一个名为 "),a("code",[s._v("pet")]),s._v(" 的属性： "),a("code",[s._v("person.pet")]),s._v(" 不是 nullish。它有个名为 "),a("code",[s._v("name")]),s._v(" 的属性，并返回字符串 "),a("code",[s._v("Mara")]),s._v("。\n"),a("code",[s._v("person.pet?.family?.name")]),s._v("： "),a("code",[s._v("person")]),s._v(" 有一个名为 "),a("code",[s._v("pet")]),s._v(" 的属性： "),a("code",[s._v("person.pet")]),s._v(" 不是 nullish. "),a("code",[s._v("pet")]),s._v(" "),a("em",[s._v("并没有")]),s._v(" 一个名为 "),a("code",[s._v("family")]),s._v(" 的属性, "),a("code",[s._v("person.pet.family")]),s._v(" 是 nullish。表达式返回 "),a("code",[s._v("undefined")]),s._v("。\n"),a("code",[s._v("person.getFullName?.()")]),s._v("： "),a("code",[s._v("person")]),s._v(" 有一个名为 "),a("code",[s._v("getFullName")]),s._v(" 的属性： "),a("code",[s._v("person.getFullName()")]),s._v(" 不是 nullish 并可以被调用，返回字符串 "),a("code",[s._v("Lydia Hallie")]),s._v("。\n"),a("code",[s._v("member.getLastName?.()")]),s._v(": "),a("code",[s._v("member")]),s._v(" is not defined: "),a("code",[s._v("member.getLastName()")]),s._v(" is nullish. The expression returns "),a("code",[s._v("undefined")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_120-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_120-输出什么？"}},[s._v("#")]),s._v(" 120. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" groceries "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"banana"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"apple"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"peanuts"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("if")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("groceries"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("indexOf")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"banana"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"We have to buy bananas!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("else")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("We don't have to buy bananas!")]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: We have to buy bananas!")]),s._v(" "),a("li",[s._v("B: We don't have to buy bananas")]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("1")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-32"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-32"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("我们传递了一个状态 "),a("code",[s._v('groceries.indexOf("banana")')]),s._v(" 给if条件语句。"),a("code",[s._v('groceries.indexOf("banana")')]),s._v(" 返回 "),a("code",[s._v("0")]),s._v("， 一个 falsy 的值。因为if条件语句的状态为 falsy，"),a("code",[s._v("else")]),s._v(" 块区内的代码执行，并且 "),a("code",[s._v("We don't have to buy bananas!")]),s._v(" 被输出.")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h2",{attrs:{id:"question-121-144"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#question-121-144"}},[s._v("#")]),s._v(" question: 121-144")]),s._v(" "),a("h4",{attrs:{id:"_121-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_121-输出什么"}},[s._v("#")]),s._v(" 121. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tlanguages"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("set")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("language")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("lang")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("languages"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("push")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("lang"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("config"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("language"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("function language(lang) { this.languages.push(lang }")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("0")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("[]")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-18"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-18"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("方法 "),a("code",[s._v("language")]),s._v(" 是一个 "),a("code",[s._v("setter")]),s._v("。Setters 并不保存一个实际值，它们的使命在于 "),a("em",[s._v("修改")]),s._v(" 属性。当调用方法 "),a("code",[s._v("setter")]),s._v("， 返回 "),a("code",[s._v("undefined")]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_122-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_122-输出什么？"}},[s._v("#")]),s._v(" 122. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia Hallie"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"object"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("===")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"string"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("true")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-37"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-37"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[a("code",[s._v("typeof name")]),s._v(" 返回 "),a("code",[s._v('"string"')]),s._v("。字符串 "),a("code",[s._v('"string"')]),s._v(" 是一个 truthy 的值，因此 "),a("code",[s._v("!typeof name")]),s._v(" 返回一个布尔值 "),a("code",[s._v("false")]),s._v("。 "),a("code",[s._v('false === "object"')]),s._v(" 和 "),a("code",[s._v('false === "string"')]),s._v(" 都返回 "),a("code",[s._v("false")]),s._v("。")]),s._v(" "),a("p",[s._v("（如果我们想检测一个值的类型，我们应该用 "),a("code",[s._v("!==")]),s._v(" 而不是 "),a("code",[s._v("!typeof")]),s._v("）")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_123-输出什么"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_123-输出什么"}},[s._v("#")]),s._v(" 123. 输出什么?")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("add")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("y")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("z")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" z"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" y "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" z"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("4")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("5")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("6")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("4")]),s._v(" "),a("code",[s._v("5")]),s._v(" "),a("code",[s._v("6")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("6")]),s._v(" "),a("code",[s._v("5")]),s._v(" "),a("code",[s._v("4")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("4")]),s._v(" "),a("code",[s._v("function")]),s._v(" "),a("code",[s._v("function")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("6")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-36"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-36"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("函数 "),a("code",[s._v("add")]),s._v(" 是一个返回 返回箭头函数的箭头函数 的箭头函数（still with me?）。第一个函数接收一个值为 "),a("code",[s._v("4")]),s._v(" 的参数 "),a("code",[s._v("x")]),s._v("。我们调用第二个函数，它接收一个值为 "),a("code",[s._v("5")]),s._v(" 的参数 "),a("code",[s._v("y")]),s._v("。然后我们调用第三个函数，它接收一个值为 "),a("code",[s._v("6")]),s._v(" 的参数 "),a("code",[s._v("z")]),s._v("。当我们尝试在最后一个箭头函数中获取 "),a("code",[s._v("x")]),s._v(", "),a("code",[s._v("y")]),s._v(" 和 "),a("code",[s._v("z")]),s._v(" 的值，JS 引擎根据作用域链去找 "),a("code",[s._v("x")]),s._v(" 和 "),a("code",[s._v("y")]),s._v(" 的值。得到 "),a("code",[s._v("4")]),s._v(" "),a("code",[s._v("5")]),s._v(" "),a("code",[s._v("6")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_124-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_124-输出什么？"}},[s._v("#")]),s._v(" 124. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("async")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("range")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("start"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" end")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" start"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<=")]),s._v(" end"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("yield")]),s._v(" Promise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("resolve")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("async")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" gen "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("range")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("await")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" item "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("of")]),s._v(" gen"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("item"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("Promise {1}")]),s._v(" "),a("code",[s._v("Promise {2}")]),s._v(" "),a("code",[s._v("Promise {3}")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Promise {<pending>}")]),s._v(" "),a("code",[s._v("Promise {<pending>}")]),s._v(" "),a("code",[s._v("Promise {<pending>}")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("3")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-38"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-38"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("我们给 函数range 传递： "),a("code",[s._v("Promise{1}")]),s._v(", "),a("code",[s._v("Promise{2}")]),s._v(", "),a("code",[s._v("Promise{3}")]),s._v("，Generator 函数 "),a("code",[s._v("range")]),s._v(" 返回一个全是 async object promise 数组。我们将 async object 赋值给变量 "),a("code",[s._v("gen")]),s._v("，之后我们使用"),a("code",[s._v("for await ... of")]),s._v(" 进行循环遍历。我们将返回的 Promise 实例赋值给 "),a("code",[s._v("item")]),s._v("： 第一个返回 "),a("code",[s._v("Promise{1}")]),s._v("， 第二个返回 "),a("code",[s._v("Promise{2}")]),s._v("，之后是 "),a("code",[s._v("Promise{3}")]),s._v("。因为我们正 "),a("em",[s._v("awaiting")]),s._v(" "),a("code",[s._v("item")]),s._v(" 的值，resolved 状态的 promsie，promise数组的resolved "),a("em",[s._v("值")]),s._v(" 以此为： "),a("code",[s._v("1")]),s._v("，"),a("code",[s._v("2")]),s._v("，"),a("code",[s._v("3")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_125-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_125-输出什么？"}},[s._v("#")]),s._v(" 125. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("myFunc")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" z "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" y"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" z"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("myFunc")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("1")]),s._v(" "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("3")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("{1: 1}")]),s._v(" "),a("code",[s._v("{2: 2}")]),s._v(" "),a("code",[s._v("{3: 3}")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("{ 1: undefined }")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")]),s._v(" "),a("code",[s._v("undefined")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-19"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-19"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[a("code",[s._v("myFunc")]),s._v(" 期望接收一个包含 "),a("code",[s._v("x")]),s._v(", "),a("code",[s._v("y")]),s._v(" 和 "),a("code",[s._v("z")]),s._v(" 属性的对象作为它的参数。因为我们仅仅传递三个单独的数字值 (1, 2, 3) 而不是一个含有 "),a("code",[s._v("x")]),s._v(", "),a("code",[s._v("y")]),s._v(" 和 "),a("code",[s._v("z")]),s._v(" 属性的对象 ({x: 1, y: 2, z: 3})， "),a("code",[s._v("x")]),s._v(", "),a("code",[s._v("y")]),s._v(" 和 "),a("code",[s._v("z")]),s._v(" 有着各自的默认值 "),a("code",[s._v("undefined")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_126-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_126-输出什么？"}},[s._v("#")]),s._v(" 126. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getFine")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("speed"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" amount")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" formattedSpeed "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Intl"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("NumberFormat")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'en-US'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" style"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'unit'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" unit"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'mile-per-hour'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("format")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("speed"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" formattedAmount "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Intl"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("NumberFormat")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'en-US'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" style"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'currency'")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" currency"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'USD'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("format")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("amount"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("The driver drove ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),s._v("formattedSpeed"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v(" and has to pay ")]),a("span",{pre:!0,attrs:{class:"token interpolation"}},[a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("${")]),s._v("formattedAmount"),a("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[s._v("}")])]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getFine")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("130")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("300")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br")])]),a("ul",[a("li",[s._v("A: The driver drove 130 and has to pay 300")]),s._v(" "),a("li",[s._v("B: The driver drove 130 mph and has to pay $300.00")]),s._v(" "),a("li",[s._v("C: The driver drove undefined and has to pay undefined")]),s._v(" "),a("li",[s._v("D: The driver drove 130.00 and has to pay 300.00")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-33"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-33"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("通过方法 "),a("code",[s._v("Intl.NumberFormat")]),s._v("，我们可以格式化任意区域的数字值。我们对数字值 "),a("code",[s._v("130")]),s._v(" 进行 "),a("code",[s._v("mile-per-hour")]),s._v(" 作为 "),a("code",[s._v("unit")]),s._v(" 的 "),a("code",[s._v("en-US")]),s._v(" 区域 格式化，结果为 "),a("code",[s._v("130 mph")]),s._v("。对数字值 "),a("code",[s._v("300")]),s._v(" 进行 "),a("code",[s._v("USD")]),s._v(" 作为 "),a("code",[s._v("currentcy")]),s._v(" 的 "),a("code",[s._v("en-US")]),s._v(" 区域格式化，结果为 "),a("code",[s._v("$300.00")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_127-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_127-输出什么？"}},[s._v("#")]),s._v(" 127. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" spookyItems "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"👻"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🎃"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🕸"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" item"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" spookyItems"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" item"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"💀"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("spookyItems"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('["👻", "🎃", "🕸"]')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('["👻", "🎃", "🕸", "💀"]')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('["👻", "🎃", "🕸", { item: "💀" }]')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('["👻", "🎃", "🕸", "[object Object]"]')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-34"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-34"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v('通过解构对象们，我们可以从右手边的对象中拆出值，并且将拆出的值分配给左手边对象同名的属性。在这种情况下，我们将值 "💀" 分配给 '),a("code",[s._v("spookyItems[3]")]),s._v("。相当于我们正在篡改数组 "),a("code",[s._v("spookyItems")]),s._v('，我们给它添加了值 "💀"。当输出 '),a("code",[s._v("spookyItems")]),s._v(" 时，结果为 "),a("code",[s._v('["👻", "🎃", "🕸", "💀"]')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_128-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_128-输出什么？"}},[s._v("#")]),s._v(" 128. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia Hallie"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" age "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("Number"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("isNaN")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("Number"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("isNaN")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("age"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("isNaN")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("isNaN")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("age"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")]),s._v(" "),a("code",[s._v("false")]),s._v(" "),a("code",[s._v("true")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-39"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-39"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("通过方法 "),a("code",[s._v("Number.isNaN")]),s._v("，你可以检测你传递的值是否为 "),a("em",[s._v("数字值")]),s._v(" 并且是否等价于 "),a("code",[s._v("NaN")]),s._v("。"),a("code",[s._v("name")]),s._v(" 不是一个数字值，因此 "),a("code",[s._v("Number.isNaN(name)")]),s._v(" 返回 "),a("code",[s._v("false")]),s._v("。"),a("code",[s._v("age")]),s._v(" 是一个数字值，但它不等价于 "),a("code",[s._v("NaN")]),s._v("，因此 "),a("code",[s._v("Number.isNaN(age)")]),s._v(" 返回 "),a("code",[s._v("false")]),s._v(".")]),s._v(" "),a("p",[s._v("通过方法 "),a("code",[s._v("isNaN")]),s._v("， 你可以检测你传递的值是否一个 number。"),a("code",[s._v("name")]),s._v(" 不是一个 "),a("code",[s._v("number")]),s._v("，因此 "),a("code",[s._v("isNaN(name)")]),s._v(" 返回 "),a("code",[s._v("true")]),s._v(". "),a("code",[s._v("age")]),s._v(" 是一个 "),a("code",[s._v("number")]),s._v(" 因此 "),a("code",[s._v("isNaN(age)")]),s._v(" 返回 "),a("code",[s._v("false")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_129-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_129-输出什么？"}},[s._v("#")]),s._v(" 129. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" randomValue "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getInfo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("typeof")]),s._v(" randomValue"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" randomValue "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia Hallie"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getInfo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('"number"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('"string"')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("ReferenceError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-20"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-20"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("通过 "),a("code",[s._v("const")]),s._v(" 关键字声明的变量在被初始化之前不可被引用：这被称之为 "),a("em",[s._v("暂时性死去")]),s._v("。在函数 "),a("code",[s._v("getInfo")]),s._v(" 中, 变量 "),a("code",[s._v("randomValue")]),s._v(" 声明在"),a("code",[s._v("getInfo")]),s._v(" 的作用域的此法环境中。在想要对 "),a("code",[s._v("typeof randomValue")]),s._v(" 进行log之前，变量 "),a("code",[s._v("randomValue")]),s._v(" 仍未被初始化： 错误"),a("code",[s._v("ReferenceError")]),s._v(" 被抛出! JS引擎并不会根据作用域链网上寻找该变量，因为我们已经在 "),a("code",[s._v("getInfo")]),s._v(" 函数中声明了 "),a("code",[s._v("randomValue")]),s._v(" 变量。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_130-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_130-输出什么？"}},[s._v("#")]),s._v(" 130. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" myPromise "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" Promise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("resolve")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Woah some cool data"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("async")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("try")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("await")]),s._v(" myPromise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("catch")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("throw")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Error")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token template-string"}},[a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("Oops didn't work")]),a("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[s._v("`")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("finally")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Oh finally!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("Woah some cool data")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Oh finally!")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Woah some cool data")]),s._v(" "),a("code",[s._v("Oh finally!")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Oops didn't work")]),s._v(" "),a("code",[s._v("Oh finally!")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-40"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-40"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("在 "),a("code",[s._v("try")]),s._v(" 块区，我们打印 "),a("code",[s._v("myPromise")]),s._v(" 变量的 awaited 值： "),a("code",[s._v('"Woah some cool data"')]),s._v("。因为"),a("code",[s._v("try")]),s._v(" 块区没有错误抛出，"),a("code",[s._v("catch")]),s._v(" 块区的代码并不执行。"),a("code",[s._v("finally")]),s._v(" 块区的代码 "),a("em",[s._v("总是")]),s._v(" 执行，"),a("code",[s._v('"Oh finally!"')]),s._v(" 被输出。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_131-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_131-输出什么？"}},[s._v("#")]),s._v(" 131. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" emojis "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🥑"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"✨"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"✨"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🍕"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🍕"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("emojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("flat")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("['🥑', ['✨', '✨', ['🍕', '🍕']]]")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("['🥑', '✨', '✨', ['🍕', '🍕']]")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("['🥑', ['✨', '✨', '🍕', '🍕']]")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("['🥑', '✨', '✨', '🍕', '🍕']")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-35"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-35"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("通过方法 "),a("code",[s._v("flat")]),s._v("， 我们可以创建一个新的, 已被扁平化的数组。被扁平化的深度取决于我们传递的值。在这个case里，我们传递了值 "),a("code",[s._v("1")]),s._v(" (并不必要，这是默认值)，相当于只有第一层的数组才会被连接。即这个 case 里的 "),a("code",[s._v("['🥑']")]),s._v(" and "),a("code",[s._v("['✨', '✨', ['🍕', '🍕']]")]),s._v("。连接这两个数组得到结果 "),a("code",[s._v("['🥑', '✨', '✨', ['🍕', '🍕']]")]),s._v(".")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_132-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_132-输出什么？"}},[s._v("#")]),s._v(" "),a("a",{attrs:{name:"20191224"}}),s._v("132. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Counter")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("count "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n\t"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("increment")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("count"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" counterOne "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Counter")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\ncounterOne"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("increment")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\ncounterOne"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("increment")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" counterTwo "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" counterOne"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\ncounterTwo"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("increment")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("counterOne"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("count"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br"),a("span",{staticClass:"line-number"},[s._v("16")]),a("br"),a("span",{staticClass:"line-number"},[s._v("17")]),a("br"),a("span",{staticClass:"line-number"},[s._v("18")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("0")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("1")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("2")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("3")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-21"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-21"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[a("code",[s._v("counterOne")]),s._v(" 是类 "),a("code",[s._v("Counter")]),s._v(" 的一个实例。类 Counter 包含一个"),a("code",[s._v("count")]),s._v(" 属性在它的构造函数里， 和一个 "),a("code",[s._v("increment")]),s._v(" 方法。首先，我们通过 "),a("code",[s._v("counterOne.increment()")]),s._v(" 调用方法 "),a("code",[s._v("increment")]),s._v(" 两次。现在, "),a("code",[s._v("counterOne.count")]),s._v(" 为 "),a("code",[s._v("2")]),s._v(".")]),s._v(" "),a("img",{attrs:{src:"https://i.imgur.com/KxLlTm9.png",width:"400"}}),s._v(" "),a("p",[s._v("然后，我们创建一个新的变量 "),a("code",[s._v("counterTwo")]),s._v(" 并将 "),a("code",[s._v("counterOne")]),s._v(" 的引用地址赋值给它。因为对象受引用地址的影响，我们刚刚创建了一个新的对象，其引用地址和 "),a("code",[s._v("counterOne")]),s._v(" 的等价。因此它们指向同一块内存地址，任何对其的副作用都会影响 "),a("code",[s._v("counterTwo")]),s._v("。现在 "),a("code",[s._v("counterTwo.count")]),s._v(" 为 "),a("code",[s._v("2")]),s._v("。")]),s._v(" "),a("p",[s._v("我们调用 "),a("code",[s._v("counterTwo.increment()")]),s._v(" 将 "),a("code",[s._v("count")]),s._v(" 的值设为 "),a("code",[s._v("3")]),s._v("。然后，我们打印 "),a("code",[s._v("counterOne")]),s._v(" 里的count，结果为 "),a("code",[s._v("3")]),s._v("。")]),s._v(" "),a("img",{attrs:{src:"https://i.imgur.com/BNBHXmc.png",width:"400"}}),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_133-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_133-输出什么？"}},[s._v("#")]),s._v(" 133. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" myPromise "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" Promise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("resolve")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("Promise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("resolve")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Promise!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("funcOne")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tmyPromise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("then")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("res")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("then")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("res")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setTimeout")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Timeout!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Last line!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("async")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("funcTwo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" res "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("await")]),s._v(" myPromise"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("await")]),s._v(" res"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("setTimeout")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Timeout!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Last line!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("funcOne")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("funcTwo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br"),a("span",{staticClass:"line-number"},[s._v("16")]),a("br"),a("span",{staticClass:"line-number"},[s._v("17")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("Promise! Last line! Promise! Last line! Last line! Promise!")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Last line! Timeout! Promise! Last line! Timeout! Promise!")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Promise! Last line! Last line! Promise! Timeout! Timeout!")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Last line! Promise! Promise! Last line! Timeout! Timeout!")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-22"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-22"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("首先，我们调用 "),a("code",[s._v("funcOne")]),s._v("。在函数 "),a("code",[s._v("funcOne")]),s._v(" 的第一行，我们调用"),a("code",[s._v("myPromise")]),s._v(" promise "),a("em",[s._v("异步操作")]),s._v("。当JS引擎在忙于执行 promise，它继续执行函数 "),a("code",[s._v("funcOne")]),s._v("。下一行 "),a("em",[s._v("异步操作")]),s._v(" "),a("code",[s._v("setTimeout")]),s._v("，其回调函数被 Web API 调用。 (详情请参考我关于event loop的文章.)")]),s._v(" "),a("p",[s._v("promise 和 timeout 都是异步操作，函数继续执行当JS引擎忙于执行promise 和 处理 "),a("code",[s._v("setTimeout")]),s._v(" 的回调。相当于 "),a("code",[s._v("Last line!")]),s._v(" 首先被输出， 因为它不是异步操作。执行完 "),a("code",[s._v("funcOne")]),s._v(" 的最后一行，promise 状态转变为 resolved，"),a("code",[s._v("Promise!")]),s._v(" 被打印。然而，因为我们调用了 "),a("code",[s._v("funcTwo()")]),s._v(", 调用栈不为空，"),a("code",[s._v("setTimeout")]),s._v(" 的回调仍不能入栈。")]),s._v(" "),a("p",[s._v("我们现在处于 "),a("code",[s._v("funcTwo")]),s._v("，先 "),a("em",[s._v("awaiting")]),s._v(" myPromise。通过 "),a("code",[s._v("await")]),s._v(" 关键字， 我们暂停了函数的执行直到 promise 状态变为 resolved (或 rejected)。然后，我们输出 "),a("code",[s._v("res")]),s._v(" 的 awaited 值（因为 promise 本身返回一个 promise）。 接着输出 "),a("code",[s._v("Promise!")]),s._v("。")]),s._v(" "),a("p",[s._v("下一行就是 "),a("em",[s._v("异步操作")]),s._v(" "),a("code",[s._v("setTimeout")]),s._v("，其回调函数被 Web API 调用。")]),s._v(" "),a("p",[s._v("我们执行到函数 "),a("code",[s._v("funcTwo")]),s._v(" 的最后一行，输出 "),a("code",[s._v("Last line!")]),s._v("。现在，因为 "),a("code",[s._v("funcTwo")]),s._v(" 出栈，调用栈为空。在事件队列中等待的回调函数（"),a("code",[s._v('() => console.log("Timeout!")')]),s._v(" from "),a("code",[s._v("funcOne")]),s._v(", and "),a("code",[s._v('() => console.log("Timeout!")')]),s._v(" from "),a("code",[s._v("funcTwo")]),s._v("）以此入栈。第一个回调输出 "),a("code",[s._v("Timeout!")]),s._v("，并出栈。然后，第二个回调输出 "),a("code",[s._v("Timeout!")]),s._v("，并出栈。得到结果 "),a("code",[s._v("Last line! Promise! Promise! Last line! Timeout! Timeout!")])]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_134-我们怎样才能在-index-js-中调用-sum-js-中的-sum？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_134-我们怎样才能在-index-js-中调用-sum-js-中的-sum？"}},[s._v("#")]),s._v(" 134. 我们怎样才能在 "),a("code",[s._v("index.js")]),s._v(" 中调用 "),a("code",[s._v("sum.js?")]),s._v(" 中的 "),a("code",[s._v("sum")]),s._v("？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// sum.js")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("export")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("default")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sum")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// index.js")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("import")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("as")]),s._v(" sum "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("from")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"./sum"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("sum(4)")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("sum.sum(4)")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("sum.default(4)")])]),s._v(" "),a("li",[s._v("D: 默认导出不用 "),a("code",[s._v("*")]),s._v(" 来导入，只能具名导出")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-41"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-41"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("使用符号 "),a("code",[s._v("*")]),s._v("，我们引入文件中的所有值，包括默认和具名。如果我们有以下文件：")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// info.js")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("export")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("export")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" age "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("export")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("default")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"I love JavaScript"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// index.js")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("import")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("as")]),s._v(" info "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("from")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"./info"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("info"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("p",[s._v("将会输出以下内容：")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("default")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"I love JavaScript"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("p",[s._v("以 "),a("code",[s._v("sum")]),s._v(" 为例，相当于以下形式引入值 "),a("code",[s._v("sum")]),s._v("：")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("default")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("sum")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("我们可以通过调用 "),a("code",[s._v("sum.default")]),s._v(" 来调用该函数")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_135-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_135-输出什么？"}},[s._v("#")]),s._v(" 135. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" handler "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("set")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Added a new property!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("get")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" console"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Accessed a property!"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Proxy")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" handler"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nperson"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nperson"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("Added a new property!")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("Accessed a property!")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("Added a new property!")]),s._v(" "),a("code",[s._v("Accessed a property!")])]),s._v(" "),a("li",[s._v("D: 没有任何输出")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-42"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-42"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("使用 Proxy 对象，我们可以给一个对象添加自定义行为。在这个 case，我们传递一个包含以下属性的对象 "),a("code",[s._v("handler")]),s._v(" : "),a("code",[s._v("set")]),s._v(" and "),a("code",[s._v("get")]),s._v("。每当我门 "),a("em",[s._v("设置")]),s._v(" 属性值时 "),a("code",[s._v("set")]),s._v(" 被调用，每当我们 "),a("em",[s._v("获取")]),s._v(" 时 "),a("code",[s._v("get")]),s._v(" 被调用。")]),s._v(" "),a("p",[s._v("第一个参数是一个空对象 "),a("code",[s._v("{}")]),s._v("，作为 "),a("code",[s._v("person")]),s._v(" 的值。对于这个对象，自定义行为被定义在对象 "),a("code",[s._v("handler")]),s._v("。如果我们向对象 "),a("code",[s._v("person")]),s._v(" 添加属性，"),a("code",[s._v("set")]),s._v(" 将被调用。如果我们获取 "),a("code",[s._v("person")]),s._v(" 的属性, "),a("code",[s._v("get")]),s._v(" 将被调用。")]),s._v(" "),a("p",[s._v("首先，我们向 proxy 对象("),a("code",[s._v('person.name = "Lydia"')]),s._v(")添加一个属性 "),a("code",[s._v("name")]),s._v("。"),a("code",[s._v("set")]),s._v(" 被调用并输出 "),a("code",[s._v('"Added a new property!"')]),s._v("。")]),s._v(" "),a("p",[s._v("然后，我们获取 proxy 对象的一个属性，对象 handler 的属性 "),a("code",[s._v("get")]),s._v(" 被调用。输出 "),a("code",[s._v('"Accessed a property!"')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_136-以下哪一项会对对象-person-有副作用？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_136-以下哪一项会对对象-person-有副作用？"}},[s._v("#")]),s._v(" 136. 以下哪一项会对对象 "),a("code",[s._v("person")]),s._v(" 有副作用？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia Hallie"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nObject"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("seal")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('person.name = "Evan Bacon"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("person.age = 21")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("delete person.name")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("Object.assign(person, { age: 21 })")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-37"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-37"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("使用 "),a("code",[s._v("Object.seal")]),s._v(" 我们可以防止新属性 "),a("em",[s._v("被添加")]),s._v("，或者存在属性 "),a("em",[s._v("被移除")]),s._v(".")]),s._v(" "),a("p",[s._v("然而，你仍然可以对存在属性进行更改。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_137-以下哪一项会对对象-person-有副作用？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_137-以下哪一项会对对象-person-有副作用？"}},[s._v("#")]),s._v(" 137. 以下哪一项会对对象 "),a("code",[s._v("person")]),s._v(" 有副作用？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tname"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia Hallie"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n\taddress"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\tstreet"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"100 Main St"')]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nObject"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("freeze")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('person.name = "Evan Bacon"')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("delete person.address")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('person.address.street = "101 Main St"')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('person.pet = { name: "Mara" }')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-43"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-43"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("使用方法 "),a("code",[s._v("Object.freeze")]),s._v(" 对一个对象进行 "),a("em",[s._v("冻结")]),s._v("。不能对属性进行添加，修改，删除。")]),s._v(" "),a("p",[s._v("然而，它仅 对对象进行 "),a("em",[s._v("浅")]),s._v(" 冻结，意味着只有 对象中的 "),a("em",[s._v("直接")]),s._v(" 属性被冻结。如果属性是另一个 object，像案例中的 "),a("code",[s._v("address")]),s._v("，"),a("code",[s._v("address")]),s._v(" 中的属性没有被冻结，仍然可以被修改。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_138-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_138-输出什么？"}},[s._v("#")]),s._v(" 138. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[s._v("add")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("x")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=>")]),s._v(" x "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("+")]),s._v(" x"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("myFunc")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("num "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" value "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("num"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")])]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("num"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" value"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("myFunc")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("myFunc")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("3")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("4")]),s._v(" and "),a("code",[s._v("3")]),s._v(" "),a("code",[s._v("6")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("NaN")]),s._v(" and "),a("code",[s._v("3")]),s._v(" "),a("code",[s._v("NaN")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("Error")]),s._v(" and "),a("code",[s._v("3")]),s._v(" "),a("code",[s._v("6")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("2")]),s._v(" "),a("code",[s._v("4")]),s._v(" and "),a("code",[s._v("3")]),s._v(" "),a("code",[s._v("Error")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-a-38"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-38"}},[s._v("#")]),s._v(" 答案: A")]),s._v(" "),a("p",[s._v("首先我们不传递任何参数调用 "),a("code",[s._v("myFunc()")]),s._v("。因为我们没有传递参数，"),a("code",[s._v("num")]),s._v(" 和 "),a("code",[s._v("value")]),s._v(" 获取它们各自的默认值：num 为 "),a("code",[s._v("2")]),s._v(", 而 "),a("code",[s._v("value")]),s._v(" 为函数 "),a("code",[s._v("add")]),s._v(" 的返回值。对于函数 "),a("code",[s._v("add")]),s._v("，我们传递值为2的 "),a("code",[s._v("num")]),s._v(" 作为参数。函数 "),a("code",[s._v("add")]),s._v(" 返回 "),a("code",[s._v("4")]),s._v(" 作为 "),a("code",[s._v("value")]),s._v(" 的值。")]),s._v(" "),a("p",[s._v("然后，我们调用 "),a("code",[s._v("myFunc(3)")]),s._v(" 并传递值 "),a("code",[s._v("3")]),s._v(" 参数 "),a("code",[s._v("num")]),s._v(" 的值。我们没有给 "),a("code",[s._v("value")]),s._v(" 传递值。因为我们没有给参数 "),a("code",[s._v("value")]),s._v(" 传递值，它获取默认值：函数 "),a("code",[s._v("add")]),s._v(" 的返回值。对于函数 "),a("code",[s._v("add")]),s._v("，我们传递值为3的 "),a("code",[s._v("num")]),s._v("给它。函数 "),a("code",[s._v("add")]),s._v(" 返回 "),a("code",[s._v("6")]),s._v(" 作为 "),a("code",[s._v("value")]),s._v(" 的值。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_139-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_139-输出什么？"}},[s._v("#")]),s._v(" 139. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Counter")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  #number "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("10")]),s._v("\n\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("increment")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("#number"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),s._v("\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n  "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getNum")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n    "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("this")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("#number\n  "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" counter "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Counter")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\ncounter"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("increment")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("counter"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("#number"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br"),a("span",{staticClass:"line-number"},[s._v("16")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("10")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("11")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("undefined")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("SyntaxError")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-23"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-23"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[s._v("在 ES2020 中，通过 "),a("code",[s._v("#")]),s._v(" 我们可以给 class 添加私有变量。在 class 的外部我们无法获取该值。当我们尝试输出 "),a("code",[s._v("counter.#number")]),s._v("，语法错误被抛出：我们无法在 class "),a("code",[s._v("Counter")]),s._v(" 外部获取它!")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_140-选择哪一个？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_140-选择哪一个？"}},[s._v("#")]),s._v(" 140. 选择哪一个？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" teams "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Team 1"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" members"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Paul"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lisa"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v(" name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Team 2"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" members"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Laura"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Tim"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getMembers")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("members")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v(" members"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("length"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("yield")]),s._v(" members"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("*")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getTeams")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("teams")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("let")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v(" teams"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("length"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" i"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\t"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("// ✨ SOMETHING IS MISSING HERE ✨")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" obj "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("getTeams")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("teams"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\nobj"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v('// { value: "Paul", done: false }')]),s._v("\nobj"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("next")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v('// { value: "Lisa", done: false }')]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br"),a("span",{staticClass:"line-number"},[s._v("16")]),a("br"),a("span",{staticClass:"line-number"},[s._v("17")]),a("br"),a("span",{staticClass:"line-number"},[s._v("18")]),a("br"),a("span",{staticClass:"line-number"},[s._v("19")]),a("br"),a("span",{staticClass:"line-number"},[s._v("20")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("yield getMembers(teams[i].members)")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("yield* getMembers(teams[i].members)")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("return getMembers(teams[i].members)")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("return yield getMembers(teams[i].members)")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-36"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-36"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("为了遍历 "),a("code",[s._v("teams")]),s._v(" 数组中对象的属性 "),a("code",[s._v("members")]),s._v(" 中的每一项，我们需要将 "),a("code",[s._v("teams[i].members")]),s._v(" 传递给 Generator 函数 "),a("code",[s._v("getMembers")]),s._v("。Generator 函数返回一个 generator 对象。为了遍历这个 generator 对象中的每一项，我们需要使用 "),a("code",[s._v("yield*")]),s._v(".")]),s._v(" "),a("p",[s._v("如果我们没有写 "),a("code",[s._v("yield")]),s._v("，"),a("code",[s._v("return yield")]),s._v(" 或者 "),a("code",[s._v("return")]),s._v("，整个 Generator 函数不会第一时间 return 当我们调用 "),a("code",[s._v("next")]),s._v(" 方法.")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_141-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_141-输出什么？"}},[s._v("#")]),s._v(" 141. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\tname"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia Hallie"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n\thobbies"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"coding"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("function")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("addHobby")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[s._v("hobby"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" hobbies "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("hobbies")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\thobbies"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("push")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("hobby"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("return")]),s._v(" hobbies"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("addHobby")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"running"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("addHobby")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"dancing"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("addHobby")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"baking"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("hobbies"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\nconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("hobbies"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v('["coding"]')])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v('["coding", "dancing"]')])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v('["coding", "dancing", "baking"]')])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v('["coding", "running", "dancing", "baking"]')])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-44"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-44"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("函数 "),a("code",[s._v("addHobby")]),s._v(" 接受两个参数，"),a("code",[s._v("hobby")]),s._v(" 和有着对象 "),a("code",[s._v("person")]),s._v(" 中数组 "),a("code",[s._v("hobbies")]),s._v(" 默认值的 "),a("code",[s._v("hobbies")]),s._v("。")]),s._v(" "),a("p",[s._v("首相，我们调用函数 "),a("code",[s._v("addHobby")]),s._v("，并给 "),a("code",[s._v("hobby")]),s._v(" 传递 "),a("code",[s._v('"running"')]),s._v(" 以及给 "),a("code",[s._v("hobbies")]),s._v(" 传递一个空数组。因为我们给 "),a("code",[s._v("hobbies")]),s._v(" 传递了空数组，"),a("code",[s._v('"running"')]),s._v(" 被添加到这个空数组。")]),s._v(" "),a("p",[s._v("然后，我们调用函数 "),a("code",[s._v("addHobby")]),s._v("，并给 "),a("code",[s._v("hobby")]),s._v(" 传递 "),a("code",[s._v('"dancing"')]),s._v("。我们不向 "),a("code",[s._v("hobbies")]),s._v(" 传递值，因此它获取其默认值 —— 对象 "),a("code",[s._v("person")]),s._v(" 的 属性 "),a("code",[s._v("hobbies")]),s._v("。我们向数组 "),a("code",[s._v("person.hobbies")]),s._v(" push "),a("code",[s._v("dancing")]),s._v("。")]),s._v(" "),a("p",[s._v("最后，我们调用函数 "),a("code",[s._v("addHobby")]),s._v("，并向 "),a("code",[s._v("hobby")]),s._v(" 传递 值 "),a("code",[s._v('"bdaking"')]),s._v("，并且向 "),a("code",[s._v("hobbies")]),s._v(" 传递 "),a("code",[s._v("person.hobbies")]),s._v("。我们向数组 "),a("code",[s._v("person.hobbies")]),s._v(" push "),a("code",[s._v("dancing")]),s._v("。")]),s._v(" "),a("p",[s._v("pushing "),a("code",[s._v("dancing")]),s._v(" 和 "),a("code",[s._v("baking")]),s._v(" 之后，"),a("code",[s._v("person.hobbies")]),s._v(" 的值为 "),a("code",[s._v('["coding", "dancing", "baking"]')])]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_142-输出什么？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_142-输出什么？"}},[s._v("#")]),s._v(" 142. 输出什么？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Bird")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"I\'m a bird. 🦢"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("class")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Flamingo")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("extends")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Bird")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("constructor")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n\t\tconsole"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("log")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"I\'m pink. 🌸"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t\t"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("super")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\t"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" pet "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("new")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token class-name"}},[s._v("Flamingo")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br")])]),a("ul",[a("li",[s._v("A: "),a("code",[s._v("I'm pink. 🌸")])]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("I'm pink. 🌸")]),s._v(" "),a("code",[s._v("I'm a bird. 🦢")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("I'm a bird. 🦢")]),s._v(" "),a("code",[s._v("I'm pink. 🌸")])]),s._v(" "),a("li",[s._v("D: Nothing, we didn't call any method")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-b-37"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-37"}},[s._v("#")]),s._v(" 答案: B")]),s._v(" "),a("p",[s._v("我们创建了类 "),a("code",[s._v("Flamingo")]),s._v(" 的实例 "),a("code",[s._v("pet")]),s._v("。当我们实例化这个实例，"),a("code",[s._v("Flamingo")]),s._v(" 中的 "),a("code",[s._v("constructor")]),s._v(" 被调用。首相，输出 "),a("code",[s._v('"I\'m pink. 🌸"')]),s._v(", 之后我们调用"),a("code",[s._v("super()")]),s._v("。"),a("code",[s._v("super()")]),s._v(" 调用父类的构造函数，"),a("code",[s._v("Bird")]),s._v("。"),a("code",[s._v("Bird")]),s._v(" 的构造函数被调用，并输出 "),a("code",[s._v('"I\'m a bird. 🦢"')]),s._v("。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_143-哪一个选项会导致报错？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_143-哪一个选项会导致报错？"}},[s._v("#")]),s._v(" 143. 哪一个选项会导致报错？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" emojis "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🎄"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🎅🏼"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🎁"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"⭐"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("/* 1 */")]),s._v(" emojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("push")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🦌"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("/* 2 */")]),s._v(" emojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("splice")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("/* 3 */")]),s._v(" emojis "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("emojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"🥂"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("/* 4 */")]),s._v(" emojis"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(".")]),s._v("length "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(";")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: 1")]),s._v(" "),a("li",[s._v("B: 1 and 2")]),s._v(" "),a("li",[s._v("C: 3 and 4")]),s._v(" "),a("li",[s._v("D: 3")])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-d-24"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-24"}},[s._v("#")]),s._v(" 答案: D")]),s._v(" "),a("p",[a("code",[s._v("const")]),s._v(" 关键字意味着我们不能 "),a("em",[s._v("重定义")]),s._v(" 变量中的值，它 "),a("em",[s._v("仅可读")]),s._v("。而然，值本身不可修改。数组 "),a("code",[s._v("emojis")]),s._v(" 中的值可被修改，如 push 新的值, 拼接，又或者将数组的长度设置为0。")]),s._v(" "),a("p")]),s._v(" "),a("hr"),s._v(" "),a("h4",{attrs:{id:"_144-我们需要向对象-person-添加什么，以致执行-person-时获得形如-lydia-hallie-21-的输出？"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_144-我们需要向对象-person-添加什么，以致执行-person-时获得形如-lydia-hallie-21-的输出？"}},[s._v("#")]),s._v(" 144. 我们需要向对象 "),a("code",[s._v("person")]),s._v(" 添加什么，以致执行 "),a("code",[s._v("[...person]")]),s._v(" 时获得形如 "),a("code",[s._v('["Lydia Hallie", 21]')]),s._v(" 的输出？")]),s._v(" "),a("div",{staticClass:"language-javascript line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("const")]),s._v(" person "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("{")]),s._v("\n  name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"Lydia Hallie"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(",")]),s._v("\n  age"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(":")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("}")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("...")]),s._v("person"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v('// ["Lydia Hallie", 21]')]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br")])]),a("ul",[a("li",[s._v("A: 不需要，对象默认就是可迭代的")]),s._v(" "),a("li",[s._v("B: "),a("code",[s._v("*[Symbol.iterator]() { for (let x in this) yield* this[x] }")])]),s._v(" "),a("li",[s._v("C: "),a("code",[s._v("*[Symbol.iterator]() { for (let x in this) yield* Object.values(this) }")])]),s._v(" "),a("li",[s._v("D: "),a("code",[s._v("*[Symbol.iterator]() { for (let x in this) yield this }")])])]),s._v(" "),a("details",[a("summary",[a("b",[s._v("答案")])]),s._v(" "),a("p"),a("h4",{attrs:{id:"答案-c-45"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-45"}},[s._v("#")]),s._v(" 答案: C")]),s._v(" "),a("p",[s._v("对象默认并不是可迭代的。如果迭代规则被定义，则一个对象是可迭代的（An iterable is an iterable if the iterator protocol is present）。我们可以通过添加迭代器symbol "),a("code",[s._v("[Symbol.iterator]")]),s._v(" 来定义迭代规则，其返回一个 generator 对象，比如说构建一个 generator 函数 "),a("code",[s._v("*[Symbol.iterator]() {}")]),s._v("。如果我们想要返回数组 "),a("code",[s._v('["Lydia Hallie", 21]')]),s._v(": "),a("code",[s._v("yield* Object.values(this)")]),s._v("，这个 generator 函数一定要 yield 对象 "),a("code",[s._v("person")]),s._v(" 的"),a("code",[s._v("Object.values")]),s._v("。")]),s._v(" "),a("p")])])}),[],!1,null,null,null);t.default=e.exports}}]);