From f49fe88286d20adff1025d52b73a70d55685a318 Mon Sep 17 00:00:00 2001 From: 2xiao <827574297wxxtb@sina.com> Date: Mon, 30 Oct 2023 21:44:33 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20=20@=2032084?= =?UTF-8?q?f69ded3b5614953c971c47f4a8883a01cbd=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 404.html | 6 +- .../js/{130.73b73bb8.js => 130.efc790d3.js} | 2 +- .../js/{132.685c3342.js => 132.99483200.js} | 2 +- .../js/{137.d41b0742.js => 137.57a96f72.js} | 2 +- .../js/{138.d691c767.js => 138.2a52cce3.js} | 2 +- assets/js/16.47bca1a5.js | 1 + assets/js/16.89f608ba.js | 1 - assets/js/17.e0522960.js | 1 - assets/js/17.f204a89a.js | 1 + assets/js/30.101b2813.js | 1 - assets/js/30.20fca599.js | 1 + assets/js/{33.1fe42da9.js => 33.51b65a31.js} | 2 +- assets/js/{34.63d3fafa.js => 34.98fa8d33.js} | 2 +- assets/js/70.3bcafc1f.js | 1 + assets/js/70.f226e9bd.js | 1 - assets/js/71.4be81573.js | 1 - assets/js/71.627d9732.js | 1 + assets/js/72.4836d96e.js | 1 - assets/js/72.61ee7a07.js | 1 + assets/js/77.a1b4142c.js | 1 - assets/js/77.a4a2a77e.js | 1 + assets/js/{87.79d5ddce.js => 87.b80a6ef8.js} | 2 +- .../js/{app.53d1ecaf.js => app.bddd4a5c.js} | 14 +- fe/basic/1.html | 6 +- fe/index.html | 6 +- index.html | 6 +- leetcode/algorithm/0_enumeration.html | 6 +- leetcode/algorithm/10_slide_window.html | 6 +- leetcode/algorithm/1_recursion.html | 6 +- leetcode/algorithm/2_divide_conquer.html | 6 +- leetcode/algorithm/3_backtracking.html | 6 +- leetcode/algorithm/4_greed.html | 6 +- leetcode/algorithm/5_dynamic_programming.html | 6 +- leetcode/algorithm/6_bit.html | 6 +- leetcode/algorithm/7_sort.html | 6 +- leetcode/algorithm/8_binary_search.html | 6 +- leetcode/algorithm/9_two_pointer.html | 6 +- leetcode/ds/0_array.html | 8 +- leetcode/ds/1_linked_list.html | 6 +- leetcode/ds/2_stack.html | 6 +- leetcode/ds/3_queue.html | 6 +- leetcode/ds/4_hash_table.html | 6 +- leetcode/ds/5_string.html | 6 +- leetcode/ds/6_tree.html | 6 +- leetcode/ds/7_graph.html | 6 +- leetcode/index.html | 6 +- leetcode/outline/0_table.html | 8 +- leetcode/outline/1_complexity.html | 8 +- leetcode/outline/2_solution_list.html | 6 +- leetcode/outline/3_categories_list.html | 6 +- leetcode/outline/4_top_200_list.html | 6 +- leetcode/outline/5_frequency_list.html | 6 +- leetcode/outline/6_company_list.html | 6 +- leetcode/problem/0001.html | 6 +- leetcode/problem/0002.html | 6 +- leetcode/problem/0003.html | 6 +- leetcode/problem/0004.html | 6 +- leetcode/problem/0005.html | 6 +- leetcode/problem/0006.html | 6 +- leetcode/problem/0007.html | 6 +- leetcode/problem/0008.html | 6 +- leetcode/problem/0009.html | 6 +- leetcode/problem/0011.html | 6 +- leetcode/problem/0013.html | 6 +- leetcode/problem/0015.html | 6 +- leetcode/problem/0016.html | 6 +- leetcode/problem/0018.html | 6 +- leetcode/problem/0020.html | 6 +- leetcode/problem/0026.html | 6 +- leetcode/problem/0027.html | 6 +- leetcode/problem/0033.html | 6 +- leetcode/problem/0048.html | 134 +++++---------- leetcode/problem/0054.html | 162 +++++------------- leetcode/problem/0059.html | 110 ++++++------ leetcode/problem/0062.html | 6 +- leetcode/problem/0063.html | 6 +- leetcode/problem/0066.html | 6 +- leetcode/problem/0070.html | 6 +- leetcode/problem/0073.html | 122 +++++++------ leetcode/problem/0080.html | 6 +- leetcode/problem/0120.html | 6 +- leetcode/problem/0125.html | 6 +- leetcode/problem/0152.html | 6 +- leetcode/problem/0167.html | 6 +- leetcode/problem/0189.html | 6 +- leetcode/problem/0206.html | 6 +- leetcode/problem/0227.html | 6 +- leetcode/problem/0238.html | 6 +- leetcode/problem/0259.html | 8 +- leetcode/problem/0279.html | 6 +- leetcode/problem/0283.html | 6 +- leetcode/problem/0344.html | 6 +- leetcode/problem/0345.html | 6 +- leetcode/problem/0485.html | 6 +- leetcode/problem/0498.html | 6 +- leetcode/problem/0509.html | 6 +- leetcode/problem/0611.html | 6 +- leetcode/problem/0724.html | 6 +- leetcode/problem/1047.html | 6 +- leetcode/problem/LCP_53.html | 6 +- leetcode/problem/i_03.01.html | 6 +- leetcode/problem/jz_offer_59_2.html | 6 +- leetcode/problem/jz_offer_II_055.html | 6 +- leetcode/solution/0001-0099.html | 6 +- leetcode/solution/0100-0199.html | 6 +- leetcode/solution/0200-0299.html | 6 +- leetcode/solution/0300-0399.html | 6 +- leetcode/solution/0400-0499.html | 6 +- leetcode/solution/0500-0599.html | 6 +- leetcode/solution/0600-0699.html | 6 +- leetcode/solution/0700-0799.html | 6 +- leetcode/solution/1000-1099.html | 6 +- leetcode/solution/Interviews.html | 6 +- leetcode/solution/LCP.html | 6 +- leetcode/solution/Offer-II.html | 6 +- leetcode/solution/Offer.html | 6 +- magic.html | 6 +- react/1.1.html | 6 +- react/2.1.html | 6 +- react/index.html | 6 +- run/blog/before_quit.html | 6 +- run/blog/go_home.html | 6 +- run/blog/grandma.html | 6 +- run/blog/miss_bj.html | 6 +- run/blog/money.html | 6 +- run/blog/new_year.html | 6 +- run/blog/principle.html | 6 +- run/blog/three_years_plan.html | 6 +- run/blog/work_overtime.html | 6 +- run/europe/0_why.html | 6 +- run/europe/1_intro.html | 6 +- run/index.html | 6 +- run/usa/10043.html | 6 +- run/usa/digital_nomad.html | 6 +- run/usa/indian.html | 6 +- run/usa/live_in_us.html | 6 +- run/usa/mississippi.html | 6 +- run/usa/neighbor.html | 6 +- run/usa/quit.html | 6 +- run/usa/transfer.html | 6 +- run/usa/visa.html | 6 +- run/usa/where_to_go.html | 6 +- 142 files changed, 568 insertions(+), 706 deletions(-) rename assets/js/{130.73b73bb8.js => 130.efc790d3.js} (98%) rename assets/js/{132.685c3342.js => 132.99483200.js} (97%) rename assets/js/{137.d41b0742.js => 137.57a96f72.js} (88%) rename assets/js/{138.d691c767.js => 138.2a52cce3.js} (99%) create mode 100644 assets/js/16.47bca1a5.js delete mode 100644 assets/js/16.89f608ba.js delete mode 100644 assets/js/17.e0522960.js create mode 100644 assets/js/17.f204a89a.js delete mode 100644 assets/js/30.101b2813.js create mode 100644 assets/js/30.20fca599.js rename assets/js/{33.1fe42da9.js => 33.51b65a31.js} (89%) rename assets/js/{34.63d3fafa.js => 34.98fa8d33.js} (99%) create mode 100644 assets/js/70.3bcafc1f.js delete mode 100644 assets/js/70.f226e9bd.js delete mode 100644 assets/js/71.4be81573.js create mode 100644 assets/js/71.627d9732.js delete mode 100644 assets/js/72.4836d96e.js create mode 100644 assets/js/72.61ee7a07.js delete mode 100644 assets/js/77.a1b4142c.js create mode 100644 assets/js/77.a4a2a77e.js rename assets/js/{87.79d5ddce.js => 87.b80a6ef8.js} (62%) rename assets/js/{app.53d1ecaf.js => app.bddd4a5c.js} (88%) diff --git a/404.html b/404.html index dd02eab995..ccc8f59e9d 100644 --- a/404.html +++ b/404.html @@ -8,11 +8,11 @@ - + -

404

Looks like we've got some broken links.
Take me home.
- +

404

That's a Four-Oh-Four.
Take me home.
+ diff --git a/assets/js/130.73b73bb8.js b/assets/js/130.efc790d3.js similarity index 98% rename from assets/js/130.73b73bb8.js rename to assets/js/130.efc790d3.js index cf7287da29..7b013b6fed 100644 --- a/assets/js/130.73b73bb8.js +++ b/assets/js/130.efc790d3.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[130],{578:function(t,r,a){"use strict";a.r(r);var e=a(30),s=Object(e.a)({},(function(){var t=this,r=t._self._c;return r("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[r("h1",{attrs:{id:"_10043润美方法"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#_10043润美方法"}},[t._v("#")]),t._v(" 10043润美方法")]),t._v(" "),r("p",[r("font",{attrs:{color:"gray"}},[t._v("Last updated on 2022-01-01")])],1),t._v(" "),r("div",{staticClass:"custom-block tip"},[r("p",[t._v("本文转载自"),r("a",{attrs:{href:"https://github.com/The-Run-Philosophy-Organization/run/blob/main/%E6%B6%A6%E5%AD%A6%E5%AE%9E%E4%BE%8B/10043%E5%AD%A6%E6%A0%A1%E5%A6%82%E4%BD%95%E6%B6%A6/10043%E6%B6%A6%E7%BE%8E%E6%96%B9%E6%B3%95.md",target:"_blank",rel:"noopener noreferrer"}},[t._v("润学Github"),r("OutboundLink")],1)])]),t._v(" "),r("h2",{attrs:{id:"方法一-加拿大曲线救国-成功几率最大最可靠"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#方法一-加拿大曲线救国-成功几率最大最可靠"}},[t._v("#")]),t._v(" 方法一 加拿大曲线救国(成功几率最大最可靠)")]),t._v(" "),r("ul",[r("li",[t._v("先申请加拿大CS的硕士或博士(单纯为了润不建议读博士),毕业后拿枫叶卡同时进一个互联网公司,之后拿L1工签南下去美国,美国的互联网大厂基本都在加拿大有分部,所以机会不少,但工资相对低一些,但也比缅甸生活的舒服。")]),t._v(" "),r("li",[t._v("加拿大拿卡相对美国容易得多,第一种常见的方法是走"),r("a",{attrs:{href:"https://archive.ph/J9EOY",target:"_blank",rel:"noopener noreferrer"}},[t._v("EE"),r("OutboundLink")],1),t._v("(Express Entry)通道,"),r("a",{attrs:{href:"https://www.cic.gc.ca/english/immigrate/skilled/crs-tool.asp",target:"_blank",rel:"noopener noreferrer"}},[t._v("打分制"),r("OutboundLink")],1),t._v(",包括年龄,学历,雅思成绩等等,到达这个门槛就可以获得省提名,近几年的最低门槛是450-470左右。")]),t._v(" "),r("li",[t._v("第二种方法是申请BC省(不列颠哥伦比亚省)学校的硕士或者博士,毕业后可以直接拿到省提名,拿到省提名大概半年后就可以拿到枫叶卡。学校名单点击"),r("a",{attrs:{href:"https://www.welcomebc.ca/Immigrate-to-B-C/documents/BC-PNP-IPG-EEBC-IPG-Eligible-Programs-of-Study.aspx",target:"_blank",rel:"noopener noreferrer"}},[t._v("这里"),r("OutboundLink")],1),t._v("。")]),t._v(" "),r("li",[t._v("加拿大读硕士大概一年半左右,总共需要约20-30wRMB。")]),t._v(" "),r("li",[t._v("10043首选加拿大,因为加拿大承接了美国大部分公司的分公司,据我所知温哥华微软和亚马逊一直在常年招人。现在亚马逊这么缺人,加拿大L4开出的总包也有160k加币了,虽然是比美国低一点,但是升职上去了有250k加币也不低了啊。而且相比美国,加拿大枫叶卡获取难度极低,等于白送。加拿大的妹子又多,温哥华中餐又好,比你去湾区卷不是好很多吗?")])]),t._v(" "),r("h2",{attrs:{id:"方法二-找外企工作transfer去美国"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#方法二-找外企工作transfer去美国"}},[t._v("#")]),t._v(" 方法二 找外企工作transfer去美国")]),t._v(" "),r("ul",[r("li",[t._v("卷进国内外企,如微软,Amazon,Google,内部转岗去美国,难度较大,不够可靠。")]),t._v(" "),r("li",[t._v("直接面外国大厂,例如新加坡、欧洲或者加拿大的Amazon,Google等(美国本土基本没机会)。\n如果有能力或者有一定工作经验,可以打磨好自己的LinkedIn,\n去找猎头聊天或者等猎头找你,约面试,面试过了之后拿L1签证去新加坡、欧洲或加拿大,最后再润去美国。")]),t._v(" "),r("li",[t._v("适用于有一定工作经验且英语好的人,也有点运气成分在里面。")])]),t._v(" "),r("h2",{attrs:{id:"方法三-新加坡、欧洲曲线救国"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#方法三-新加坡、欧洲曲线救国"}},[t._v("#")]),t._v(" 方法三 新加坡、欧洲曲线救国")]),t._v(" "),r("ul",[r("li",[t._v("类似于去加拿大读书,也可以去欧洲或者新加坡读书拿身份,再润去美国,\n但这些国家的移民政策的相对于加拿大来说条件太多,例如新加坡可能需要5年才能拿到卡,欧洲也差不多,时间成本太高,不太建议。")])]),t._v(" "),r("h2",{attrs:{id:"方法四-美国交换"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#方法四-美国交换"}},[t._v("#")]),t._v(" 方法四 美国交换")]),t._v(" "),r("ul",[r("li",[t._v("10043学校如哈工大有UCI 3+1+1项目,其中第一年挂在教育学院下并且只是本科交换,卡签概率比较小,入境后可正常留在UCI读完3+2或在3+1后申请其他美国学校,UCI的3+2项目可行性已确认,别的学期交换理论上也是可行,可以一试。")])]),t._v(" "),r("h2",{attrs:{id:"方法五-境内转身份"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#方法五-境内转身份"}},[t._v("#")]),t._v(" 方法五 境内转身份")]),t._v(" "),r("ul",[r("li",[t._v("亲测10043学校毕业生可以正常申请B签,但是无法申请F类、J类签证。可以先去大使馆"),r("a",{attrs:{href:"./0_visa"}},[t._v("申请B签")]),t._v("入境;")]),t._v(" "),r("li",[t._v("入境后向移民局申请转F类或者J类签证,亲测USCIS并不care10043;")]),t._v(" "),r("li",[t._v("申请F2、J2的通过率很高,但是F1、J1的通过率较低,会被质疑入境目的不纯;")]),t._v(" "),r("li",[t._v("转身份仅限境内有效,一旦出境,就需要再去大使馆重新申请签证。")])])])}),[],!1,null,null,null);r.default=s.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[130],{576:function(t,r,a){"use strict";a.r(r);var e=a(30),s=Object(e.a)({},(function(){var t=this,r=t._self._c;return r("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[r("h1",{attrs:{id:"_10043润美方法"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#_10043润美方法"}},[t._v("#")]),t._v(" 10043润美方法")]),t._v(" "),r("p",[r("font",{attrs:{color:"gray"}},[t._v("Last updated on 2022-01-01")])],1),t._v(" "),r("div",{staticClass:"custom-block tip"},[r("p",[t._v("本文转载自"),r("a",{attrs:{href:"https://github.com/The-Run-Philosophy-Organization/run/blob/main/%E6%B6%A6%E5%AD%A6%E5%AE%9E%E4%BE%8B/10043%E5%AD%A6%E6%A0%A1%E5%A6%82%E4%BD%95%E6%B6%A6/10043%E6%B6%A6%E7%BE%8E%E6%96%B9%E6%B3%95.md",target:"_blank",rel:"noopener noreferrer"}},[t._v("润学Github"),r("OutboundLink")],1)])]),t._v(" "),r("h2",{attrs:{id:"方法一-加拿大曲线救国-成功几率最大最可靠"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#方法一-加拿大曲线救国-成功几率最大最可靠"}},[t._v("#")]),t._v(" 方法一 加拿大曲线救国(成功几率最大最可靠)")]),t._v(" "),r("ul",[r("li",[t._v("先申请加拿大CS的硕士或博士(单纯为了润不建议读博士),毕业后拿枫叶卡同时进一个互联网公司,之后拿L1工签南下去美国,美国的互联网大厂基本都在加拿大有分部,所以机会不少,但工资相对低一些,但也比缅甸生活的舒服。")]),t._v(" "),r("li",[t._v("加拿大拿卡相对美国容易得多,第一种常见的方法是走"),r("a",{attrs:{href:"https://archive.ph/J9EOY",target:"_blank",rel:"noopener noreferrer"}},[t._v("EE"),r("OutboundLink")],1),t._v("(Express Entry)通道,"),r("a",{attrs:{href:"https://www.cic.gc.ca/english/immigrate/skilled/crs-tool.asp",target:"_blank",rel:"noopener noreferrer"}},[t._v("打分制"),r("OutboundLink")],1),t._v(",包括年龄,学历,雅思成绩等等,到达这个门槛就可以获得省提名,近几年的最低门槛是450-470左右。")]),t._v(" "),r("li",[t._v("第二种方法是申请BC省(不列颠哥伦比亚省)学校的硕士或者博士,毕业后可以直接拿到省提名,拿到省提名大概半年后就可以拿到枫叶卡。学校名单点击"),r("a",{attrs:{href:"https://www.welcomebc.ca/Immigrate-to-B-C/documents/BC-PNP-IPG-EEBC-IPG-Eligible-Programs-of-Study.aspx",target:"_blank",rel:"noopener noreferrer"}},[t._v("这里"),r("OutboundLink")],1),t._v("。")]),t._v(" "),r("li",[t._v("加拿大读硕士大概一年半左右,总共需要约20-30wRMB。")]),t._v(" "),r("li",[t._v("10043首选加拿大,因为加拿大承接了美国大部分公司的分公司,据我所知温哥华微软和亚马逊一直在常年招人。现在亚马逊这么缺人,加拿大L4开出的总包也有160k加币了,虽然是比美国低一点,但是升职上去了有250k加币也不低了啊。而且相比美国,加拿大枫叶卡获取难度极低,等于白送。加拿大的妹子又多,温哥华中餐又好,比你去湾区卷不是好很多吗?")])]),t._v(" "),r("h2",{attrs:{id:"方法二-找外企工作transfer去美国"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#方法二-找外企工作transfer去美国"}},[t._v("#")]),t._v(" 方法二 找外企工作transfer去美国")]),t._v(" "),r("ul",[r("li",[t._v("卷进国内外企,如微软,Amazon,Google,内部转岗去美国,难度较大,不够可靠。")]),t._v(" "),r("li",[t._v("直接面外国大厂,例如新加坡、欧洲或者加拿大的Amazon,Google等(美国本土基本没机会)。\n如果有能力或者有一定工作经验,可以打磨好自己的LinkedIn,\n去找猎头聊天或者等猎头找你,约面试,面试过了之后拿L1签证去新加坡、欧洲或加拿大,最后再润去美国。")]),t._v(" "),r("li",[t._v("适用于有一定工作经验且英语好的人,也有点运气成分在里面。")])]),t._v(" "),r("h2",{attrs:{id:"方法三-新加坡、欧洲曲线救国"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#方法三-新加坡、欧洲曲线救国"}},[t._v("#")]),t._v(" 方法三 新加坡、欧洲曲线救国")]),t._v(" "),r("ul",[r("li",[t._v("类似于去加拿大读书,也可以去欧洲或者新加坡读书拿身份,再润去美国,\n但这些国家的移民政策的相对于加拿大来说条件太多,例如新加坡可能需要5年才能拿到卡,欧洲也差不多,时间成本太高,不太建议。")])]),t._v(" "),r("h2",{attrs:{id:"方法四-美国交换"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#方法四-美国交换"}},[t._v("#")]),t._v(" 方法四 美国交换")]),t._v(" "),r("ul",[r("li",[t._v("10043学校如哈工大有UCI 3+1+1项目,其中第一年挂在教育学院下并且只是本科交换,卡签概率比较小,入境后可正常留在UCI读完3+2或在3+1后申请其他美国学校,UCI的3+2项目可行性已确认,别的学期交换理论上也是可行,可以一试。")])]),t._v(" "),r("h2",{attrs:{id:"方法五-境内转身份"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#方法五-境内转身份"}},[t._v("#")]),t._v(" 方法五 境内转身份")]),t._v(" "),r("ul",[r("li",[t._v("亲测10043学校毕业生可以正常申请B签,但是无法申请F类、J类签证。可以先去大使馆"),r("a",{attrs:{href:"./0_visa"}},[t._v("申请B签")]),t._v("入境;")]),t._v(" "),r("li",[t._v("入境后向移民局申请转F类或者J类签证,亲测USCIS并不care10043;")]),t._v(" "),r("li",[t._v("申请F2、J2的通过率很高,但是F1、J1的通过率较低,会被质疑入境目的不纯;")]),t._v(" "),r("li",[t._v("转身份仅限境内有效,一旦出境,就需要再去大使馆重新申请签证。")])])])}),[],!1,null,null,null);r.default=s.exports}}]); \ No newline at end of file diff --git a/assets/js/132.685c3342.js b/assets/js/132.99483200.js similarity index 97% rename from assets/js/132.685c3342.js rename to assets/js/132.99483200.js index 04ff0ce7d2..d0cec6acd3 100644 --- a/assets/js/132.685c3342.js +++ b/assets/js/132.99483200.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[132],{573:function(v,_,t){"use strict";t.r(_);var p=t(30),a=Object(p.a)({},(function(){var v=this,_=v._self._c;return _("ContentSlotsDistributor",{attrs:{"slot-key":v.$parent.slotKey}},[_("h1",{attrs:{id:"黑下来的印度老哥"}},[_("a",{staticClass:"header-anchor",attrs:{href:"#黑下来的印度老哥"}},[v._v("#")]),v._v(" 黑下来的印度老哥")]),v._v(" "),_("p",[_("font",{attrs:{color:"gray"}},[v._v("Last updated on 2023-07-17")])],1),v._v(" "),_("p",[v._v("今天去沃尔玛买菜,顺便去印度餐厅打包一个咖喱山羊肉。")]),v._v(" "),_("p",[v._v("坐着等餐的时候和前台的印度小哥聊起来,他说他已经来美国38个月了。")]),v._v(" "),_("p",[v._v("我问他怎么拿到visa的?")]),v._v(" "),_("p",[v._v("他说就是非法滞留在这边,签证已经过期了。")]),v._v(" "),_("p",[v._v("我又问他一个月挣多少钱?")]),v._v(" "),_("p",[v._v("他说从早上十点到晚上十一点,一个月3500刀。但是如果去那种按小时pay的地方工资会更高。")]),v._v(" "),_("p",[v._v("打算一直就在这边吗?")]),v._v(" "),_("p",[v._v("没有,就是挣点钱就回去了。")]),v._v(" "),_("hr"),v._v(" "),_("p",[v._v("3500刀算是这边的平均工资,只不过打黑工没有交社保,时间也会被压榨,也没法办驾照,没法出境。但是仍然有很多很多人愿意黑下来。")]),v._v(" "),_("p",[v._v("有的人黑下来是为了挣美元,也有人为了孩子的身份。")]),v._v(" "),_("p",[v._v("挣美元、拿绿卡是挺好的,但是阶级降落也是很明显的。")]),v._v(" "),_("p",[v._v("在国内做白领,甚至躺平退休了,来美国只能做蓝领,炒盒饭、做服务员。")]),v._v(" "),_("p",[v._v("在国内可以过中产阶级的生活,来美国啥都乘以七,啥都觉得贵。")]),v._v(" "),_("p",[v._v("我还是觉得为了身份(不管是北京户口还是绿卡)而放弃自由和生活品质,也是一种执念。")]),v._v(" "),_("p",[v._v("宇宙套利指南,是要自由,而且挣美元。")])])}),[],!1,null,null,null);_.default=a.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[132],{578:function(v,_,t){"use strict";t.r(_);var p=t(30),a=Object(p.a)({},(function(){var v=this,_=v._self._c;return _("ContentSlotsDistributor",{attrs:{"slot-key":v.$parent.slotKey}},[_("h1",{attrs:{id:"黑下来的印度老哥"}},[_("a",{staticClass:"header-anchor",attrs:{href:"#黑下来的印度老哥"}},[v._v("#")]),v._v(" 黑下来的印度老哥")]),v._v(" "),_("p",[_("font",{attrs:{color:"gray"}},[v._v("Last updated on 2023-07-17")])],1),v._v(" "),_("p",[v._v("今天去沃尔玛买菜,顺便去印度餐厅打包一个咖喱山羊肉。")]),v._v(" "),_("p",[v._v("坐着等餐的时候和前台的印度小哥聊起来,他说他已经来美国38个月了。")]),v._v(" "),_("p",[v._v("我问他怎么拿到visa的?")]),v._v(" "),_("p",[v._v("他说就是非法滞留在这边,签证已经过期了。")]),v._v(" "),_("p",[v._v("我又问他一个月挣多少钱?")]),v._v(" "),_("p",[v._v("他说从早上十点到晚上十一点,一个月3500刀。但是如果去那种按小时pay的地方工资会更高。")]),v._v(" "),_("p",[v._v("打算一直就在这边吗?")]),v._v(" "),_("p",[v._v("没有,就是挣点钱就回去了。")]),v._v(" "),_("hr"),v._v(" "),_("p",[v._v("3500刀算是这边的平均工资,只不过打黑工没有交社保,时间也会被压榨,也没法办驾照,没法出境。但是仍然有很多很多人愿意黑下来。")]),v._v(" "),_("p",[v._v("有的人黑下来是为了挣美元,也有人为了孩子的身份。")]),v._v(" "),_("p",[v._v("挣美元、拿绿卡是挺好的,但是阶级降落也是很明显的。")]),v._v(" "),_("p",[v._v("在国内做白领,甚至躺平退休了,来美国只能做蓝领,炒盒饭、做服务员。")]),v._v(" "),_("p",[v._v("在国内可以过中产阶级的生活,来美国啥都乘以七,啥都觉得贵。")]),v._v(" "),_("p",[v._v("我还是觉得为了身份(不管是北京户口还是绿卡)而放弃自由和生活品质,也是一种执念。")]),v._v(" "),_("p",[v._v("宇宙套利指南,是要自由,而且挣美元。")])])}),[],!1,null,null,null);_.default=a.exports}}]); \ No newline at end of file diff --git a/assets/js/137.d41b0742.js b/assets/js/137.57a96f72.js similarity index 88% rename from assets/js/137.d41b0742.js rename to assets/js/137.57a96f72.js index 5567988b1e..f72635f2fd 100644 --- a/assets/js/137.d41b0742.js +++ b/assets/js/137.57a96f72.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[137],{574:function(t,s,a){"use strict";a.r(s);var r=a(30),n=Object(r.a)({},(function(){var t=this._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":this.$parent.slotKey}},[t("h1",{attrs:{id:"什么人适合润到美国"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#什么人适合润到美国"}},[this._v("#")]),this._v(" 什么人适合润到美国")]),this._v(" "),t("p",[t("font",{attrs:{color:"gray"}},[this._v("Last updated on 2023-10-28")])],1)])}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[137],{573:function(t,s,a){"use strict";a.r(s);var r=a(30),n=Object(r.a)({},(function(){var t=this._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":this.$parent.slotKey}},[t("h1",{attrs:{id:"什么人适合润到美国"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#什么人适合润到美国"}},[this._v("#")]),this._v(" 什么人适合润到美国")]),this._v(" "),t("p",[t("font",{attrs:{color:"gray"}},[this._v("Last updated on 2023-10-28")])],1)])}),[],!1,null,null,null);s.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/138.d691c767.js b/assets/js/138.2a52cce3.js similarity index 99% rename from assets/js/138.d691c767.js rename to assets/js/138.2a52cce3.js index 8e59fb9204..224d260184 100644 --- a/assets/js/138.d691c767.js +++ b/assets/js/138.2a52cce3.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[138],{576:function(e,v,i){"use strict";i.r(v);var a=i(30),t=Object(a.a)({},(function(){var e=this,v=e._self._c;return v("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[v("h1",{attrs:{id:"如何拿到美国十年b签"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#如何拿到美国十年b签"}},[e._v("#")]),e._v(" 如何拿到美国十年B签")]),e._v(" "),v("p",[v("font",{attrs:{color:"gray"}},[e._v("Last updated on 2022-01-01")])],1),e._v(" "),v("p",[e._v("美国大使馆由于疫情关闭了大半年,2021年11月,在美国大使馆刚刚重新开放预约的时候,我第一时间预约了面签。\n这是我的时间线:")]),e._v(" "),v("ul",[v("li",[e._v("12.13:北京面签B2,通过;")]),e._v(" "),v("li",[e._v("12.14:Issued;")]),e._v(" "),v("li",[e._v("12.16:到中信银行领取护照,给了十年。")])]),e._v(" "),v("h2",{attrs:{id:"ds160"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#ds160"}},[e._v("#")]),e._v(" DS160")]),e._v(" "),v("p",[e._v("我的DS160是自己填的,没找中介,网上有很多手把手教程,这里就不细表了,主要讲一下面签的经验。")]),e._v(" "),v("h2",{attrs:{id:"面签"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#面签"}},[e._v("#")]),e._v(" 面签")]),e._v(" "),v("h4",{attrs:{id:"材料"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#材料"}},[e._v("#")]),e._v(" 材料")]),e._v(" "),v("ul",[v("li",[e._v("材料要准备充分,下面会列出我的材料清单;")]),e._v(" "),v("li",[e._v("照片可以用ppt做成一页4-5张的排版,标注好时间、地点、人物,彩色打印下来,带玻璃相框的照片不让带进去;")]),e._v(" "),v("li",[e._v("去照相馆拍一张近照带着,我ds160上提交的照片是两年前的,面签前一天去重拍了,登记护照信息的时候主动递进去,给我换成了近照;")]),e._v(" "),v("li",[e._v("把所有材料贴好标签,分类整理好,面签开始前一堆一堆的摆好,问哪方面的问题就把一摞都递进去;")]),e._v(" "),v("li",[e._v("回答问题时"),v("strong",[e._v("尽量主动给面签官一些相关的材料")]),e._v("。")])]),e._v(" "),v("h4",{attrs:{id:"面试"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#面试"}},[e._v("#")]),e._v(" 面试")]),e._v(" "),v("ol",[v("li",[e._v("小红书上有非常多面签经验分享,我把和自己情况差不多的面签问题整理出来,做成了题集;")]),e._v(" "),v("li",[e._v("仔细琢磨应该如何回答每一个问题,回答问题的原则是:真实、证明自己的回国约束力;")]),e._v(" "),v("li",[e._v("将整理出的题集问题和回答,都翻译成英文,打印出来朗读背诵(最终被问到的问题都没有超出题集的范围)")]),e._v(" "),v("li",[e._v("找人用英文模拟面试,把题集里面问题多过几遍,做到每个问题都可以流利地回答。")])]),e._v(" "),v("h2",{attrs:{id:"材料清单"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#材料清单"}},[e._v("#")]),e._v(" 材料清单")]),e._v(" "),v("h4",{attrs:{id:"邀请人相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#邀请人相关"}},[e._v("#")]),e._v(" 邀请人相关")]),e._v(" "),v("ol",[v("li",[e._v("邀请信和邀请人信息")]),e._v(" "),v("li",[e._v("驾驶证")]),e._v(" "),v("li",[e._v("护照")]),e._v(" "),v("li",[e._v("签证页")]),e._v(" "),v("li",[e._v("SSN")]),e._v(" "),v("li",[e._v("工资单")]),e._v(" "),v("li",[e._v("简历")]),e._v(" "),v("li",[e._v("合影")])]),e._v(" "),v("h4",{attrs:{id:"工作方面"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#工作方面"}},[e._v("#")]),e._v(" 工作方面")]),e._v(" "),v("ol",[v("li",[e._v("在职证明")]),e._v(" "),v("li",[e._v("公司营业执照")]),e._v(" "),v("li",[e._v("居住证明")]),e._v(" "),v("li",[e._v("简历")])]),e._v(" "),v("h4",{attrs:{id:"财产证明"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#财产证明"}},[e._v("#")]),e._v(" 财产证明")]),e._v(" "),v("ol",[v("li",[e._v("工资证明")]),e._v(" "),v("li",[e._v("股票证明")]),e._v(" "),v("li",[e._v("银行活期证明")]),e._v(" "),v("li",[e._v("房产证")]),e._v(" "),v("li",[e._v("银行流水")])]),e._v(" "),v("h4",{attrs:{id:"旅行计划方面"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#旅行计划方面"}},[e._v("#")]),e._v(" 旅行计划方面")]),e._v(" "),v("ol",[v("li",[e._v("旅行计划")])]),e._v(" "),v("h4",{attrs:{id:"父母相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#父母相关"}},[e._v("#")]),e._v(" 父母相关")]),e._v(" "),v("ol",[v("li",[e._v("一家人合影")]),e._v(" "),v("li",[e._v("父母工作证明")]),e._v(" "),v("li",[e._v("父母房产证")]),e._v(" "),v("li",[e._v("父母身份证复印件")])]),e._v(" "),v("h4",{attrs:{id:"个人资料"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#个人资料"}},[e._v("#")]),e._v(" 个人资料")]),e._v(" "),v("ol",[v("li",[e._v("学历证、毕业证")]),e._v(" "),v("li",[e._v("户口首页、个人页")]),e._v(" "),v("li",[e._v("护照")]),e._v(" "),v("li",[e._v("身份证原件")]),e._v(" "),v("li",[e._v("DS160 confirmation")]),e._v(" "),v("li",[e._v("DS160 Payment")]),e._v(" "),v("li",[e._v("面签预约单")]),e._v(" "),v("li",[e._v("旅行计划")]),e._v(" "),v("li",[e._v("预定机票信息,付款前订单页面")]),e._v(" "),v("li",[e._v("当场自助照相,10刀cash")]),e._v(" "),v("li",[e._v("证件照 * 2")]),e._v(" "),v("li",[e._v("疫苗接种证明(中英文)")])]),e._v(" "),v("h2",{attrs:{id:"被问的问题"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#被问的问题"}},[e._v("#")]),e._v(" 被问的问题")]),e._v(" "),v("p",[e._v("(全程英文)")]),e._v(" "),v("h4",{attrs:{id:"行程相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#行程相关"}},[e._v("#")]),e._v(" 行程相关")]),e._v(" "),v("ul",[v("li",[e._v("你去美国干嘛?Why are you going to the USA?\n"),v("ul",[v("li",[e._v("春节期间去看朋友+旅行(递了朋友的所有资料,收了)")])])]),e._v(" "),v("li",[e._v("去美国哪里? Where do you plan to go?\n"),v("ul",[v("li",[e._v("按旅行计划说")])])]),e._v(" "),v("li",[e._v("去几天?计划在美国待多久?\n"),v("ul",[v("li",[e._v("xx天")])])]),e._v(" "),v("li",[e._v("去过哪些国家?What other countries have you been to (visited)?\n"),v("ul",[v("li",[e._v("xx")])])]),e._v(" "),v("li",[e._v("你知道疫情回来要隔离多久吗?")]),e._v(" "),v("li",[e._v("Do you know how long it takes to quarantine?\n"),v("ul",[v("li",[e._v("3周,我远程工作")])])]),e._v(" "),v("li",[e._v("你之前去过美国吗?Have you been to the US before?\n"),v("ul",[v("li",[e._v("xx")])])])]),e._v(" "),v("h4",{attrs:{id:"工作相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#工作相关"}},[e._v("#")]),e._v(" 工作相关")]),e._v(" "),v("ul",[v("li",[e._v("你的工作是什么?What's your job? What do you do for a living?\n"),v("ul",[v("li",[e._v("递工作证明等,没有要")])])]),e._v(" "),v("li",[e._v("你工作多久了?How long have you worked?")]),e._v(" "),v("li",[e._v("你工作的具体内容?tell me about your job.(眼睛直勾勾的对视)")])]),e._v(" "),v("h4",{attrs:{id:"朋友相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#朋友相关"}},[e._v("#")]),e._v(" 朋友相关")]),e._v(" "),v("ul",[v("li",[e._v("你朋友住在哪里?Where does he live?\n"),v("ul",[v("li",[e._v("主动说了城市,工作")])])]),e._v(" "),v("li",[e._v("你们怎么认识的?How did you meet?")]),e._v(" "),v("li",[e._v("追问了一下,你们是什么时候认识的?")]),e._v(" "),v("li",[e._v("你朋友在现在的城市多久了?在美国多久了?How long has your friend been in the US?\n"),v("ul",[v("li",[e._v("(翻看了朋友资料,看了护照、邀请信、旅行计划、合影,剩下的没看了)")])])])]),e._v(" "),v("h4",{attrs:{id:"个人信息相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#个人信息相关"}},[e._v("#")]),e._v(" 个人信息相关")]),e._v(" "),v("ul",[v("li",[e._v("最高学历是什么?What's your degree (education)?\n"),v("ul",[v("li",[e._v("递学位证明等,没有要")])])])]),e._v(" "),v("ul",[v("li",[e._v("你收入多少?How much do you earn (make) each month?\n"),v("ul",[v("li",[e._v("递银行证明等,没有要")])])])]),e._v(" "),v("h2",{attrs:{id:"面签题集"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#面签题集"}},[e._v("#")]),e._v(" 面签题集")]),e._v(" "),v("h4",{attrs:{id:"行程相关-2"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#行程相关-2"}},[e._v("#")]),e._v(" 行程相关")]),e._v(" "),v("ul",[v("li",[e._v("你去美国干嘛?Why are you applying for the visa? Why are you going to the USA? What do you do in the USA?\n"),v("ul",[v("li",[e._v("I plan to visit my xx during the Chinese spring festival.")])])]),e._v(" "),v("li",[e._v("去美国哪里? Where do you plan to go (travel/visit)?\n"),v("ul",[v("li",[e._v("xx (Here's my travel plan)")])])]),e._v(" "),v("li",[e._v("Why do you want to visit xx city?")]),e._v(" "),v("li",[e._v("去几天?计划在美国待多久?")]),e._v(" "),v("li",[e._v("准备什么时候去?")]),e._v(" "),v("li",[e._v("为什么现在去?")]),e._v(" "),v("li",[e._v("去过哪些国家?What other countries have you been to (visited)?\n"),v("ul",[v("li",[e._v("xx countries")])])]),e._v(" "),v("li",[e._v("疫情回来隔离这么久你怎么办?Do you have enough time to quarantine?\n"),v("ul",[v("li",[e._v("I got the approval to work remotely during the quarantine.")])])]),e._v(" "),v("li",[e._v("打算在美国住哪?\n"),v("ul",[v("li",[e._v("My friend's home in xx and some hotels. here is my travel plan.")])])]),e._v(" "),v("li",[e._v("你一个人去美国吗?Will you be traveling alone? Is there someone you travel with?\n"),v("ul",[v("li",[e._v("Yes. here is my travel plan.")])])]),e._v(" "),v("li",[e._v("你之前去过美国吗?Have you been to the US before?")]),e._v(" "),v("li",[e._v("你有朋友一起去美国吗?Is there someone you travel with?")]),e._v(" "),v("li",[e._v("你有那么多假期去美国吗?Do you have enough vacation (time) to travel to the US?")]),e._v(" "),v("li",[e._v("回国隔离要很久你知道吗?Do you know you have to self-quarantine for a long time?")]),e._v(" "),v("li",[e._v("你有详细的旅行计划吗?Do you have specific travel plans?\n"),v("ul",[v("li",[e._v("Yes here's my travel plan")])])]),e._v(" "),v("li",[e._v("订机票了吗?Have you booked flights?\n"),v("ul",[v("li",[e._v("Not yet, but I will book these flights once I get the visa.")])])]),e._v(" "),v("li",[e._v("买访客医疗保险了吗?Have you purchased visitor insurance?\n"),v("ul",[v("li",[e._v("No, but I will buy soem once I get the visa.")])])])]),e._v(" "),v("h4",{attrs:{id:"工作相关-2"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#工作相关-2"}},[e._v("#")]),e._v(" 工作相关")]),e._v(" "),v("ul",[v("li",[e._v("你的工作是什么?What's your job? What do you do for a living?\n"),v("ul",[v("li",[e._v("I am a xx. here is my employment certification.")])])]),e._v(" "),v("li",[e._v("你工作多久了?How long have you worked?\n"),v("ul",[v("li",[e._v("xx years.here is my employment certification.")])])]),e._v(" "),v("li",[e._v("你收入多少?年收入多少?How much do you earn (make) each year?\n"),v("ul",[v("li",[e._v("I make xx dollars after tax")])])]),e._v(" "),v("li",[e._v("你收入多少?月收入多少?How much do you earn (make) each month?\n"),v("ul",[v("li",[e._v("I make xx dollars after tax")])])]),e._v(" "),v("li",[e._v("你在这家公司几年了?How long have you worked here?\n"),v("ul",[v("li",[e._v("xx years.here is my employment certification.")])])]),e._v(" "),v("li",[e._v("你访问美国期间,你的工作谁来负责?Who will take care (do your work for you) your work during your visit?\n"),v("ul",[v("li",[e._v("myself.")])])]),e._v(" "),v("li",[e._v("你会在美国工作吗?做生意吗?\n"),v("ul",[v("li",[e._v("No. I will go back to China and continue to work at China.")])])]),e._v(" "),v("li",[e._v("你的职级?What's your job title?")]),e._v(" "),v("li",[e._v("你的工作?What's your specific job in the company? what do you do in the company?")])]),e._v(" "),v("h4",{attrs:{id:"个人信息相关-2"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#个人信息相关-2"}},[e._v("#")]),e._v(" 个人信息相关")]),e._v(" "),v("ul",[v("li",[e._v("最高学历是什么?What's your highest degree (education)?\n"),v("ul",[v("li",[e._v("I received my xx degree from xx")])])]),e._v(" "),v("li",[e._v("Where did you go to college? What city?")]),e._v(" "),v("li",[e._v("What university did you go to for college?")]),e._v(" "),v("li",[e._v("你住在哪里?Where do you live?\n"),v("ul",[v("li",[e._v("I live in xx. here is my address certification.")])])]),e._v(" "),v("li",[e._v("What's your major?\n"),v("ul",[v("li",[e._v("xx for undergrad, and xx for graduate study.here is my diploma.")])])]),e._v(" "),v("li",[e._v("你打疫苗了吗?have you received your covid vaccine? are you full vaccinated?\n"),v("ul",[v("li",[e._v("yes, I received three doses of covid vaccine. (here is my covid caccine cetifitation.)")])])])]),e._v(" "),v("h4",{attrs:{id:"朋友相关-2"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#朋友相关-2"}},[e._v("#")]),e._v(" 朋友相关")]),e._v(" "),v("ul",[v("li",[e._v("你在美国有亲人吗?Do you have any relatives (family member) in US?\n"),v("ul",[v("li",[e._v("xx.here is their infomation.")])])]),e._v(" "),v("li",[e._v("你结婚了吗?Are you married or single?")]),e._v(" "),v("li",[e._v("你有小孩吗?Do you have children?")]),e._v(" "),v("li",[e._v("你会去美国结婚吗?Will you get marrried in the US?")]),e._v(" "),v("li",[e._v("你朋友做什么?What do your friend do?\n"),v("ul",[v("li",[e._v("He's a xx (Here's his information)")])])]),e._v(" "),v("li",[e._v("他是美国公民吗?Is he a US citizen?\n"),v("ul",[v("li",[e._v("xx (Here's his information)")])])]),e._v(" "),v("li",[e._v("你知道你朋友的联系方式吗?Do you have the contact information of him?\n"),v("ul",[v("li",[e._v("Yes, here's his address (maybe show the invitation letter)")])])]),e._v(" "),v("li",[e._v("你朋友住在哪里?Where does he live?\n"),v("ul",[v("li",[e._v("He lives in xx, here's his address.(Show some paper that has the address)")])])]),e._v(" "),v("li",[e._v("离你上次见到你朋友有多久了?How long have you last seen each other? When was the last time you saw each other?\n"),v("ul",[v("li",[e._v("xx years.(here is owr photos.)")])])]),e._v(" "),v("li",[e._v("你们怎么认识的?How did you meet? know each other?\n"),v("ul",[v("li",[e._v("We xx.(here is owr photos.)")])])]),e._v(" "),v("li",[e._v("你们认识多久了?How long have you know each other?\n"),v("ul",[v("li",[e._v("xx years(here is owr photos.)")])])]),e._v(" "),v("li",[e._v("你朋友在美国多久了?How long has your friend been in the US?\n"),v("ul",[v("li",[e._v("xx years, since xx.(here is his infomation and visa.)")])])]),e._v(" "),v("li",[e._v("每年挣多少钱?How much does he make anually?\n"),v("ul",[v("li",[e._v("xx dollars.(here is his infomation)")])])])]),e._v(" "),v("h4",{attrs:{id:"家庭相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#家庭相关"}},[e._v("#")]),e._v(" 家庭相关")]),e._v(" "),v("ul",[v("li",[e._v("你家人知道你去美国吗? Does your family know you are applying the visa?\n"),v("ul",[v("li",[e._v("Yes they are very supportive of me.")])])]),e._v(" "),v("li",[e._v("你爸爸叫什么名?What is the name of you father?\n"),v("ul",[v("li",[e._v("xx. (Here's his info)")])])]),e._v(" "),v("li",[e._v("你父母是做什么工作的?What do your parents do? What are your parents' job? What do they do for a living?\n"),v("ul",[v("li",[e._v("They are xx. (Here's their information)")])])]),e._v(" "),v("li",[e._v("你父母退休了吗?Are they retired?")]),e._v(" "),v("li",[e._v("你父母多少岁了?How old are they?")]),e._v(" "),v("li",[e._v("你在国内有什么家人?Do you have any family members?")])]),e._v(" "),v("h4",{attrs:{id:"资产相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#资产相关"}},[e._v("#")]),e._v(" 资产相关")]),e._v(" "),v("ul",[v("li",[e._v("预计这次旅行要花多少钱?How much does this travel take? How much did you prepare for this travel?\n"),v("ul",[v("li",[e._v("I prepare xx dollars for the travel. here's my bank account information.")])])]),e._v(" "),v("li",[e._v("谁付钱?Who will pay this travel?Who sponsors this travel?\n"),v("ul",[v("li",[e._v("Myself. I prepare xx dollars for the travel. here's my bank account information.")])])]),e._v(" "),v("li",[e._v("你有房子吗?Do you own any house/property/real estate?")]),e._v(" "),v("li",[e._v("你有信用卡吗?Do you have any credit cards?")]),e._v(" "),v("li",[e._v("你有些什么财产?What properties do you own?")])])])}),[],!1,null,null,null);v.default=t.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[138],{574:function(e,v,i){"use strict";i.r(v);var a=i(30),t=Object(a.a)({},(function(){var e=this,v=e._self._c;return v("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[v("h1",{attrs:{id:"如何拿到美国十年b签"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#如何拿到美国十年b签"}},[e._v("#")]),e._v(" 如何拿到美国十年B签")]),e._v(" "),v("p",[v("font",{attrs:{color:"gray"}},[e._v("Last updated on 2022-01-01")])],1),e._v(" "),v("p",[e._v("美国大使馆由于疫情关闭了大半年,2021年11月,在美国大使馆刚刚重新开放预约的时候,我第一时间预约了面签。\n这是我的时间线:")]),e._v(" "),v("ul",[v("li",[e._v("12.13:北京面签B2,通过;")]),e._v(" "),v("li",[e._v("12.14:Issued;")]),e._v(" "),v("li",[e._v("12.16:到中信银行领取护照,给了十年。")])]),e._v(" "),v("h2",{attrs:{id:"ds160"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#ds160"}},[e._v("#")]),e._v(" DS160")]),e._v(" "),v("p",[e._v("我的DS160是自己填的,没找中介,网上有很多手把手教程,这里就不细表了,主要讲一下面签的经验。")]),e._v(" "),v("h2",{attrs:{id:"面签"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#面签"}},[e._v("#")]),e._v(" 面签")]),e._v(" "),v("h4",{attrs:{id:"材料"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#材料"}},[e._v("#")]),e._v(" 材料")]),e._v(" "),v("ul",[v("li",[e._v("材料要准备充分,下面会列出我的材料清单;")]),e._v(" "),v("li",[e._v("照片可以用ppt做成一页4-5张的排版,标注好时间、地点、人物,彩色打印下来,带玻璃相框的照片不让带进去;")]),e._v(" "),v("li",[e._v("去照相馆拍一张近照带着,我ds160上提交的照片是两年前的,面签前一天去重拍了,登记护照信息的时候主动递进去,给我换成了近照;")]),e._v(" "),v("li",[e._v("把所有材料贴好标签,分类整理好,面签开始前一堆一堆的摆好,问哪方面的问题就把一摞都递进去;")]),e._v(" "),v("li",[e._v("回答问题时"),v("strong",[e._v("尽量主动给面签官一些相关的材料")]),e._v("。")])]),e._v(" "),v("h4",{attrs:{id:"面试"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#面试"}},[e._v("#")]),e._v(" 面试")]),e._v(" "),v("ol",[v("li",[e._v("小红书上有非常多面签经验分享,我把和自己情况差不多的面签问题整理出来,做成了题集;")]),e._v(" "),v("li",[e._v("仔细琢磨应该如何回答每一个问题,回答问题的原则是:真实、证明自己的回国约束力;")]),e._v(" "),v("li",[e._v("将整理出的题集问题和回答,都翻译成英文,打印出来朗读背诵(最终被问到的问题都没有超出题集的范围)")]),e._v(" "),v("li",[e._v("找人用英文模拟面试,把题集里面问题多过几遍,做到每个问题都可以流利地回答。")])]),e._v(" "),v("h2",{attrs:{id:"材料清单"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#材料清单"}},[e._v("#")]),e._v(" 材料清单")]),e._v(" "),v("h4",{attrs:{id:"邀请人相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#邀请人相关"}},[e._v("#")]),e._v(" 邀请人相关")]),e._v(" "),v("ol",[v("li",[e._v("邀请信和邀请人信息")]),e._v(" "),v("li",[e._v("驾驶证")]),e._v(" "),v("li",[e._v("护照")]),e._v(" "),v("li",[e._v("签证页")]),e._v(" "),v("li",[e._v("SSN")]),e._v(" "),v("li",[e._v("工资单")]),e._v(" "),v("li",[e._v("简历")]),e._v(" "),v("li",[e._v("合影")])]),e._v(" "),v("h4",{attrs:{id:"工作方面"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#工作方面"}},[e._v("#")]),e._v(" 工作方面")]),e._v(" "),v("ol",[v("li",[e._v("在职证明")]),e._v(" "),v("li",[e._v("公司营业执照")]),e._v(" "),v("li",[e._v("居住证明")]),e._v(" "),v("li",[e._v("简历")])]),e._v(" "),v("h4",{attrs:{id:"财产证明"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#财产证明"}},[e._v("#")]),e._v(" 财产证明")]),e._v(" "),v("ol",[v("li",[e._v("工资证明")]),e._v(" "),v("li",[e._v("股票证明")]),e._v(" "),v("li",[e._v("银行活期证明")]),e._v(" "),v("li",[e._v("房产证")]),e._v(" "),v("li",[e._v("银行流水")])]),e._v(" "),v("h4",{attrs:{id:"旅行计划方面"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#旅行计划方面"}},[e._v("#")]),e._v(" 旅行计划方面")]),e._v(" "),v("ol",[v("li",[e._v("旅行计划")])]),e._v(" "),v("h4",{attrs:{id:"父母相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#父母相关"}},[e._v("#")]),e._v(" 父母相关")]),e._v(" "),v("ol",[v("li",[e._v("一家人合影")]),e._v(" "),v("li",[e._v("父母工作证明")]),e._v(" "),v("li",[e._v("父母房产证")]),e._v(" "),v("li",[e._v("父母身份证复印件")])]),e._v(" "),v("h4",{attrs:{id:"个人资料"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#个人资料"}},[e._v("#")]),e._v(" 个人资料")]),e._v(" "),v("ol",[v("li",[e._v("学历证、毕业证")]),e._v(" "),v("li",[e._v("户口首页、个人页")]),e._v(" "),v("li",[e._v("护照")]),e._v(" "),v("li",[e._v("身份证原件")]),e._v(" "),v("li",[e._v("DS160 confirmation")]),e._v(" "),v("li",[e._v("DS160 Payment")]),e._v(" "),v("li",[e._v("面签预约单")]),e._v(" "),v("li",[e._v("旅行计划")]),e._v(" "),v("li",[e._v("预定机票信息,付款前订单页面")]),e._v(" "),v("li",[e._v("当场自助照相,10刀cash")]),e._v(" "),v("li",[e._v("证件照 * 2")]),e._v(" "),v("li",[e._v("疫苗接种证明(中英文)")])]),e._v(" "),v("h2",{attrs:{id:"被问的问题"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#被问的问题"}},[e._v("#")]),e._v(" 被问的问题")]),e._v(" "),v("p",[e._v("(全程英文)")]),e._v(" "),v("h4",{attrs:{id:"行程相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#行程相关"}},[e._v("#")]),e._v(" 行程相关")]),e._v(" "),v("ul",[v("li",[e._v("你去美国干嘛?Why are you going to the USA?\n"),v("ul",[v("li",[e._v("春节期间去看朋友+旅行(递了朋友的所有资料,收了)")])])]),e._v(" "),v("li",[e._v("去美国哪里? Where do you plan to go?\n"),v("ul",[v("li",[e._v("按旅行计划说")])])]),e._v(" "),v("li",[e._v("去几天?计划在美国待多久?\n"),v("ul",[v("li",[e._v("xx天")])])]),e._v(" "),v("li",[e._v("去过哪些国家?What other countries have you been to (visited)?\n"),v("ul",[v("li",[e._v("xx")])])]),e._v(" "),v("li",[e._v("你知道疫情回来要隔离多久吗?")]),e._v(" "),v("li",[e._v("Do you know how long it takes to quarantine?\n"),v("ul",[v("li",[e._v("3周,我远程工作")])])]),e._v(" "),v("li",[e._v("你之前去过美国吗?Have you been to the US before?\n"),v("ul",[v("li",[e._v("xx")])])])]),e._v(" "),v("h4",{attrs:{id:"工作相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#工作相关"}},[e._v("#")]),e._v(" 工作相关")]),e._v(" "),v("ul",[v("li",[e._v("你的工作是什么?What's your job? What do you do for a living?\n"),v("ul",[v("li",[e._v("递工作证明等,没有要")])])]),e._v(" "),v("li",[e._v("你工作多久了?How long have you worked?")]),e._v(" "),v("li",[e._v("你工作的具体内容?tell me about your job.(眼睛直勾勾的对视)")])]),e._v(" "),v("h4",{attrs:{id:"朋友相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#朋友相关"}},[e._v("#")]),e._v(" 朋友相关")]),e._v(" "),v("ul",[v("li",[e._v("你朋友住在哪里?Where does he live?\n"),v("ul",[v("li",[e._v("主动说了城市,工作")])])]),e._v(" "),v("li",[e._v("你们怎么认识的?How did you meet?")]),e._v(" "),v("li",[e._v("追问了一下,你们是什么时候认识的?")]),e._v(" "),v("li",[e._v("你朋友在现在的城市多久了?在美国多久了?How long has your friend been in the US?\n"),v("ul",[v("li",[e._v("(翻看了朋友资料,看了护照、邀请信、旅行计划、合影,剩下的没看了)")])])])]),e._v(" "),v("h4",{attrs:{id:"个人信息相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#个人信息相关"}},[e._v("#")]),e._v(" 个人信息相关")]),e._v(" "),v("ul",[v("li",[e._v("最高学历是什么?What's your degree (education)?\n"),v("ul",[v("li",[e._v("递学位证明等,没有要")])])])]),e._v(" "),v("ul",[v("li",[e._v("你收入多少?How much do you earn (make) each month?\n"),v("ul",[v("li",[e._v("递银行证明等,没有要")])])])]),e._v(" "),v("h2",{attrs:{id:"面签题集"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#面签题集"}},[e._v("#")]),e._v(" 面签题集")]),e._v(" "),v("h4",{attrs:{id:"行程相关-2"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#行程相关-2"}},[e._v("#")]),e._v(" 行程相关")]),e._v(" "),v("ul",[v("li",[e._v("你去美国干嘛?Why are you applying for the visa? Why are you going to the USA? What do you do in the USA?\n"),v("ul",[v("li",[e._v("I plan to visit my xx during the Chinese spring festival.")])])]),e._v(" "),v("li",[e._v("去美国哪里? Where do you plan to go (travel/visit)?\n"),v("ul",[v("li",[e._v("xx (Here's my travel plan)")])])]),e._v(" "),v("li",[e._v("Why do you want to visit xx city?")]),e._v(" "),v("li",[e._v("去几天?计划在美国待多久?")]),e._v(" "),v("li",[e._v("准备什么时候去?")]),e._v(" "),v("li",[e._v("为什么现在去?")]),e._v(" "),v("li",[e._v("去过哪些国家?What other countries have you been to (visited)?\n"),v("ul",[v("li",[e._v("xx countries")])])]),e._v(" "),v("li",[e._v("疫情回来隔离这么久你怎么办?Do you have enough time to quarantine?\n"),v("ul",[v("li",[e._v("I got the approval to work remotely during the quarantine.")])])]),e._v(" "),v("li",[e._v("打算在美国住哪?\n"),v("ul",[v("li",[e._v("My friend's home in xx and some hotels. here is my travel plan.")])])]),e._v(" "),v("li",[e._v("你一个人去美国吗?Will you be traveling alone? Is there someone you travel with?\n"),v("ul",[v("li",[e._v("Yes. here is my travel plan.")])])]),e._v(" "),v("li",[e._v("你之前去过美国吗?Have you been to the US before?")]),e._v(" "),v("li",[e._v("你有朋友一起去美国吗?Is there someone you travel with?")]),e._v(" "),v("li",[e._v("你有那么多假期去美国吗?Do you have enough vacation (time) to travel to the US?")]),e._v(" "),v("li",[e._v("回国隔离要很久你知道吗?Do you know you have to self-quarantine for a long time?")]),e._v(" "),v("li",[e._v("你有详细的旅行计划吗?Do you have specific travel plans?\n"),v("ul",[v("li",[e._v("Yes here's my travel plan")])])]),e._v(" "),v("li",[e._v("订机票了吗?Have you booked flights?\n"),v("ul",[v("li",[e._v("Not yet, but I will book these flights once I get the visa.")])])]),e._v(" "),v("li",[e._v("买访客医疗保险了吗?Have you purchased visitor insurance?\n"),v("ul",[v("li",[e._v("No, but I will buy soem once I get the visa.")])])])]),e._v(" "),v("h4",{attrs:{id:"工作相关-2"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#工作相关-2"}},[e._v("#")]),e._v(" 工作相关")]),e._v(" "),v("ul",[v("li",[e._v("你的工作是什么?What's your job? What do you do for a living?\n"),v("ul",[v("li",[e._v("I am a xx. here is my employment certification.")])])]),e._v(" "),v("li",[e._v("你工作多久了?How long have you worked?\n"),v("ul",[v("li",[e._v("xx years.here is my employment certification.")])])]),e._v(" "),v("li",[e._v("你收入多少?年收入多少?How much do you earn (make) each year?\n"),v("ul",[v("li",[e._v("I make xx dollars after tax")])])]),e._v(" "),v("li",[e._v("你收入多少?月收入多少?How much do you earn (make) each month?\n"),v("ul",[v("li",[e._v("I make xx dollars after tax")])])]),e._v(" "),v("li",[e._v("你在这家公司几年了?How long have you worked here?\n"),v("ul",[v("li",[e._v("xx years.here is my employment certification.")])])]),e._v(" "),v("li",[e._v("你访问美国期间,你的工作谁来负责?Who will take care (do your work for you) your work during your visit?\n"),v("ul",[v("li",[e._v("myself.")])])]),e._v(" "),v("li",[e._v("你会在美国工作吗?做生意吗?\n"),v("ul",[v("li",[e._v("No. I will go back to China and continue to work at China.")])])]),e._v(" "),v("li",[e._v("你的职级?What's your job title?")]),e._v(" "),v("li",[e._v("你的工作?What's your specific job in the company? what do you do in the company?")])]),e._v(" "),v("h4",{attrs:{id:"个人信息相关-2"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#个人信息相关-2"}},[e._v("#")]),e._v(" 个人信息相关")]),e._v(" "),v("ul",[v("li",[e._v("最高学历是什么?What's your highest degree (education)?\n"),v("ul",[v("li",[e._v("I received my xx degree from xx")])])]),e._v(" "),v("li",[e._v("Where did you go to college? What city?")]),e._v(" "),v("li",[e._v("What university did you go to for college?")]),e._v(" "),v("li",[e._v("你住在哪里?Where do you live?\n"),v("ul",[v("li",[e._v("I live in xx. here is my address certification.")])])]),e._v(" "),v("li",[e._v("What's your major?\n"),v("ul",[v("li",[e._v("xx for undergrad, and xx for graduate study.here is my diploma.")])])]),e._v(" "),v("li",[e._v("你打疫苗了吗?have you received your covid vaccine? are you full vaccinated?\n"),v("ul",[v("li",[e._v("yes, I received three doses of covid vaccine. (here is my covid caccine cetifitation.)")])])])]),e._v(" "),v("h4",{attrs:{id:"朋友相关-2"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#朋友相关-2"}},[e._v("#")]),e._v(" 朋友相关")]),e._v(" "),v("ul",[v("li",[e._v("你在美国有亲人吗?Do you have any relatives (family member) in US?\n"),v("ul",[v("li",[e._v("xx.here is their infomation.")])])]),e._v(" "),v("li",[e._v("你结婚了吗?Are you married or single?")]),e._v(" "),v("li",[e._v("你有小孩吗?Do you have children?")]),e._v(" "),v("li",[e._v("你会去美国结婚吗?Will you get marrried in the US?")]),e._v(" "),v("li",[e._v("你朋友做什么?What do your friend do?\n"),v("ul",[v("li",[e._v("He's a xx (Here's his information)")])])]),e._v(" "),v("li",[e._v("他是美国公民吗?Is he a US citizen?\n"),v("ul",[v("li",[e._v("xx (Here's his information)")])])]),e._v(" "),v("li",[e._v("你知道你朋友的联系方式吗?Do you have the contact information of him?\n"),v("ul",[v("li",[e._v("Yes, here's his address (maybe show the invitation letter)")])])]),e._v(" "),v("li",[e._v("你朋友住在哪里?Where does he live?\n"),v("ul",[v("li",[e._v("He lives in xx, here's his address.(Show some paper that has the address)")])])]),e._v(" "),v("li",[e._v("离你上次见到你朋友有多久了?How long have you last seen each other? When was the last time you saw each other?\n"),v("ul",[v("li",[e._v("xx years.(here is owr photos.)")])])]),e._v(" "),v("li",[e._v("你们怎么认识的?How did you meet? know each other?\n"),v("ul",[v("li",[e._v("We xx.(here is owr photos.)")])])]),e._v(" "),v("li",[e._v("你们认识多久了?How long have you know each other?\n"),v("ul",[v("li",[e._v("xx years(here is owr photos.)")])])]),e._v(" "),v("li",[e._v("你朋友在美国多久了?How long has your friend been in the US?\n"),v("ul",[v("li",[e._v("xx years, since xx.(here is his infomation and visa.)")])])]),e._v(" "),v("li",[e._v("每年挣多少钱?How much does he make anually?\n"),v("ul",[v("li",[e._v("xx dollars.(here is his infomation)")])])])]),e._v(" "),v("h4",{attrs:{id:"家庭相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#家庭相关"}},[e._v("#")]),e._v(" 家庭相关")]),e._v(" "),v("ul",[v("li",[e._v("你家人知道你去美国吗? Does your family know you are applying the visa?\n"),v("ul",[v("li",[e._v("Yes they are very supportive of me.")])])]),e._v(" "),v("li",[e._v("你爸爸叫什么名?What is the name of you father?\n"),v("ul",[v("li",[e._v("xx. (Here's his info)")])])]),e._v(" "),v("li",[e._v("你父母是做什么工作的?What do your parents do? What are your parents' job? What do they do for a living?\n"),v("ul",[v("li",[e._v("They are xx. (Here's their information)")])])]),e._v(" "),v("li",[e._v("你父母退休了吗?Are they retired?")]),e._v(" "),v("li",[e._v("你父母多少岁了?How old are they?")]),e._v(" "),v("li",[e._v("你在国内有什么家人?Do you have any family members?")])]),e._v(" "),v("h4",{attrs:{id:"资产相关"}},[v("a",{staticClass:"header-anchor",attrs:{href:"#资产相关"}},[e._v("#")]),e._v(" 资产相关")]),e._v(" "),v("ul",[v("li",[e._v("预计这次旅行要花多少钱?How much does this travel take? How much did you prepare for this travel?\n"),v("ul",[v("li",[e._v("I prepare xx dollars for the travel. here's my bank account information.")])])]),e._v(" "),v("li",[e._v("谁付钱?Who will pay this travel?Who sponsors this travel?\n"),v("ul",[v("li",[e._v("Myself. I prepare xx dollars for the travel. here's my bank account information.")])])]),e._v(" "),v("li",[e._v("你有房子吗?Do you own any house/property/real estate?")]),e._v(" "),v("li",[e._v("你有信用卡吗?Do you have any credit cards?")]),e._v(" "),v("li",[e._v("你有些什么财产?What properties do you own?")])])])}),[],!1,null,null,null);v.default=t.exports}}]); \ No newline at end of file diff --git a/assets/js/16.47bca1a5.js b/assets/js/16.47bca1a5.js new file mode 100644 index 0000000000..8f77c7dbae --- /dev/null +++ b/assets/js/16.47bca1a5.js @@ -0,0 +1 @@ +(window.webpackJsonp=window.webpackJsonp||[]).push([[16],{430:function(t,e,a){t.exports=a.p+"assets/img/98df8e702b14096e7ee4a5141260cdc4.ce6807a6.png"},431:function(t,e,a){t.exports=a.p+"assets/img/b6b71ec46935130dff5c4b62cf273477.3cbe0216.png"},432:function(t,e,a){t.exports=a.p+"assets/img/6ebf42641b5f98f912d36f6bf86f6569.c4cc26c0.png"},433:function(t,e,a){t.exports=a.p+"assets/img/3f70b4ad9069ec568a2caaddc231b7dc.8e3501a3.png"},475:function(t,e,a){"use strict";a.r(e);var s=a(30),n=Object(s.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"_2-1-数组"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_2-1-数组"}},[t._v("#")]),t._v(" 2.1 数组")]),t._v(" "),e("h2",{attrs:{id:"数组的定义"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数组的定义"}},[t._v("#")]),t._v(" 数组的定义")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",[t._v("**数组(Array)**是一种线性表数据结构。它用一组连续的内存空间,来存储一组具有相同类型的数据。")])]),t._v(" "),e("p",[e("img",{attrs:{src:a(430),alt:""}})]),t._v(" "),e("div",{staticClass:"language-javascript extra-class"},[e("pre",{pre:!0,attrs:{class:"language-javascript"}},[e("code",[e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 一维数组:")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 数组的每一个元素是一个数据类型")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 二维数组:")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 数组的每一个元素是一个一维数组")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("123")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 三维数组:")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 数组的每一个元素是一个二维数组")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),e("p",[t._v("我们还可以从两个方面来解释一下数组的定义。")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("ol",[e("li",[e("strong",[t._v("线性表")])]),t._v(" "),e("li",[e("strong",[t._v("连续的内存空间")])])])]),t._v(" "),e("h2",{attrs:{id:"线性表与非线性表"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#线性表与非线性表"}},[t._v("#")]),t._v(" 线性表与非线性表")]),t._v(" "),e("p",[e("strong",[t._v("线性表(Linear List)")]),t._v(" 就是数据排成像一条线一样的结构,线性表上的数据元素都是相同类型。每个线性表上的数据最多只有前和后两个方向。")]),t._v(" "),e("p",[e("strong",[t._v("数组、链表、队列、栈都是是线性表结构")]),t._v("。")]),t._v(" "),e("p",[t._v("线性表有两种存储结构:「顺序存储结构」和「链式存储结构」。")]),t._v(" "),e("p",[t._v("其中,「"),e("strong",[t._v("顺序存储结构")]),t._v("」是指占用的内存空间是连续的,相邻数据元素之间,物理内存上的存储位置也相邻。")]),t._v(" "),e("p",[t._v("数组也是采用了顺序存储结构,并且存储的数据都是相同类型的。")]),t._v(" "),e("p",[e("img",{attrs:{src:a(431),alt:""}})]),t._v(" "),e("p",[t._v("与它相对立的是"),e("strong",[t._v("非线性表")]),t._v(",比如"),e("strong",[t._v("二叉树、堆、图")]),t._v("等。")]),t._v(" "),e("p",[t._v("在非线性表中,数据之间并不是简单的前后关系。")]),t._v(" "),e("p",[e("img",{attrs:{src:a(432),alt:""}})]),t._v(" "),e("h2",{attrs:{id:"数组的操作"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数组的操作"}},[t._v("#")]),t._v(" 数组的操作")]),t._v(" "),e("p",[t._v("数据结构的操作一般涉及到增、删、改、查共 4 种情况,下面我们一起来看一下数组的这 4 种基本操作。")]),t._v(" "),e("h3",{attrs:{id:"_1-访问和查找元素"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_1-访问和查找元素"}},[t._v("#")]),t._v(" 1. 访问和查找元素")]),t._v(" "),e("p",[t._v("因为数组有"),e("strong",[t._v("连续的内存空间和相同类型的数据")]),t._v(",所以数组支持 "),e("strong",[t._v("“随机访问”")]),t._v("。")]),t._v(" "),e("p",[t._v("但这两个限制也让数组的很多操作变得非常低效,比如在数组中删除、插入一个数据,为了内存数据的保证连续性,就需要做大量的数据搬移工作。")]),t._v(" "),e("p",[t._v("在面试的时候,面试官常常会问数组和链表的区别?很多人都回答说,“链表适合插入、删除,时间复杂度 "),e("code",[t._v("O(1)")]),t._v(";数组适合查找,查找时间复杂度为 "),e("code",[t._v("O(1)")]),t._v("”。实际上,这种表述是不准确的。")]),t._v(" "),e("p",[t._v("数组适合查找操作,但是查找的时间复杂度并不为 "),e("code",[t._v("O(1)")]),t._v("。即便是排好序的数组,用"),e("strong",[t._v("二分查找")]),t._v(",时间复杂度也是 "),e("code",[t._v("O(logn)")]),t._v("。")]),t._v(" "),e("p",[t._v("所以,正确的表述应该是,数组支持随机访问,"),e("strong",[t._v("根据下标随机访问")]),t._v("的时间复杂度为 "),e("code",[t._v("O(1)")]),t._v("。")]),t._v(" "),e("h3",{attrs:{id:"_2-改变元素"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_2-改变元素"}},[t._v("#")]),t._v(" 2. 改变元素")]),t._v(" "),e("p",[t._v("改变元素的操作跟访问元素操作类似,访问操作不依赖于数组中元素个数,因此,「改变元素」的时间复杂度为 "),e("code",[t._v("O(1)")]),t._v("。")]),t._v(" "),e("h3",{attrs:{id:"_3-插入元素"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_3-插入元素"}},[t._v("#")]),t._v(" 3. 插入元素")]),t._v(" "),e("p",[t._v("假设数组的长度为 n,将一个数据插入到数组中的第 k 个位置。为了把第 k 个位置腾给新来的数据,要将第 k ~ n 这部分的元素都顺序地往后挪一位。")]),t._v(" "),e("ul",[e("li",[t._v("如果在数组的"),e("strong",[t._v("末尾插入")]),t._v("元素,不需要移动数据,时间复杂度为 "),e("code",[t._v("O(1)")]),t._v("。")]),t._v(" "),e("li",[t._v("但如果在数组的"),e("strong",[t._v("开头插入")]),t._v("元素,那所有的数据都要依次往后移动一位,所以最坏时间复杂度是"),e("code",[t._v("O(n)")]),t._v("。")]),t._v(" "),e("li",[t._v("因为每个位置插入元素的概率一样,所以"),e("strong",[t._v("平均情况")]),t._v("时间复杂度为"),e("code",[t._v("(1 + 2 + … + n) / n = O(n)")]),t._v("。")])]),t._v(" "),e("p",[t._v("如果数组中的数据是有序的,在插入新元素时就必须搬移 k 之后的数据。但是,如果数组中存储的数据并没有任何规律,将某个新元素插入到第 k 个位置时,为了避免大规模的数据搬移,有一个简单的办法就是,直接将第 k 位的数据搬移到数组元素的最后,把新的元素直接放入第 k 个位置。")]),t._v(" "),e("p",[t._v("例如:数组 a 中存储了如下 5 个元素:a,b,c,d,e。要将元素 x 插入到第 3 个位置。只需将 c 放入到 a[5],将 a[2]赋值为 x 即可。最后数组中的元素如下: a,b,x,d,e,c。")]),t._v(" "),e("p",[e("img",{attrs:{src:a(433),alt:""}})]),t._v(" "),e("p",[t._v("利用这种处理技巧,在特定场景下,在第 k 个位置插入一个元素的时间复杂度就会降为 O(1)。这个处理思想在"),e("strong",[t._v("快排")]),t._v("中也会用到。")]),t._v(" "),e("h3",{attrs:{id:"_4-删除元素"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_4-删除元素"}},[t._v("#")]),t._v(" 4. 删除元素")]),t._v(" "),e("p",[t._v("跟插入数据类似,如果我们要删除第 k 个位置的数据,为了内存的连续性,也需要搬移数据,不然中间就会出现空洞,内存就不连续了。")]),t._v(" "),e("p",[t._v("和插入类似:")]),t._v(" "),e("ul",[e("li",[t._v("如果"),e("strong",[t._v("删除数组末尾")]),t._v("的数据,则最好情况时间复杂度为 "),e("code",[t._v("O(1)")]),t._v(";")]),t._v(" "),e("li",[t._v("如果"),e("strong",[t._v("删除开头")]),t._v("的数据,则最坏情况时间复杂度为 "),e("code",[t._v("O(n)")]),t._v(";")]),t._v(" "),e("li",[e("strong",[t._v("平均情况")]),t._v("时间复杂度也为 "),e("code",[t._v("O(n)")]),t._v("。")])]),t._v(" "),e("p",[t._v("实际上,在某些特殊场景下,并不一定非得追求数组中数据的连续性。如果每次的删除操作并不是真正地搬移数据,只是记录数据已经被删除。当数组没有更多空间存储数据时,再触发执行一次真正的删除操作,就可以大大减少了删除操作导致的数据搬移。这也是"),e("strong",[t._v("JVM 标记清除垃圾回收算法")]),t._v("的核心思想。")]),t._v(" "),e("h2",{attrs:{id:"相关题目"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#相关题目"}},[t._v("#")]),t._v(" 相关题目")]),t._v(" "),e("h4",{attrs:{id:"数组操作"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数组操作"}},[t._v("#")]),t._v(" 数组操作")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",{staticStyle:{"text-align":"left"}},[t._v("题号")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("标题")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("题解")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("标签")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("难度")])])]),t._v(" "),e("tbody",[e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0189")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/rotate-array/",target:"_blank",rel:"noopener noreferrer"}},[t._v("轮转数组"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0189",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、数学、双指针")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0066")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/plus-one/",target:"_blank",rel:"noopener noreferrer"}},[t._v("加一"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0066",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、数学")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("简单")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0724")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/find-pivot-index/",target:"_blank",rel:"noopener noreferrer"}},[t._v("寻找数组的中心下标"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0724",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、前缀和")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("简单")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0485")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/max-consecutive-ones/",target:"_blank",rel:"noopener noreferrer"}},[t._v("最大连续 1 的个数"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0485",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("简单")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0238")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/product-of-array-except-self/",target:"_blank",rel:"noopener noreferrer"}},[t._v("除自身以外数组的乘积"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0238",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、前缀和")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])])])]),t._v(" "),e("h4",{attrs:{id:"二维数组"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#二维数组"}},[t._v("#")]),t._v(" 二维数组")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",{staticStyle:{"text-align":"left"}},[t._v("题号")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("标题")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("题解")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("标签")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("难度")])])]),t._v(" "),e("tbody",[e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0498")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/diagonal-traverse/",target:"_blank",rel:"noopener noreferrer"}},[t._v("对角线遍历"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0498",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、矩阵、模拟")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0048")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/rotate-image/",target:"_blank",rel:"noopener noreferrer"}},[t._v("旋转图像"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0048",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、数学、矩阵")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0073")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/set-matrix-zeroes/",target:"_blank",rel:"noopener noreferrer"}},[t._v("矩阵置零"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0073",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、哈希表、矩阵")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0054")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/spiral-matrix/",target:"_blank",rel:"noopener noreferrer"}},[t._v("螺旋矩阵"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0054",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、矩阵、模拟")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0059")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/spiral-matrix-ii/",target:"_blank",rel:"noopener noreferrer"}},[t._v("螺旋矩阵 II"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0059",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、矩阵、模拟")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0289")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/game-of-life/",target:"_blank",rel:"noopener noreferrer"}},[t._v("生命游戏"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}}),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、矩阵、模拟")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])])])])])}),[],!1,null,null,null);e.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/16.89f608ba.js b/assets/js/16.89f608ba.js deleted file mode 100644 index 084062bbf3..0000000000 --- a/assets/js/16.89f608ba.js +++ /dev/null @@ -1 +0,0 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[16],{430:function(t,e,a){t.exports=a.p+"assets/img/98df8e702b14096e7ee4a5141260cdc4.ce6807a6.png"},431:function(t,e,a){t.exports=a.p+"assets/img/b6b71ec46935130dff5c4b62cf273477.3cbe0216.png"},432:function(t,e,a){t.exports=a.p+"assets/img/6ebf42641b5f98f912d36f6bf86f6569.c4cc26c0.png"},433:function(t,e,a){t.exports=a.p+"assets/img/3f70b4ad9069ec568a2caaddc231b7dc.8e3501a3.png"},475:function(t,e,a){"use strict";a.r(e);var s=a(30),n=Object(s.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"_2-1-数组"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_2-1-数组"}},[t._v("#")]),t._v(" 2.1 数组")]),t._v(" "),e("h2",{attrs:{id:"数组的定义"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数组的定义"}},[t._v("#")]),t._v(" 数组的定义")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",[t._v("数组(Array)是一种线性表数据结构。它用一组连续的内存空间,来存储一组具有相同类型的数据。")])]),t._v(" "),e("p",[e("img",{attrs:{src:a(430),alt:""}})]),t._v(" "),e("div",{staticClass:"language-javascript extra-class"},[e("pre",{pre:!0,attrs:{class:"language-javascript"}},[e("code",[e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 一维数组:")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 数组的每一个元素是一个数据类型")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 二维数组:")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 数组的每一个元素是一个一维数组")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("123")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 三维数组:")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 数组的每一个元素是一个二维数组")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])])]),e("p",[t._v("我们还可以从两个方面来解释一下数组的定义。")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("ol",[e("li",[e("strong",[t._v("线性表")])]),t._v(" "),e("li",[e("strong",[t._v("连续的内存空间")])])])]),t._v(" "),e("h2",{attrs:{id:"线性表与非线性表"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#线性表与非线性表"}},[t._v("#")]),t._v(" 线性表与非线性表")]),t._v(" "),e("p",[e("strong",[t._v("线性表(Linear List)")]),t._v(" 就是数据排成像一条线一样的结构,线性表上的数据元素都是相同类型。每个线性表上的数据最多只有前和后两个方向。")]),t._v(" "),e("p",[e("strong",[t._v("数组、链表、队列、栈都是是线性表结构")]),t._v("。")]),t._v(" "),e("p",[t._v("线性表有两种存储结构:「顺序存储结构」和「链式存储结构」。")]),t._v(" "),e("p",[t._v("其中,「"),e("strong",[t._v("顺序存储结构")]),t._v("」是指占用的内存空间是连续的,相邻数据元素之间,物理内存上的存储位置也相邻。")]),t._v(" "),e("p",[t._v("数组也是采用了顺序存储结构,并且存储的数据都是相同类型的。")]),t._v(" "),e("p",[e("img",{attrs:{src:a(431),alt:""}})]),t._v(" "),e("p",[t._v("与它相对立的是"),e("strong",[t._v("非线性表")]),t._v(",比如"),e("strong",[t._v("二叉树、堆、图")]),t._v("等。")]),t._v(" "),e("p",[t._v("在非线性表中,数据之间并不是简单的前后关系。")]),t._v(" "),e("p",[e("img",{attrs:{src:a(432),alt:""}})]),t._v(" "),e("h2",{attrs:{id:"数组的操作"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数组的操作"}},[t._v("#")]),t._v(" 数组的操作")]),t._v(" "),e("p",[t._v("数据结构的操作一般涉及到增、删、改、查共 4 种情况,下面我们一起来看一下数组的这 4 种基本操作。")]),t._v(" "),e("h3",{attrs:{id:"_1-访问和查找元素"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_1-访问和查找元素"}},[t._v("#")]),t._v(" 1. 访问和查找元素")]),t._v(" "),e("p",[t._v("因为数组有"),e("strong",[t._v("连续的内存空间和相同类型的数据")]),t._v(",所以数组支持 "),e("strong",[t._v("“随机访问”")]),t._v("。")]),t._v(" "),e("p",[t._v("但这两个限制也让数组的很多操作变得非常低效,比如在数组中删除、插入一个数据,为了内存数据的保证连续性,就需要做大量的数据搬移工作。")]),t._v(" "),e("p",[t._v("在面试的时候,面试官常常会问数组和链表的区别?很多人都回答说,“链表适合插入、删除,时间复杂度 "),e("code",[t._v("O(1)")]),t._v(";数组适合查找,查找时间复杂度为 "),e("code",[t._v("O(1)")]),t._v("”。实际上,这种表述是不准确的。")]),t._v(" "),e("p",[t._v("数组适合查找操作,但是查找的时间复杂度并不为 "),e("code",[t._v("O(1)")]),t._v("。即便是排好序的数组,用"),e("strong",[t._v("二分查找")]),t._v(",时间复杂度也是 "),e("code",[t._v("O(logn)")]),t._v("。")]),t._v(" "),e("p",[t._v("所以,正确的表述应该是,数组支持随机访问,"),e("strong",[t._v("根据下标随机访问")]),t._v("的时间复杂度为 "),e("code",[t._v("O(1)")]),t._v("。")]),t._v(" "),e("h3",{attrs:{id:"_2-改变元素"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_2-改变元素"}},[t._v("#")]),t._v(" 2. 改变元素")]),t._v(" "),e("p",[t._v("改变元素的操作跟访问元素操作类似,访问操作不依赖于数组中元素个数,因此,「改变元素」的时间复杂度为 "),e("code",[t._v("O(1)")]),t._v("。")]),t._v(" "),e("h3",{attrs:{id:"_3-插入元素"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_3-插入元素"}},[t._v("#")]),t._v(" 3. 插入元素")]),t._v(" "),e("p",[t._v("假设数组的长度为 n,将一个数据插入到数组中的第 k 个位置。为了把第 k 个位置腾给新来的数据,要将第 k ~ n 这部分的元素都顺序地往后挪一位。")]),t._v(" "),e("ul",[e("li",[t._v("如果在数组的"),e("strong",[t._v("末尾插入")]),t._v("元素,不需要移动数据,时间复杂度为 "),e("code",[t._v("O(1)")]),t._v("。")]),t._v(" "),e("li",[t._v("但如果在数组的"),e("strong",[t._v("开头插入")]),t._v("元素,那所有的数据都要依次往后移动一位,所以最坏时间复杂度是"),e("code",[t._v("O(n)")]),t._v("。")]),t._v(" "),e("li",[t._v("因为每个位置插入元素的概率一样,所以"),e("strong",[t._v("平均情况")]),t._v("时间复杂度为"),e("code",[t._v("(1 + 2 + … + n) / n = O(n)")]),t._v("。")])]),t._v(" "),e("p",[t._v("如果数组中的数据是有序的,在插入新元素时就必须搬移 k 之后的数据。但是,如果数组中存储的数据并没有任何规律,将某个新元素插入到第 k 个位置时,为了避免大规模的数据搬移,有一个简单的办法就是,直接将第 k 位的数据搬移到数组元素的最后,把新的元素直接放入第 k 个位置。")]),t._v(" "),e("p",[t._v("例如:数组 a 中存储了如下 5 个元素:a,b,c,d,e。要将元素 x 插入到第 3 个位置。只需将 c 放入到 a[5],将 a[2]赋值为 x 即可。最后数组中的元素如下: a,b,x,d,e,c。")]),t._v(" "),e("p",[e("img",{attrs:{src:a(433),alt:""}})]),t._v(" "),e("p",[t._v("利用这种处理技巧,在特定场景下,在第 k 个位置插入一个元素的时间复杂度就会降为 O(1)。这个处理思想在"),e("strong",[t._v("快排")]),t._v("中也会用到。")]),t._v(" "),e("h3",{attrs:{id:"_4-删除元素"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_4-删除元素"}},[t._v("#")]),t._v(" 4. 删除元素")]),t._v(" "),e("p",[t._v("跟插入数据类似,如果我们要删除第 k 个位置的数据,为了内存的连续性,也需要搬移数据,不然中间就会出现空洞,内存就不连续了。")]),t._v(" "),e("p",[t._v("和插入类似:")]),t._v(" "),e("ul",[e("li",[t._v("如果"),e("strong",[t._v("删除数组末尾")]),t._v("的数据,则最好情况时间复杂度为 "),e("code",[t._v("O(1)")]),t._v(";")]),t._v(" "),e("li",[t._v("如果"),e("strong",[t._v("删除开头")]),t._v("的数据,则最坏情况时间复杂度为 "),e("code",[t._v("O(n)")]),t._v(";")]),t._v(" "),e("li",[e("strong",[t._v("平均情况")]),t._v("时间复杂度也为 "),e("code",[t._v("O(n)")]),t._v("。")])]),t._v(" "),e("p",[t._v("实际上,在某些特殊场景下,并不一定非得追求数组中数据的连续性。如果每次的删除操作并不是真正地搬移数据,只是记录数据已经被删除。当数组没有更多空间存储数据时,再触发执行一次真正的删除操作,就可以大大减少了删除操作导致的数据搬移。这也是"),e("strong",[t._v("JVM 标记清除垃圾回收算法")]),t._v("的核心思想。")]),t._v(" "),e("h2",{attrs:{id:"相关题目"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#相关题目"}},[t._v("#")]),t._v(" 相关题目")]),t._v(" "),e("h4",{attrs:{id:"数组操作"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数组操作"}},[t._v("#")]),t._v(" 数组操作")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",{staticStyle:{"text-align":"left"}},[t._v("题号")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("标题")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("题解")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("标签")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("难度")])])]),t._v(" "),e("tbody",[e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0189")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/rotate-array/",target:"_blank",rel:"noopener noreferrer"}},[t._v("轮转数组"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0189",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、数学、双指针")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0066")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/plus-one/",target:"_blank",rel:"noopener noreferrer"}},[t._v("加一"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0066",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、数学")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("简单")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0724")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/find-pivot-index/",target:"_blank",rel:"noopener noreferrer"}},[t._v("寻找数组的中心下标"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0724",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、前缀和")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("简单")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0485")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/max-consecutive-ones/",target:"_blank",rel:"noopener noreferrer"}},[t._v("最大连续 1 的个数"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0485",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("简单")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0238")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/product-of-array-except-self/",target:"_blank",rel:"noopener noreferrer"}},[t._v("除自身以外数组的乘积"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0238",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、前缀和")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])])])]),t._v(" "),e("h4",{attrs:{id:"二维数组"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#二维数组"}},[t._v("#")]),t._v(" 二维数组")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",{staticStyle:{"text-align":"left"}},[t._v("题号")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("标题")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("题解")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("标签")]),t._v(" "),e("th",{staticStyle:{"text-align":"left"}},[t._v("难度")])])]),t._v(" "),e("tbody",[e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0498")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/diagonal-traverse/",target:"_blank",rel:"noopener noreferrer"}},[t._v("对角线遍历"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0498",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、矩阵、模拟")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0048")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/rotate-image/",target:"_blank",rel:"noopener noreferrer"}},[t._v("旋转图像"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0048",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、数学、矩阵")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0073")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/set-matrix-zeroes/",target:"_blank",rel:"noopener noreferrer"}},[t._v("矩阵置零"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0073",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、哈希表、矩阵")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0054")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/spiral-matrix/",target:"_blank",rel:"noopener noreferrer"}},[t._v("螺旋矩阵"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0054",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、矩阵、模拟")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0059")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/spiral-matrix-ii/",target:"_blank",rel:"noopener noreferrer"}},[t._v("螺旋矩阵 II"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://2xiao.github.io/leetcode-js/leetcode/problem/0059",target:"_blank",rel:"noopener noreferrer"}},[t._v("JS"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、矩阵、模拟")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])]),t._v(" "),e("tr",[e("td",{staticStyle:{"text-align":"left"}},[t._v("0289")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[e("a",{attrs:{href:"https://leetcode.com/problems/game-of-life/",target:"_blank",rel:"noopener noreferrer"}},[t._v("生命游戏"),e("OutboundLink")],1)]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}}),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("数组、矩阵、模拟")]),t._v(" "),e("td",{staticStyle:{"text-align":"left"}},[t._v("中等")])])])])])}),[],!1,null,null,null);e.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/17.e0522960.js b/assets/js/17.e0522960.js deleted file mode 100644 index bdfa6e30d2..0000000000 --- a/assets/js/17.e0522960.js +++ /dev/null @@ -1 +0,0 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[17],{408:function(t,e,_){},445:function(t,e,_){t.exports=_.p+"assets/img/3723793cc5c810e9d5b06bc95325bf0a.2bf7f5e4.png"},446:function(t,e,_){t.exports=_.p+"assets/img/497a3f120b7debee07dc0d03984faf04.4979878a.png"},447:function(t,e,_){"use strict";_(408)},484:function(t,e,_){"use strict";_.r(e);_(447);var v=_(30),n=Object(v.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"_1-2-复杂度分析"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_1-2-复杂度分析"}},[t._v("#")]),t._v(" 1.2 复杂度分析")]),t._v(" "),e("p",[t._v("想要学习数据结构与算法,首先要掌握一个最重要的概念——复杂度分析,它可以帮我们分析如何更省、更快地存储和处理数据。")]),t._v(" "),e("h2",{attrs:{id:"时间复杂度"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#时间复杂度"}},[t._v("#")]),t._v(" 时间复杂度")]),t._v(" "),e("p",[t._v("算法的时间复杂度(time complexity)是一个函数,它定性描述该算法的运行时间。用于评估执行程序所消耗的时间,可以估算出程序对处理器的使用程度。")]),t._v(" "),e("p",[t._v("时间复杂度常用大O符号表述,使用这种方式时,时间复杂度可被称为是渐近的,亦即考察输入值大小趋近无穷时的情况。")]),t._v(" "),e("p",[t._v("相同大小的不同输入值仍可能造成算法的执行时间不同,因此我们通常使用算法的最坏情况复杂度,记为 "),e("code",[t._v("T(n)")]),t._v(" ,定义为任何大小的输入 n 所需的最大执行时间。")]),t._v(" "),e("p",[t._v("以下是一些最常用的 大O标记法 列表以及它们与不同大小输入数据的性能比较。")]),t._v(" "),e("p",[e("img",{attrs:{src:_(445),alt:""}}),t._v(" "),e("img",{attrs:{src:_(446),alt:""}})]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("大O标记法")]),t._v(" "),e("th",[t._v("计算10个元素")]),t._v(" "),e("th",[t._v("计算100个元素")]),t._v(" "),e("th",[t._v("计算1000个元素")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("strong",[t._v("O(1)")])]),t._v(" "),e("td",[t._v("1")]),t._v(" "),e("td",[t._v("1")]),t._v(" "),e("td",[t._v("1")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(log N)")])]),t._v(" "),e("td",[t._v("3")]),t._v(" "),e("td",[t._v("6")]),t._v(" "),e("td",[t._v("9")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(N)")])]),t._v(" "),e("td",[t._v("10")]),t._v(" "),e("td",[t._v("100")]),t._v(" "),e("td",[t._v("1000")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(N log N)")])]),t._v(" "),e("td",[t._v("30")]),t._v(" "),e("td",[t._v("600")]),t._v(" "),e("td",[t._v("9000")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(N^2)")])]),t._v(" "),e("td",[t._v("100")]),t._v(" "),e("td",[t._v("10000")]),t._v(" "),e("td",[t._v("1000000")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(2^N)")])]),t._v(" "),e("td",[t._v("1024")]),t._v(" "),e("td",[t._v("1.26e+29")]),t._v(" "),e("td",[t._v("1.07e+301")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(N!)")])]),t._v(" "),e("td",[t._v("3628800")]),t._v(" "),e("td",[t._v("9.3e+157")]),t._v(" "),e("td",[t._v("4.02e+2567")])])])]),t._v(" "),e("h4",{attrs:{id:"数据结构操作的复杂性"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数据结构操作的复杂性"}},[t._v("#")]),t._v(" 数据结构操作的复杂性")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("数据结构")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("连接")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("查找")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("插入")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("删除")]),t._v(" "),e("th",[t._v("备注")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("strong",[t._v("数组")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("栈")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("队列")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("链表")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("哈希表")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("-")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",[t._v("在完全哈希函数情况下,复杂度是 O(1)")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("二分查找树")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",[t._v("在平衡树情况下,复杂度是 O(log(n))")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("B 树")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("红黑树")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("AVL 树")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("布隆过滤器")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("-")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("-")]),t._v(" "),e("td",[t._v("存在一定概率的判断错误(误判成存在)")])])])]),t._v(" "),e("h4",{attrs:{id:"数组排序算法的复杂性"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数组排序算法的复杂性"}},[t._v("#")]),t._v(" 数组排序算法的复杂性")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("名称")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("最优")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("平均")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("最坏")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("内存")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("稳定")]),t._v(" "),e("th",[t._v("备注")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("strong",[t._v("冒泡排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Yes")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("插入排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Yes")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("选择排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("No")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("堆排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("No")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("归并排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Yes")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("快速排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("No")]),t._v(" "),e("td",[t._v("在 in-place 版本下,内存复杂度通常是 O(log(n))")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("希尔排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("取决于差距序列")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n (log(n))^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("No")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("计数排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n + r")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n + r")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n + r")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n + r")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Yes")]),t._v(" "),e("td",[t._v("r - 数组里最大的数")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("基数排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n * k")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n * k")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n * k")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n + k")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Yes")]),t._v(" "),e("td",[t._v("k - 最长 key 的升序")])])])]),t._v(" "),e("h4",{attrs:{id:"分析复杂度的一些规则"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#分析复杂度的一些规则"}},[t._v("#")]),t._v(" 分析复杂度的一些规则")]),t._v(" "),e("ul",[e("li",[t._v("多个时间复杂度相加,如果都是与n相关,则取取复杂度高的那一个,例如:"),e("code",[t._v("O(nlogn + n) = O(nlogn),O(nlogn + n^2) = O(n^2)")]),t._v("。")]),t._v(" "),e("li",[t._v("多个时间复杂度相加,如果其中有些项的复杂度和n不相关则不能忽略任何项,例如:"),e("code",[t._v("O(AlogA + B),O(AlogA + B^2)")])]),t._v(" "),e("li",[t._v("两个循环依次执行,则取复杂度高的那个,嵌套多个循环则需要累乘复杂度。")])]),t._v(" "),e("p",[t._v("一个时间复杂度分析的例子:")]),t._v(" "),e("blockquote",[e("p",[t._v("有一个字符串数组,将数组中的每个字符串按照字母排序,然后在将整个字符串数组按照字典顺序排序。求整个操作的时间复杂度。")]),t._v(" "),e("ul",[e("li",[e("p",[t._v("我们来分析一下,假设最长字符串的长度是s,数组中有n个字符串。")])]),t._v(" "),e("li",[e("p",[t._v("对每个字符串排序 "),e("code",[t._v("O(slogs)")]),t._v(",将数组中的每个字符串按照字母排序"),e("code",[t._v("O(n * slogs)")]),t._v(";")])]),t._v(" "),e("li",[e("p",[t._v("将整个字符串数组按字典排序 "),e("code",[t._v("O(s * nlogn)")]),t._v(";")])]),t._v(" "),e("li",[e("p",[t._v("所以最后的时间复杂度是"),e("code",[t._v("O(n * slogs) + O(s * nlogn) = O(nslogs + nslogn) = O(ns * (logs+logn))")])])])])]),t._v(" "),e("h4",{attrs:{id:"时间复杂度优化"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#时间复杂度优化"}},[t._v("#")]),t._v(" 时间复杂度优化")]),t._v(" "),e("ul",[e("li",[t._v("采用更好的算法:举例:"),e("code",[t._v("1+2+3...n")]),t._v(" 从 "),e("code",[t._v("1~n")]),t._v(" 求和,直接循环法,"),e("code",[t._v("for i->n: sum+=i")]),t._v(" ,我们也可以用求和公式: "),e("code",[t._v("n(n+1)/2")]),t._v(";有些问题可以用二分查找等。")]),t._v(" "),e("li",[t._v("空间换时间,比如用set 或map 加快查找的速度,用二叉搜索树或者字典树加快字符串的搜索。")])]),t._v(" "),e("h2",{attrs:{id:"空间复杂度"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#空间复杂度"}},[t._v("#")]),t._v(" 空间复杂度")]),t._v(" "),e("p",[t._v("空间复杂度(Space Complexity)指的是算法在运行过程中所占存储空间的大小,依然使用大O来表示。用于评估执行程序所占用的内存空间,可以估算出程序对计算机内存的使用程度。")]),t._v(" "),e("h4",{attrs:{id:"常见的空间复杂度"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#常见的空间复杂度"}},[t._v("#")]),t._v(" 常见的空间复杂度")]),t._v(" "),e("ul",[e("li",[t._v("一维数组空间,如果存储了n个元素,空间复杂度"),e("code",[t._v("O(n)")]),t._v(";")]),t._v(" "),e("li",[t._v("二维数组空间,总共有n个数组,每个数组存储了n个元素,空间复杂度"),e("code",[t._v("O(n^2)")]),t._v(";")]),t._v(" "),e("li",[t._v("常数空间复杂度"),e("code",[t._v("O(1)")]),t._v(";")])])])}),[],!1,null,null,null);e.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/17.f204a89a.js b/assets/js/17.f204a89a.js new file mode 100644 index 0000000000..722668a913 --- /dev/null +++ b/assets/js/17.f204a89a.js @@ -0,0 +1 @@ +(window.webpackJsonp=window.webpackJsonp||[]).push([[17],{408:function(t,e,_){},445:function(t,e,_){t.exports=_.p+"assets/img/3723793cc5c810e9d5b06bc95325bf0a.2bf7f5e4.png"},446:function(t,e,_){t.exports=_.p+"assets/img/497a3f120b7debee07dc0d03984faf04.4979878a.png"},447:function(t,e,_){"use strict";_(408)},484:function(t,e,_){"use strict";_.r(e);_(447);var v=_(30),n=Object(v.a)({},(function(){var t=this,e=t._self._c;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"_1-2-复杂度分析"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#_1-2-复杂度分析"}},[t._v("#")]),t._v(" 1.2 复杂度分析")]),t._v(" "),e("p",[t._v("想要学习数据结构与算法,首先要掌握一个最重要的概念——复杂度分析,它可以帮我们分析如何更省、更快地存储和处理数据。")]),t._v(" "),e("h2",{attrs:{id:"时间复杂度"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#时间复杂度"}},[t._v("#")]),t._v(" 时间复杂度")]),t._v(" "),e("p",[t._v("算法的**时间复杂度(time complexity)**是一个函数,它定性描述该算法的运行时间。用于评估执行程序所消耗的时间,可以估算出程序对处理器的使用程度。")]),t._v(" "),e("p",[t._v("时间复杂度常用大O符号表述,使用这种方式时,时间复杂度可被称为是渐近的,亦即考察输入值大小趋近无穷时的情况。")]),t._v(" "),e("p",[t._v("相同大小的不同输入值仍可能造成算法的执行时间不同,因此我们通常使用算法的最坏情况复杂度,记为 "),e("code",[t._v("T(n)")]),t._v(" ,定义为任何大小的输入 n 所需的最大执行时间。")]),t._v(" "),e("p",[t._v("以下是一些最常用的 大O标记法 列表以及它们与不同大小输入数据的性能比较。")]),t._v(" "),e("p",[e("img",{attrs:{src:_(445),alt:""}}),t._v(" "),e("img",{attrs:{src:_(446),alt:""}})]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("大O标记法")]),t._v(" "),e("th",[t._v("计算10个元素")]),t._v(" "),e("th",[t._v("计算100个元素")]),t._v(" "),e("th",[t._v("计算1000个元素")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("strong",[t._v("O(1)")])]),t._v(" "),e("td",[t._v("1")]),t._v(" "),e("td",[t._v("1")]),t._v(" "),e("td",[t._v("1")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(log N)")])]),t._v(" "),e("td",[t._v("3")]),t._v(" "),e("td",[t._v("6")]),t._v(" "),e("td",[t._v("9")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(N)")])]),t._v(" "),e("td",[t._v("10")]),t._v(" "),e("td",[t._v("100")]),t._v(" "),e("td",[t._v("1000")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(N log N)")])]),t._v(" "),e("td",[t._v("30")]),t._v(" "),e("td",[t._v("600")]),t._v(" "),e("td",[t._v("9000")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(N^2)")])]),t._v(" "),e("td",[t._v("100")]),t._v(" "),e("td",[t._v("10000")]),t._v(" "),e("td",[t._v("1000000")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(2^N)")])]),t._v(" "),e("td",[t._v("1024")]),t._v(" "),e("td",[t._v("1.26e+29")]),t._v(" "),e("td",[t._v("1.07e+301")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("O(N!)")])]),t._v(" "),e("td",[t._v("3628800")]),t._v(" "),e("td",[t._v("9.3e+157")]),t._v(" "),e("td",[t._v("4.02e+2567")])])])]),t._v(" "),e("h3",{attrs:{id:"数据结构操作的复杂性"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数据结构操作的复杂性"}},[t._v("#")]),t._v(" 数据结构操作的复杂性")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("数据结构")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("连接")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("查找")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("插入")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("删除")]),t._v(" "),e("th",[t._v("备注")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("strong",[t._v("数组")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("栈")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("队列")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("链表")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("哈希表")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("-")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",[t._v("在完全哈希函数情况下,复杂度是 O(1)")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("二分查找树")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",[t._v("在平衡树情况下,复杂度是 O(log(n))")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("B 树")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("红黑树")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("AVL 树")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("布隆过滤器")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("-")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("-")]),t._v(" "),e("td",[t._v("存在一定概率的判断错误(误判成存在)")])])])]),t._v(" "),e("h3",{attrs:{id:"数组排序算法的复杂性"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#数组排序算法的复杂性"}},[t._v("#")]),t._v(" 数组排序算法的复杂性")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("名称")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("最优")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("平均")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("最坏")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("内存")]),t._v(" "),e("th",{staticStyle:{"text-align":"center"}},[t._v("稳定")]),t._v(" "),e("th",[t._v("备注")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("strong",[t._v("冒泡排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Yes")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("插入排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Yes")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("选择排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("No")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("堆排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("No")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("归并排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Yes")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("快速排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("No")]),t._v(" "),e("td",[t._v("在 in-place 版本下,内存复杂度通常是 O(log(n))")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("希尔排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n log(n)")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("取决于差距序列")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n (log(n))^2")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("1")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("No")]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("计数排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n + r")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n + r")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n + r")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n + r")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Yes")]),t._v(" "),e("td",[t._v("r - 数组里最大的数")])]),t._v(" "),e("tr",[e("td",[e("strong",[t._v("基数排序")])]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n * k")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n * k")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n * k")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("n + k")]),t._v(" "),e("td",{staticStyle:{"text-align":"center"}},[t._v("Yes")]),t._v(" "),e("td",[t._v("k - 最长 key 的升序")])])])]),t._v(" "),e("h3",{attrs:{id:"分析复杂度的一些规则"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#分析复杂度的一些规则"}},[t._v("#")]),t._v(" 分析复杂度的一些规则")]),t._v(" "),e("ul",[e("li",[t._v("多个时间复杂度相加,如果都是与n相关,则取取复杂度高的那一个,例如:"),e("code",[t._v("O(nlogn + n) = O(nlogn),O(nlogn + n^2) = O(n^2)")]),t._v("。")]),t._v(" "),e("li",[t._v("多个时间复杂度相加,如果其中有些项的复杂度和n不相关则不能忽略任何项,例如:"),e("code",[t._v("O(AlogA + B),O(AlogA + B^2)")])]),t._v(" "),e("li",[t._v("两个循环依次执行,则取复杂度高的那个,嵌套多个循环则需要累乘复杂度。")])]),t._v(" "),e("p",[t._v("一个时间复杂度分析的例子:")]),t._v(" "),e("blockquote",[e("p",[t._v("有一个字符串数组,将数组中的每个字符串按照字母排序,然后在将整个字符串数组按照字典顺序排序。求整个操作的时间复杂度。")]),t._v(" "),e("ul",[e("li",[e("p",[t._v("我们来分析一下,假设最长字符串的长度是s,数组中有n个字符串。")])]),t._v(" "),e("li",[e("p",[t._v("对每个字符串排序 "),e("code",[t._v("O(slogs)")]),t._v(",将数组中的每个字符串按照字母排序"),e("code",[t._v("O(n * slogs)")]),t._v(";")])]),t._v(" "),e("li",[e("p",[t._v("将整个字符串数组按字典排序 "),e("code",[t._v("O(s * nlogn)")]),t._v(";")])]),t._v(" "),e("li",[e("p",[t._v("所以最后的时间复杂度是"),e("code",[t._v("O(n * slogs) + O(s * nlogn) = O(nslogs + nslogn) = O(ns * (logs+logn))")])])])])]),t._v(" "),e("h3",{attrs:{id:"时间复杂度优化"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#时间复杂度优化"}},[t._v("#")]),t._v(" 时间复杂度优化")]),t._v(" "),e("ul",[e("li",[t._v("采用更好的算法:举例:"),e("code",[t._v("1+2+3...n")]),t._v(" 从 "),e("code",[t._v("1~n")]),t._v(" 求和,直接循环法,"),e("code",[t._v("for i->n: sum+=i")]),t._v(" ,我们也可以用求和公式: "),e("code",[t._v("n(n+1)/2")]),t._v(";有些问题可以用二分查找等。")]),t._v(" "),e("li",[t._v("空间换时间,比如用set 或map 加快查找的速度,用二叉搜索树或者字典树加快字符串的搜索。")])]),t._v(" "),e("h2",{attrs:{id:"空间复杂度"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#空间复杂度"}},[t._v("#")]),t._v(" 空间复杂度")]),t._v(" "),e("p",[t._v("**空间复杂度(Space Complexity)**指的是算法在运行过程中所占存储空间的大小,依然使用大O来表示。用于评估执行程序所占用的内存空间,可以估算出程序对计算机内存的使用程度。")]),t._v(" "),e("h3",{attrs:{id:"常见的空间复杂度"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#常见的空间复杂度"}},[t._v("#")]),t._v(" 常见的空间复杂度")]),t._v(" "),e("ul",[e("li",[t._v("一维数组空间,如果存储了n个元素,空间复杂度"),e("code",[t._v("O(n)")]),t._v(";")]),t._v(" "),e("li",[t._v("二维数组空间,总共有n个数组,每个数组存储了n个元素,空间复杂度"),e("code",[t._v("O(n^2)")]),t._v(";")]),t._v(" "),e("li",[t._v("常数空间复杂度"),e("code",[t._v("O(1)")]),t._v(";")])])])}),[],!1,null,null,null);e.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/30.101b2813.js b/assets/js/30.101b2813.js deleted file mode 100644 index 9ccd59387f..0000000000 --- a/assets/js/30.101b2813.js +++ /dev/null @@ -1 +0,0 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[30],{444:function(_,t,a){_.exports=a.p+"assets/img/913e0ababe43a2d57267df5c5f0832a7.a521b6df.png"},483:function(_,t,a){"use strict";a.r(t);var r=a(30),v=Object(r.a)({},(function(){var _=this,t=_._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":_.$parent.slotKey}},[t("h1",{attrs:{id:"_1-1-数据结构与算法"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#_1-1-数据结构与算法"}},[_._v("#")]),_._v(" 1.1 数据结构与算法")]),_._v(" "),t("p",[_._v("首先我们来明确一下数据结构与算法的定义。")]),_._v(" "),t("p",[_._v("从广义上讲,数据结构就是指一组数据的存储结构,算法就是操作数据的一组方法。")]),_._v(" "),t("p",[_._v("从狭义上讲,也就是本书要讲的,是指某些经典的数据结构和算法,比如队列、栈、堆、二分查找、动态规划等。这些都是前人从实际操作场景中抽象出来的,经过非常多的求证和检验,可以高效地帮助我们解决实际的开发问题。")]),_._v(" "),t("h2",{attrs:{id:"如何学习"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#如何学习"}},[_._v("#")]),_._v(" 如何学习")]),_._v(" "),t("p",[_._v("数据结构与算法涵盖的内容很多,要如何高效地系统性学习呢?")]),_._v(" "),t("p",[_._v("你并不需要掌握图里面的所有知识点。很多高级的数据结构与算法,比如二分图、最大流等,在我们平常的开发中很少会用到。")]),_._v(" "),t("p",[_._v("我总结了 19 个最常用、最基础的数据结构与算法,不管是应付面试还是工作需要,只要集中精力逐一攻克这 19 个知识点就足够了。")]),_._v(" "),t("div",{staticClass:"custom-block tip"},[t("ul",[t("li",[t("p",[t("strong",[_._v("8 个数据结构")]),_._v(":"),t("a",{attrs:{href:"../ds/0_array"}},[_._v("数组")]),_._v("、"),t("a",{attrs:{href:"../ds/1_linked_list"}},[_._v("链表")]),_._v("、"),t("a",{attrs:{href:"../ds/2_stack"}},[_._v("栈")]),_._v("、"),t("a",{attrs:{href:"../ds/3_queue"}},[_._v("队列")]),_._v("、"),t("a",{attrs:{href:"../ds/4_hash_table"}},[_._v("哈希表")]),_._v("、"),t("a",{attrs:{href:"../ds/5_string"}},[_._v("字符串")]),_._v("、"),t("a",{attrs:{href:"../ds/6_tree"}},[_._v("树")]),_._v("、"),t("a",{attrs:{href:"../ds/7_graph"}},[_._v("图")]),_._v(";")])]),_._v(" "),t("li",[t("p",[t("strong",[_._v("11 个算法")]),_._v(":"),t("a",{attrs:{href:"../algorithm/0_enumeration"}},[_._v("枚举算法")]),_._v("、"),t("a",{attrs:{href:"../algorithm/1_recursion"}},[_._v("递归算法")]),_._v("、"),t("a",{attrs:{href:"../algorithm/2_divide_conquer"}},[_._v("分治算法")]),_._v("、"),t("a",{attrs:{href:"../algorithm/3_backtracking"}},[_._v("回溯算法")]),_._v("、"),t("a",{attrs:{href:"../algorithm/4_greed"}},[_._v("贪心算法")]),_._v("、"),t("a",{attrs:{href:"../algorithm/5_dynamic_programming"}},[_._v("动态规划")]),_._v("、"),t("a",{attrs:{href:"../algorithm/6_bit"}},[_._v("位运算")]),_._v("、"),t("a",{attrs:{href:"../algorithm/7_sort"}},[_._v("排序算法")]),_._v("、"),t("a",{attrs:{href:"../algorithm/8_binary_search"}},[_._v("二分查找")]),_._v("、"),t("a",{attrs:{href:"../algorithm/9_two_pointer"}},[_._v("双指针")]),_._v("、"),t("a",{attrs:{href:"../algorithm/10_slide_window"}},[_._v("滑动窗口")]),_._v(";")])])])]),_._v(" "),t("p",[_._v("我对每个知识点都做了精讲,并配有对应的 LeetCode 题目,可以帮你打下扎实的基础,形成自己的知识体系。")]),_._v(" "),t("p",[_._v("想要对数据结构和算法有更全面的认识,可以查看这张思维导图,里面几乎涵盖了所有数据结构和算法书籍中都会讲到的知识点。")]),_._v(" "),t("p",[t("img",{attrs:{src:a(444),alt:""}})]),_._v(" "),t("h2",{attrs:{id:"如何刷题"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#如何刷题"}},[_._v("#")]),_._v(" 如何刷题")]),_._v(" "),t("p",[_._v("LeetCode 题目虽然多,但如果分类别来看,其实也没多少,很多题目都是类似的套路和延伸。")]),_._v(" "),t("p",[_._v("对于计算机基础不扎实的同学,如果按照高频顺序刷题,通过每道题反向获取知识,这样的方法不是不可以,但效率可能不高,还会造成知识零散化,不能融会贯通。")]),_._v(" "),t("p",[_._v("建议采用“"),t("strong",[_._v("分类知识学习")]),_._v(" + "),t("strong",[_._v("核心题目")]),_._v(" + "),t("strong",[_._v("反复训练")]),_._v(" + "),t("strong",[_._v("融会贯通")]),_._v("”的系统性学习方法。")]),_._v(" "),t("p",[_._v("我整理了 "),t("a",{attrs:{href:"../outline/4_top_200_list"}},[_._v("高频面试题(按分类排序)")]),_._v("和 "),t("a",{attrs:{href:"../outline/3_categories_list"}},[_._v("LeetCode 题解(分类)")]),_._v(",建议先从这些题入手,分类别练习,点击标题可以跳转到LeetCode对应答题页面,点击题解(JS)可以查看我的答题思路和代码,遇到不熟悉的知识点可以去对应的知识点精讲学习。")]),_._v(" "),t("p",[_._v("掌握了这十几种常见算法类型的基本原理和思路,就对数据结构与算法有了一个大体的了解,即便出现很多新题,大多也能用现有知识体系去化解。")]),_._v(" "),t("p",[_._v("对算法模板、数据结构形成初步的认识之后,可以再结合 "),t("a",{attrs:{href:"../outline/5_frequency_list"}},[_._v("高频面试题(按频次排序)")]),_._v("、"),t("a",{attrs:{href:"../outline/6_company_list"}},[_._v("高频面试题(按公司排序)")]),_._v("、 "),t("a",{attrs:{href:"../outline/2_solution_list"}},[_._v("LeetCode 题解")]),_._v(" 多加练习,逐渐提升自己对答题思路的掌握,和对内在原理的领悟。")]),_._v(" "),t("div",{staticClass:"custom-block tip"},[t("p",[_._v("电影《师父》里面有一句话:「每日挥刀五百下,这个数管住了我。」")])]),_._v(" "),t("p",[_._v("成功往往来自于,"),t("strong",[_._v("把简单、正确的事情重复做")]),_._v(",不相信也不追求快速而一劳永逸的必胜之法。")]),_._v(" "),t("p",[_._v("想要通关 LeetCode,没有什么神奇的方法,最重要还是自己动手刷题。")]),_._v(" "),t("p",[_._v("多花时间思考怎么 AC 手上的题目,少花时间幻想走了多少进度条。")])])}),[],!1,null,null,null);t.default=v.exports}}]); \ No newline at end of file diff --git a/assets/js/30.20fca599.js b/assets/js/30.20fca599.js new file mode 100644 index 0000000000..1f01707fa5 --- /dev/null +++ b/assets/js/30.20fca599.js @@ -0,0 +1 @@ +(window.webpackJsonp=window.webpackJsonp||[]).push([[30],{444:function(t,_,r){t.exports=r.p+"assets/img/913e0ababe43a2d57267df5c5f0832a7.a521b6df.png"},483:function(t,_,r){"use strict";r.r(_);var a=r(30),v=Object(a.a)({},(function(){var t=this,_=t._self._c;return _("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[_("h1",{attrs:{id:"_1-1-数据结构与算法"}},[_("a",{staticClass:"header-anchor",attrs:{href:"#_1-1-数据结构与算法"}},[t._v("#")]),t._v(" 1.1 数据结构与算法")]),t._v(" "),_("p",[t._v("首先我们来明确一下数据结构与算法的定义。")]),t._v(" "),_("p",[t._v("从广义上讲,数据结构就是指一组数据的存储结构,算法就是操作数据的一组方法。")]),t._v(" "),_("p",[t._v("从狭义上讲,也就是本书要讲的,是指某些经典的数据结构和算法,比如队列、栈、堆、二分查找、动态规划等。这些都是前人从实际操作场景中抽象出来的,经过非常多的求证和检验,可以高效地帮助我们解决实际的开发问题。")]),t._v(" "),_("h2",{attrs:{id:"如何学习"}},[_("a",{staticClass:"header-anchor",attrs:{href:"#如何学习"}},[t._v("#")]),t._v(" 如何学习")]),t._v(" "),_("p",[t._v("数据结构与算法涵盖的内容很多,要如何高效地系统性学习呢?")]),t._v(" "),_("p",[t._v("你并不需要掌握图里面的所有知识点。很多高级的数据结构与算法,比如二分图、最大流等,在我们平常的开发中很少会用到。")]),t._v(" "),_("p",[t._v("我总结了 19 个最常用、最基础的数据结构与算法,不管是应付面试还是工作需要,只要集中精力逐一攻克这 19 个知识点就足够了。")]),t._v(" "),_("div",{staticClass:"custom-block tip"},[_("ul",[_("li",[_("p",[_("strong",[t._v("8 个数据结构")]),t._v(":"),_("a",{attrs:{href:"../ds/0_array"}},[t._v("数组")]),t._v("、"),_("a",{attrs:{href:"../ds/1_linked_list"}},[t._v("链表")]),t._v("、"),_("a",{attrs:{href:"../ds/2_stack"}},[t._v("栈")]),t._v("、"),_("a",{attrs:{href:"../ds/3_queue"}},[t._v("队列")]),t._v("、"),_("a",{attrs:{href:"../ds/4_hash_table"}},[t._v("哈希表")]),t._v("、"),_("a",{attrs:{href:"../ds/5_string"}},[t._v("字符串")]),t._v("、"),_("a",{attrs:{href:"../ds/6_tree"}},[t._v("树")]),t._v("、"),_("a",{attrs:{href:"../ds/7_graph"}},[t._v("图")]),t._v(";")])]),t._v(" "),_("li",[_("p",[_("strong",[t._v("11 个算法")]),t._v(":"),_("a",{attrs:{href:"../algorithm/0_enumeration"}},[t._v("枚举算法")]),t._v("、"),_("a",{attrs:{href:"../algorithm/1_recursion"}},[t._v("递归算法")]),t._v("、"),_("a",{attrs:{href:"../algorithm/2_divide_conquer"}},[t._v("分治算法")]),t._v("、"),_("a",{attrs:{href:"../algorithm/3_backtracking"}},[t._v("回溯算法")]),t._v("、"),_("a",{attrs:{href:"../algorithm/4_greed"}},[t._v("贪心算法")]),t._v("、"),_("a",{attrs:{href:"../algorithm/5_dynamic_programming"}},[t._v("动态规划")]),t._v("、"),_("a",{attrs:{href:"../algorithm/6_bit"}},[t._v("位运算")]),t._v("、"),_("a",{attrs:{href:"../algorithm/7_sort"}},[t._v("排序算法")]),t._v("、"),_("a",{attrs:{href:"../algorithm/8_binary_search"}},[t._v("二分查找")]),t._v("、"),_("a",{attrs:{href:"../algorithm/9_two_pointer"}},[t._v("双指针")]),t._v("、"),_("a",{attrs:{href:"../algorithm/10_slide_window"}},[t._v("滑动窗口")]),t._v(";")])])])]),t._v(" "),_("p",[t._v("我对每个知识点都做了精讲,并配有对应的 LeetCode 题目,可以帮你打下扎实的基础,形成自己的知识体系。")]),t._v(" "),_("p",[t._v("想要对数据结构和算法有更全面的认识,可以查看这张思维导图,里面几乎涵盖了所有数据结构和算法书籍中都会讲到的知识点。")]),t._v(" "),_("p",[_("img",{attrs:{src:r(444),alt:""}})]),t._v(" "),_("h2",{attrs:{id:"如何刷题"}},[_("a",{staticClass:"header-anchor",attrs:{href:"#如何刷题"}},[t._v("#")]),t._v(" 如何刷题")]),t._v(" "),_("p",[t._v("LeetCode 题目虽然多,但如果分类别来看,其实也没多少,很多题目都是类似的套路和延伸。")]),t._v(" "),_("p",[t._v("对于计算机基础不扎实的同学,如果按照高频顺序刷题,通过每道题反向获取知识,这样的方法不是不可以,但效率可能不高,还会造成知识零散化,不能融会贯通。")]),t._v(" "),_("p",[t._v("建议采用“"),_("strong",[t._v("分类知识学习")]),t._v(" + "),_("strong",[t._v("核心题目")]),t._v(" + "),_("strong",[t._v("反复训练")]),t._v(" + "),_("strong",[t._v("融会贯通")]),t._v("”的系统性学习方法。")]),t._v(" "),_("p",[t._v("我整理了 "),_("a",{attrs:{href:"../outline/4_top_200_list"}},[_("strong",[t._v("高频面试题(按分类排序)")])]),t._v("和 "),_("a",{attrs:{href:"../outline/3_categories_list"}},[_("strong",[t._v("LeetCode 题解(分类)")])]),t._v(",建议先从这些题入手,分类别练习,点击标题可以跳转到LeetCode对应答题页面,点击题解(JS)可以查看我的答题思路和代码,遇到不熟悉的知识点可以去对应的知识点精讲学习。")]),t._v(" "),_("p",[t._v("掌握了这十几种常见算法类型的基本原理和思路,就对数据结构与算法有了一个大体的了解,即便出现很多新题,大多也能用现有知识体系去化解。")]),t._v(" "),_("p",[t._v("对算法模板、数据结构形成初步的认识之后,可以再结合 "),_("a",{attrs:{href:"../outline/5_frequency_list"}},[_("strong",[t._v("高频面试题(按频次排序)")])]),t._v("、"),_("a",{attrs:{href:"../outline/6_company_list"}},[_("strong",[t._v("高频面试题(按公司排序)")])]),t._v("、 "),_("a",{attrs:{href:"../outline/2_solution_list"}},[_("strong",[t._v("LeetCode 题解")])]),t._v(" 多加练习,逐渐提升自己对答题思路的掌握,和对内在原理的领悟。")]),t._v(" "),_("div",{staticClass:"custom-block tip"},[_("p",[t._v("电影《师父》里面有一句话:「每日挥刀五百下,这个数管住了我。」")])]),t._v(" "),_("p",[t._v("成功往往来自于,"),_("strong",[t._v("把简单、正确的事情重复做")]),t._v(",不相信也不追求快速而一劳永逸的必胜之法。")]),t._v(" "),_("p",[t._v("想要通关 LeetCode,没有什么神奇的方法,最重要还是自己动手刷题。")]),t._v(" "),_("p",[t._v("多花时间思考怎么 AC 手上的题目,少花时间幻想走了多少进度条。")])])}),[],!1,null,null,null);_.default=v.exports}}]); \ No newline at end of file diff --git a/assets/js/33.1fe42da9.js b/assets/js/33.51b65a31.js similarity index 89% rename from assets/js/33.1fe42da9.js rename to assets/js/33.51b65a31.js index 979fedca7d..c07526dcac 100644 --- a/assets/js/33.1fe42da9.js +++ b/assets/js/33.51b65a31.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[33],{462:function(t,s,a){"use strict";a.r(s);var i=a(30),r=Object(i.a)({},(function(){var t=this._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":this.$parent.slotKey}},[t("h1",{attrs:{id:"前端与工作"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#前端与工作"}},[this._v("#")]),this._v(" 前端与工作")]),this._v(" "),t("p",[this._v("本部分内容将带你走过前端工程师的学习路径,包括:")]),this._v(" "),t("p",[t("a",{attrs:{href:"./basic/1"}},[this._v("开始阅读 ->")])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[33],{461:function(t,s,a){"use strict";a.r(s);var i=a(30),r=Object(i.a)({},(function(){var t=this._self._c;return t("ContentSlotsDistributor",{attrs:{"slot-key":this.$parent.slotKey}},[t("h1",{attrs:{id:"前端与工作"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#前端与工作"}},[this._v("#")]),this._v(" 前端与工作")]),this._v(" "),t("p",[this._v("本部分内容将带你走过前端工程师的学习路径,包括:")]),this._v(" "),t("p",[t("a",{attrs:{href:"./basic/1"}},[this._v("开始阅读 ->")])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/34.63d3fafa.js b/assets/js/34.98fa8d33.js similarity index 99% rename from assets/js/34.63d3fafa.js rename to assets/js/34.98fa8d33.js index a46061df9a..963dc3809e 100644 --- a/assets/js/34.63d3fafa.js +++ b/assets/js/34.98fa8d33.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[34],{461:function(t,s,a){"use strict";a.r(s);var n=a(30),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"javascript-问题列表"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#javascript-问题列表"}},[t._v("#")]),t._v(" JavaScript 问题列表")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_1-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-输出是什么"}},[t._v("#")]),t._v(" 1. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Lydia")]),t._v(" 和 "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Lydia")]),t._v(" 和 "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")]),t._v(" 和 "),s("code",[t._v("21")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(" 和 "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("在函数内部,我们首先通过 "),s("code",[t._v("var")]),t._v(" 关键字声明了 "),s("code",[t._v("name")]),t._v(" 变量。这意味着变量被提升了(内存空间在创建阶段就被设置好了),直到程序运行到定义变量位置之前默认值都是 "),s("code",[t._v("undefined")]),t._v("。因为当我们打印 "),s("code",[t._v("name")]),t._v(" 变量时还没有执行到定义变量的位置,因此变量的值保持为 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("let")]),t._v(" 和 "),s("code",[t._v("const")]),t._v(" 关键字声明的变量也会提升,但是和 "),s("code",[t._v("var")]),t._v(" 不同,它们不会被"),s("i",[t._v("初始化")]),t._v("。在我们声明(初始化)之前是不能访问它们的。这个行为被称之为暂时性死区。当我们试图在声明之前访问它们时,JavaScript 将会抛出一个 "),s("code",[t._v("ReferenceError")]),t._v(" 错误。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_2-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-输出是什么"}},[t._v("#")]),t._v(" 2. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("0 1 2")]),t._v(" 和 "),s("code",[t._v("0 1 2")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("0 1 2")]),t._v(" 和 "),s("code",[t._v("3 3 3")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("3 3 3")]),t._v(" 和 "),s("code",[t._v("0 1 2")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("由于 JavaScript 的事件循环,"),s("code",[t._v("setTimeout")]),t._v(" 回调会在"),s("em",[t._v("遍历结束后")]),t._v("才执行。因为在第一个遍历中遍历 "),s("code",[t._v("i")]),t._v(" 是通过 "),s("code",[t._v("var")]),t._v(" 关键字声明的,所以这个值是全局作用域下的。在遍历过程中,我们通过一元操作符 "),s("code",[t._v("++")]),t._v(" 来每次递增 "),s("code",[t._v("i")]),t._v(" 的值。当 "),s("code",[t._v("setTimeout")]),t._v(" 回调执行的时候,"),s("code",[t._v("i")]),t._v(" 的值等于 3。")]),t._v(" "),s("p",[t._v("在第二个遍历中,遍历 "),s("code",[t._v("i")]),t._v(" 是通过 "),s("code",[t._v("let")]),t._v(" 关键字声明的:通过 "),s("code",[t._v("let")]),t._v(" 和 "),s("code",[t._v("const")]),t._v(" 关键字声明的变量是拥有块级作用域(指的是任何在 {} 中的内容)。在每次的遍历过程中,"),s("code",[t._v("i")]),t._v(" 都有一个新值,并且每个值都在循环内的作用域中。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_3-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-输出是什么"}},[t._v("#")]),t._v(" 3. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" shape "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("radius")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("diameter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("radius "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("perimeter")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" Math"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("PI")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("radius"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nshape"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("diameter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nshape"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("perimeter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("20")]),t._v(" and "),s("code",[t._v("62.83185307179586")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("20")]),t._v(" and "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("20")]),t._v(" and "),s("code",[t._v("63")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("NaN")]),t._v(" and "),s("code",[t._v("63")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("注意 "),s("code",[t._v("diameter")]),t._v(" 的值是一个常规函数,但是 "),s("code",[t._v("perimeter")]),t._v(" 的值是一个箭头函数。")]),t._v(" "),s("p",[t._v("对于箭头函数,"),s("code",[t._v("this")]),t._v(" 关键字指向的是它当前周围作用域(简单来说是包含箭头函数的常规函数,如果没有常规函数的话就是全局对象),这个行为和常规函数不同。这意味着当我们调用 "),s("code",[t._v("perimeter")]),t._v(" 时,"),s("code",[t._v("this")]),t._v(" 不是指向 "),s("code",[t._v("shape")]),t._v(" 对象,而是它的周围作用域(在例子中是 "),s("code",[t._v("window")]),t._v(")。")]),t._v(" "),s("p",[t._v("在 "),s("code",[t._v("window")]),t._v(" 中没有 "),s("code",[t._v("radius")]),t._v(" 这个属性,因此返回 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_4-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-输出是什么"}},[t._v("#")]),t._v(" 4. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" and "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")]),t._v(" and "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("false")]),t._v(" and "),s("code",[t._v("false")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("一元操作符加号尝试将 bool 转为 number。"),s("code",[t._v("true")]),t._v(" 转换为 number 的话为 "),s("code",[t._v("1")]),t._v(","),s("code",[t._v("false")]),t._v(" 为 "),s("code",[t._v("0")]),t._v("。")]),t._v(" "),s("p",[t._v("字符串 "),s("code",[t._v("'Lydia'")]),t._v(" 是一个真值,真值取反那么就返回 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_5-哪一个是正确的"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_5-哪一个是正确的"}},[t._v("#")]),t._v(" 5. 哪一个是正确的?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" bird "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("size")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"small"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" mouse "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Mickey"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("small")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("mouse.bird.size")]),t._v("是无效的")]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("mouse[bird.size]")]),t._v("是无效的")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('mouse[bird["size"]]')]),t._v("是无效的")]),t._v(" "),s("li",[t._v("D: 以上三个选项都是有效的")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-2"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-2"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("在 JavaScript 中,所有对象的 keys 都是字符串(除非对象是 Symbol)。尽管我们可能不会定义它们为字符串,但它们在底层总会被转换为字符串。")]),t._v(" "),s("p",[t._v("当我们使用括号语法时([]),JavaScript 会解释(或者 unboxes)语句。它首先看到第一个开始括号 "),s("code",[t._v("[")]),t._v(" 并继续前进直到找到结束括号 "),s("code",[t._v("]")]),t._v("。只有这样,它才会计算语句的值。")]),t._v(" "),s("p",[s("code",[t._v("mouse[bird.size]")]),t._v(":首先计算 "),s("code",[t._v("bird.size")]),t._v(",这会得到 "),s("code",[t._v("small")]),t._v("。"),s("code",[t._v('mouse["small"]')]),t._v(" 返回 "),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[t._v("然后使用点语法的话,上面这一切都不会发生。"),s("code",[t._v("mouse")]),t._v(" 没有 "),s("code",[t._v("bird")]),t._v(" 这个 key,这也就意味着 "),s("code",[t._v("mouse.bird")]),t._v(" 是 "),s("code",[t._v("undefined")]),t._v("。然后当我们使用点语法 "),s("code",[t._v("mouse.bird.size")]),t._v(" 时,因为 "),s("code",[t._v("mouse.bird")]),t._v(" 是 "),s("code",[t._v("undefined")]),t._v(",这也就变成了 "),s("code",[t._v("undefined.size")]),t._v("。这个行为是无效的,并且会抛出一个错误类似 "),s("code",[t._v('Cannot read property "size" of undefined')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_6-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_6-输出是什么"}},[t._v("#")]),t._v(" 6. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" c "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("greeting")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hey!"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" d"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nd "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" c"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("greeting "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hello"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("d"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("greeting"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Hello")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-3"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-3"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("在 JavaScript 中,当设置两个对象彼此相等时,它们会通过"),s("em",[t._v("引用")]),t._v("进行交互。")]),t._v(" "),s("p",[t._v("首先,变量 "),s("code",[t._v("c")]),t._v(" 的值是一个对象。接下来,我们给 "),s("code",[t._v("d")]),t._v(" 分配了一个和 "),s("code",[t._v("c")]),t._v(" 对象相同的引用。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/ko5k0fs.png",width:"200"}}),t._v(" "),s("p",[t._v("因此当我们改变其中一个对象时,其实是改变了所有的对象。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_7-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_7-输出是什么"}},[t._v("#")]),t._v(" 7. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" b "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Number")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" c "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("b "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" c"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-2"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-2"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("new Number()")]),t._v(" 是一个内建的函数构造器。虽然它看着像是一个 number,但它实际上并不是一个真实的 number:它有一堆额外的功能并且它是一个对象。")]),t._v(" "),s("p",[t._v("当我们使用 "),s("code",[t._v("==")]),t._v(" 操作符时,它只会检查两者是否拥有相同的"),s("em",[t._v("值")]),t._v("。因为它们的值都是 "),s("code",[t._v("3")]),t._v(",因此返回 "),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[t._v("然后,当我们使用 "),s("code",[t._v("===")]),t._v(" 操作符时,两者的值以及"),s("em",[t._v("类型")]),t._v("都应该是相同的。"),s("code",[t._v("new Number()")]),t._v(" 是一个对象而不是 number,因此返回 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_8-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_8-输出是什么"}},[t._v("#")]),t._v(" 8. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Chameleon")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("static")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("colorChange")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("newColor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("newColor "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" newColor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("newColor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" newColor "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"green"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("newColor "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" newColor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" freddie "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Chameleon")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("newColor")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"purple"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nfreddie"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("colorChange")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"orange"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("orange")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("purple")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("green")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-2"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-2"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("colorChange")]),t._v(" 是一个静态方法。静态方法被设计为只能被创建它们的构造器使用(也就是 "),s("code",[t._v("Chameleon")]),t._v("),并且不能传递给实例。因为 "),s("code",[t._v("freddie")]),t._v(" 是一个实例,静态方法不能被实例使用,因此抛出了 "),s("code",[t._v("TypeError")]),t._v(" 错误。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_9-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_9-输出是什么"}},[t._v("#")]),t._v(" 9. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" greeting"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ngreetign "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Typo!")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("greetign"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("{}")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("ReferenceError: greetign is not defined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-4"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-4"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("代码打印出了一个对象,这是因为我们在全局对象上创建了一个空对象!当我们将 "),s("code",[t._v("greeting")]),t._v(" 写错成 "),s("code",[t._v("greetign")]),t._v(" 时,JS 解释器实际在上浏览器中将它视为 "),s("code",[t._v("global.greetign = {}")]),t._v("(或者 "),s("code",[t._v("window.greetign = {}")]),t._v(")。")]),t._v(" "),s("p",[t._v('为了避免这个为题,我们可以使用 `"use strict"。这能确保当你声明变量时必须赋值。')]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_10-当我们这么做时-会发生什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_10-当我们这么做时-会发生什么"}},[t._v("#")]),t._v(" 10. 当我们这么做时,会发生什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("bark")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Woof!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nbark"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("animal "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"dog"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 正常运行!")]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("SyntaxError")]),t._v(". 你不能通过这种方式给函数增加属性。")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-5"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-5"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("这在 JavaScript 中是可以的,因为函数是对象!(除了基本类型之外其他都是对象)")]),t._v(" "),s("p",[t._v("函数是一个特殊的对象。你写的这个代码其实不是一个实际的函数。函数是一个拥有属性的对象,并且属性也可被调用。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_11-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_11-输出是什么"}},[t._v("#")]),t._v(" 11. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("firstName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" lastName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("firstName "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" firstName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastName "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" lastName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" member "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nPerson"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("getFullName")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("firstName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFullName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Lydia Hallie")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-6"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-6"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("你不能像常规对象那样,给构造函数添加属性。如果你想一次性给所有实例添加特性,你应该使用原型。因此本例中,使用如下方式:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("getFullName")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("firstName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("这才会使 "),s("code",[t._v("member.getFullName()")]),t._v(" 起作用。为什么这么做有益的?假设我们将这个方法添加到构造函数本身里。也许不是每个 "),s("code",[t._v("Person")]),t._v(" 实例都需要这个方法。这将浪费大量内存空间,因为它们仍然具有该属性,这将占用每个实例的内存空间。相反,如果我们只将它添加到原型中,那么它只存在于内存中的一个位置,但是所有实例都可以访问它!")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_12-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_12-输出是什么"}},[t._v("#")]),t._v(" 12. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("firstName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" lastName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("firstName "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" firstName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastName "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" lastName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" lydia "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" sarah "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sarah"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Smith"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("lydia"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sarah"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),t._v(" and "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),t._v(" and "),s("code",[t._v('Person {firstName: "Sarah", lastName: "Smith"}')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),t._v(" and "),s("code",[t._v("{}")])]),t._v(" "),s("li",[t._v("D:"),s("code",[t._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),t._v(" and "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-7"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-7"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("对于 "),s("code",[t._v("sarah")]),t._v(",我们没有使用 "),s("code",[t._v("new")]),t._v(" 关键字。当使用 "),s("code",[t._v("new")]),t._v(" 时,"),s("code",[t._v("this")]),t._v(" 引用我们创建的空对象。当未使用 "),s("code",[t._v("new")]),t._v(" 时,"),s("code",[t._v("this")]),t._v(" 引用的是"),s("strong",[t._v("全局对象")]),t._v("(global object)。")]),t._v(" "),s("p",[t._v("我们说 "),s("code",[t._v("this.firstName")]),t._v(" 等于 "),s("code",[t._v('"Sarah"')]),t._v(",并且 "),s("code",[t._v("this.lastName")]),t._v(" 等于 "),s("code",[t._v('"Smith"')]),t._v("。实际上我们做的是,定义了 "),s("code",[t._v("global.firstName = 'Sarah'")]),t._v(" 和 "),s("code",[t._v("global.lastName = 'Smith'")]),t._v("。而 "),s("code",[t._v("sarah")]),t._v(" 本身是 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_13-事件传播的三个阶段是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_13-事件传播的三个阶段是什么"}},[t._v("#")]),t._v(" 13. 事件传播的三个阶段是什么?")]),t._v(" "),s("ul",[s("li",[t._v("A: Target > Capturing > Bubbling")]),t._v(" "),s("li",[t._v("B: Bubbling > Target > Capturing")]),t._v(" "),s("li",[t._v("C: Target > Bubbling > Capturing")]),t._v(" "),s("li",[t._v("D: Capturing > Target > Bubbling")])]),t._v(" "),s("h4",{attrs:{id:"答案-d-3"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-3"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("在"),s("strong",[t._v("捕获")]),t._v("(capturing)阶段中,事件从祖先元素向下传播到目标元素。当事件达到"),s("strong",[t._v("目标")]),t._v("(target)元素后,"),s("strong",[t._v("冒泡")]),t._v("(bubbling)才开始。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/N18oRgd.png",width:"200"}}),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_14-所有对象都有原型。"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_14-所有对象都有原型。"}},[t._v("#")]),t._v(" 14. 所有对象都有原型。")]),t._v(" "),s("ul",[s("li",[t._v("A: 对")]),t._v(" "),s("li",[t._v("B: 错")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-2"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-2"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("除了"),s("strong",[t._v("基本对象")]),t._v("(base object),所有对象都有原型。基本对象可以访问一些方法和属性,比如 "),s("code",[t._v(".toString")]),t._v("。这就是为什么你可以使用内置的 JavaScript 方法!所有这些方法在原型上都是可用的。虽然 JavaScript 不能直接在对象上找到这些方法,但 JavaScript 会沿着原型链找到它们,以便于你使用。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_15-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_15-输出是什么"}},[t._v("#")]),t._v(" 15. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" b")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"2"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"12"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("3")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-3"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-3"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("JavaScript 是一种"),s("strong",[t._v("动态类型语言")]),t._v(":我们不指定某些变量的类型。值可以在你不知道的情况下自动转换成另一种类型,这种类型称为"),s("strong",[t._v("隐式类型转换")]),t._v("(implicit type coercion)。"),s("strong",[t._v("Coercion")]),t._v(" 是指将一种类型转换为另一种类型。")]),t._v(" "),s("p",[t._v("在本例中,JavaScript 将数字 "),s("code",[t._v("1")]),t._v(" 转换为字符串,以便函数有意义并返回一个值。在数字类型("),s("code",[t._v("1")]),t._v(")和字符串类型("),s("code",[t._v("'2'")]),t._v(")相加时,该数字被视为字符串。我们可以连接字符串,比如 "),s("code",[t._v('"Hello" + "World"')]),t._v(",这里发生的是 "),s("code",[t._v('"1" + "2"')]),t._v(",它返回 "),s("code",[t._v('"12"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_16-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_16-输出是什么"}},[t._v("#")]),t._v(" 16. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" number "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("number"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("0")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("0")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-4"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-4"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("一元"),s("strong",[t._v("后自增")]),t._v("运算符 "),s("code",[t._v("++")]),t._v(":")]),t._v(" "),s("ol",[s("li",[t._v("返回值(返回 "),s("code",[t._v("0")]),t._v(")")]),t._v(" "),s("li",[t._v("值自增(number 现在是 "),s("code",[t._v("1")]),t._v(")")])]),t._v(" "),s("p",[t._v("一元"),s("strong",[t._v("前自增")]),t._v("运算符 "),s("code",[t._v("++")]),t._v(":")]),t._v(" "),s("ol",[s("li",[t._v("值自增(number 现在是 "),s("code",[t._v("2")]),t._v(")")]),t._v(" "),s("li",[t._v("返回值(返回 "),s("code",[t._v("2")]),t._v(")")])]),t._v(" "),s("p",[t._v("结果是 "),s("code",[t._v("0 2 2")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_17-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_17-输出是什么"}},[t._v("#")]),t._v(" 17. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getPersonInfo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" three")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("three"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\ngetPersonInfo"),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" is ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" years old")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Lydia"')]),t._v(" "),s("code",[t._v("21")]),t._v(" "),s("code",[t._v('["", " is ", " years old"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["", " is ", " years old"]')]),t._v(" "),s("code",[t._v('"Lydia"')]),t._v(" "),s("code",[t._v("21")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"Lydia"')]),t._v(" "),s("code",[t._v('["", " is ", " years old"]')]),t._v(" "),s("code",[t._v("21")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-3"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-3"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("如果使用标记模板字面量,第一个参数的值总是包含字符串的数组。其余的参数获取的是传递的表达式的值!")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_18-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_18-输出是什么"}},[t._v("#")]),t._v(" 18. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("checkAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("data")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"You are an adult!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"You are still an adult."')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Hmm.. You don't have an age I guess")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("checkAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("You are an adult!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("You are still an adult.")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Hmm.. You don't have an age I guess")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-5"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-5"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("在测试相等性时,基本类型通过它们的值(value)进行比较,而对象通过它们的引用(reference)进行比较。JavaScript 检查对象是否具有对内存中相同位置的引用。")]),t._v(" "),s("p",[t._v("题目中我们正在比较的两个对象不是同一个引用:作为参数传递的对象引用的内存位置,与用于判断相等的对象所引用的内存位置并不同。")]),t._v(" "),s("p",[t._v("这也是 "),s("code",[t._v("{ age: 18 } === { age: 18 }")]),t._v(" 和 "),s("code",[t._v("{ age: 18 } == { age: 18 }")]),t._v(" 都返回 "),s("code",[t._v("false")]),t._v(" 的原因。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_19-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_19-输出是什么"}},[t._v("#")]),t._v(" 19. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("args")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" args"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"number"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"array"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"object"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"NaN"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-6"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-6"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("扩展运算符("),s("code",[t._v("...args")]),t._v(")会返回实参组成的数组。而数组是对象,因此 "),s("code",[t._v("typeof args")]),t._v(" 返回 "),s("code",[t._v('"object"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_20-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_20-输出是什么"}},[t._v("#")]),t._v(" 20. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"use strict"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("21")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-7"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-7"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用 "),s("code",[t._v('"use strict"')]),t._v(",你可以确保不会意外地声明全局变量。我们从来没有声明变量 "),s("code",[t._v("age")]),t._v(",因为我们使用 "),s("code",[t._v('"use strict"')]),t._v(",它将抛出一个引用错误。如果我们不使用 "),s("code",[t._v('"use strict"')]),t._v(",它就会工作,因为属性 "),s("code",[t._v("age")]),t._v(" 会被添加到全局对象中了。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_21-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_21-输出是什么"}},[t._v("#")]),t._v(" 21. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("eval")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"10*10+5"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("105")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"105"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"10*10+5"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-8"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-8"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("代码以字符串形式传递进来,"),s("code",[t._v("eval")]),t._v(" 对其求值。如果它是一个表达式,就像本例中那样,它对表达式求值。表达式是 "),s("code",[t._v("10 * 10 + 5")]),t._v("。这将返回数字 "),s("code",[t._v("105")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_22-cool-secret-可访问多长时间"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_22-cool-secret-可访问多长时间"}},[t._v("#")]),t._v(" 22. cool_secret 可访问多长时间?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("sessionStorage"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setItem")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"cool_secret"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("123")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 永远,数据不会丢失。")]),t._v(" "),s("li",[t._v("B: 当用户关掉标签页时。")]),t._v(" "),s("li",[t._v("C: 当用户关掉整个浏览器,而不只是关掉标签页。")]),t._v(" "),s("li",[t._v("D: 当用户关闭电脑时。")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-4"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-4"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("关闭 "),s("strong",[t._v("tab 标签页")]),t._v(" 后,"),s("code",[t._v("sessionStorage")]),t._v(" 存储的数据才会删除。")]),t._v(" "),s("p",[t._v("如果使用 "),s("code",[t._v("localStorage")]),t._v(",那么数据将永远在那里,除非调用了 "),s("code",[t._v("localStorage.clear()")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_23-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_23-输出是什么"}},[t._v("#")]),t._v(" 23. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("8")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("8")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("10")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-5"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-5"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("使用 "),s("code",[t._v("var")]),t._v(" 关键字,你可以用相同的名称声明多个变量。然后变量将保存最新的值。")]),t._v(" "),s("p",[t._v("你不能使用 "),s("code",[t._v("let")]),t._v(" 或 "),s("code",[t._v("const")]),t._v(" 来实现这一点,因为它们是块作用域的。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_24-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_24-输出是什么"}},[t._v("#")]),t._v(" 24. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" obj "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" set "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Set")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nobj"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("hasOwnProperty")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nobj"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("hasOwnProperty")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nset"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("has")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nset"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("has")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-8"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-8"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("所有对象的键(不包括 Symbol)在底层都是字符串,即使你自己没有将其作为字符串输入。这就是为什么 "),s("code",[t._v("obj.hasOwnProperty('1')")]),t._v(" 也返回 "),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[t._v("对于集合,它不是这样工作的。在我们的集合中没有 "),s("code",[t._v("'1'")]),t._v(":"),s("code",[t._v("set.has('1')")]),t._v(" 返回 "),s("code",[t._v("false")]),t._v("。它有数字类型为 "),s("code",[t._v("1")]),t._v(","),s("code",[t._v("set.has(1)")]),t._v(" 返回 "),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_25-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_25-输出是什么"}},[t._v("#")]),t._v(" 25. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" obj "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("a")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"one"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("b")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"two"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("a")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"three"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("obj"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ a: "one", b: "two" }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ b: "two", a: "three" }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ a: "three", b: "two" }')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-9"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-9"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("如果你有两个名称相同的键,则键会被替换掉。它仍然位于第一个键出现的位置,但是值是最后出现那个键的值。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_26-javascript-全局执行上下文为你做了两件事-全局对象和-this-关键字。"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_26-javascript-全局执行上下文为你做了两件事-全局对象和-this-关键字。"}},[t._v("#")]),t._v(" 26. JavaScript 全局执行上下文为你做了两件事:全局对象和 this 关键字。")]),t._v(" "),s("ul",[s("li",[t._v("A: 对")]),t._v(" "),s("li",[t._v("B: 错")]),t._v(" "),s("li",[t._v("C: 看情况")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-9"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-9"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("基本执行上下文是全局执行上下文:它是代码中随处可访问的内容。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_27-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_27-输出是什么"}},[t._v("#")]),t._v(" 27. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("continue")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("4")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("4")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-10"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-10"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("如果某个条件返回 "),s("code",[t._v("true")]),t._v(",则 "),s("code",[t._v("continue")]),t._v(" 语句跳过本次迭代。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_28-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_28-输出是什么"}},[t._v("#")]),t._v(" 28. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("String")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("giveLydiaPizza")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Just give Lydia pizza already!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nname"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("giveLydiaPizza")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Just give Lydia pizza already!"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("TypeError: not a function")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-10"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-10"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("String")]),t._v(" 是内置的构造函数,我们可以向它添加属性。我只是在它的原型中添加了一个方法。基本类型字符串被自动转换为字符串对象,由字符串原型函数生成。因此,所有 string(string 对象) 都可以访问该方法!")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_29-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_29-输出是什么"}},[t._v("#")]),t._v(" 29. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" b "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("key")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" c "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("key")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\na"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("123")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\na"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("c"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("456")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("123")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("456")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-6"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-6"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("对象的键被自动转换为字符串。我们试图将一个对象 "),s("code",[t._v("b")]),t._v(" 设置为对象 "),s("code",[t._v("a")]),t._v(" 的键,且相应的值为 "),s("code",[t._v("123")]),t._v("。")]),t._v(" "),s("p",[t._v("然而,当字符串化一个对象时,它会变成 "),s("code",[t._v('"[object Object]"')]),t._v("。因此这里说的是,"),s("code",[t._v('a["[object Object]"] = 123')]),t._v("。然后,我们再一次做了同样的事情,"),s("code",[t._v("c")]),t._v(" 是另外一个对象,这里也有隐式字符串化,于是,"),s("code",[t._v('a["[object Object]"] = 456')]),t._v("。")]),t._v(" "),s("p",[t._v("然后,我们打印 "),s("code",[t._v("a[b]")]),t._v(",也就是 "),s("code",[t._v('a["[object Object]"]')]),t._v("。之前刚设置为 "),s("code",[t._v("456")]),t._v(",因此返回的是 "),s("code",[t._v("456")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_30-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_30-输出是什么"}},[t._v("#")]),t._v(" 30. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("foo")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"First"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("bar")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Second"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("baz")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Third"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("bar")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("foo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("baz")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("First")]),t._v(" "),s("code",[t._v("Second")]),t._v(" "),s("code",[t._v("Third")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("First")]),t._v(" "),s("code",[t._v("Third")]),t._v(" "),s("code",[t._v("Second")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Second")]),t._v(" "),s("code",[t._v("First")]),t._v(" "),s("code",[t._v("Third")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Second")]),t._v(" "),s("code",[t._v("Third")]),t._v(" "),s("code",[t._v("First")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-7"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-7"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("我们有一个 "),s("code",[t._v("setTimeout")]),t._v(" 函数,并首先调用它。然而,它是最后打印日志的。")]),t._v(" "),s("p",[t._v("这是因为在浏览器中,我们不仅有运行时引擎,还有一个叫做 "),s("code",[t._v("WebAPI")]),t._v(" 的东西。"),s("code",[t._v("WebAPI")]),t._v(" 提供了 "),s("code",[t._v("setTimeout")]),t._v(" 函数,也包含其他的,例如 DOM。")]),t._v(" "),s("p",[t._v("将 "),s("em",[t._v("callback")]),t._v(" 推送到 WebAPI 后,"),s("code",[t._v("setTimeout")]),t._v(" 函数本身 (但不是回调!) 将从栈中弹出。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/X5wsHOg.png",width:"200"}}),t._v(" "),s("p",[t._v("现在,"),s("code",[t._v("foo")]),t._v(" 被调用,打印 "),s("code",[t._v('"First"')]),t._v("。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/Pvc0dGq.png",width:"200"}}),t._v(" "),s("p",[s("code",[t._v("foo")]),t._v(" 从栈中弹出,"),s("code",[t._v("baz")]),t._v(" 被调用。打印 "),s("code",[t._v('"Third"')]),t._v("。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/WhA2bCP.png",width:"200"}}),t._v(" "),s("p",[t._v("WebAPI 不能随时向栈内添加内容。相反,它将回调函数推到名为 "),s("em",[t._v("queue")]),t._v(" 的地方。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/NSnDZmU.png",width:"200"}}),t._v(" "),s("p",[t._v("这就是事件循环开始工作的地方。一个"),s("strong",[t._v("事件循环")]),t._v("查看栈和任务队列。如果栈是空的,它接受队列上的第一个元素并将其推入栈。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/uyiScAI.png",width:"200"}}),t._v(" "),s("p",[s("code",[t._v("bar")]),t._v(" 被调用,打印 "),s("code",[t._v('"Second"')]),t._v(",然后它被栈弹出。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_31-当点击按钮时-event-target-是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_31-当点击按钮时-event-target-是什么"}},[t._v("#")]),t._v(" 31. 当点击按钮时,event.target 是什么?")]),t._v(" "),s("div",{staticClass:"language-html extra-class"},[s("pre",{pre:!0,attrs:{class:"language-html"}},[s("code",[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("<")]),t._v("div")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token special-attr"}},[s("span",{pre:!0,attrs:{class:"token attr-name"}},[t._v("onclick")]),s("span",{pre:!0,attrs:{class:"token attr-value"}},[s("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')]),s("span",{pre:!0,attrs:{class:"token value javascript language-javascript"}},[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'first div'")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')])])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(">")])]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("<")]),t._v("div")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token special-attr"}},[s("span",{pre:!0,attrs:{class:"token attr-name"}},[t._v("onclick")]),s("span",{pre:!0,attrs:{class:"token attr-value"}},[s("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')]),s("span",{pre:!0,attrs:{class:"token value javascript language-javascript"}},[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'second div'")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')])])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(">")])]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("<")]),t._v("button")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token special-attr"}},[s("span",{pre:!0,attrs:{class:"token attr-name"}},[t._v("onclick")]),s("span",{pre:!0,attrs:{class:"token attr-value"}},[s("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')]),s("span",{pre:!0,attrs:{class:"token value javascript language-javascript"}},[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'button'")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')])])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(">")])]),t._v("Click!"),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("")])]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("")])]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: Outer "),s("code",[t._v("div")])]),t._v(" "),s("li",[t._v("B: Inner "),s("code",[t._v("div")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("button")])]),t._v(" "),s("li",[t._v("D: 一个包含所有嵌套元素的数组。")])]),t._v(" "),s("h4",{attrs:{id:"答案-c-11"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-11"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("导致事件的最深嵌套的元素是事件的 target。你可以通过 "),s("code",[t._v("event.stopPropagation")]),t._v(" 来停止冒泡。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_32-当您单击该段落时-日志输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_32-当您单击该段落时-日志输出是什么"}},[t._v("#")]),t._v(" 32. 当您单击该段落时,日志输出是什么?")]),t._v(" "),s("div",{staticClass:"language-html extra-class"},[s("pre",{pre:!0,attrs:{class:"language-html"}},[s("code",[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("<")]),t._v("div")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token special-attr"}},[s("span",{pre:!0,attrs:{class:"token attr-name"}},[t._v("onclick")]),s("span",{pre:!0,attrs:{class:"token attr-value"}},[s("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')]),s("span",{pre:!0,attrs:{class:"token value javascript language-javascript"}},[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'div'")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')])])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(">")])]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("<")]),t._v("p")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token special-attr"}},[s("span",{pre:!0,attrs:{class:"token attr-name"}},[t._v("onclick")]),s("span",{pre:!0,attrs:{class:"token attr-value"}},[s("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')]),s("span",{pre:!0,attrs:{class:"token value javascript language-javascript"}},[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'p'")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')])])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(">")])]),t._v("Click here!"),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("")])]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("p")]),t._v(" "),s("code",[t._v("div")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("div")]),t._v(" "),s("code",[t._v("p")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("p")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("div")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-11"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-11"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("如果我们点击 "),s("code",[t._v("p")]),t._v(",我们会看到两个日志:"),s("code",[t._v("p")]),t._v(" 和 "),s("code",[t._v("div")]),t._v("。在事件传播期间,有三个阶段:捕获、目标和冒泡。默认情况下,事件处理程序在冒泡阶段执行(除非将 "),s("code",[t._v("useCapture")]),t._v(" 设置为 "),s("code",[t._v("true")]),t._v(")。它从嵌套最深的元素向外传播。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_33-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_33-输出是什么"}},[t._v("#")]),t._v(" 33. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" is ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("call")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("bind")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("undefined is 21")]),t._v(" "),s("code",[t._v("Lydia is 21")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("function")]),t._v(" "),s("code",[t._v("function")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Lydia is 21")]),t._v(" "),s("code",[t._v("Lydia is 21")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Lydia is 21")]),t._v(" "),s("code",[t._v("function")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-4"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-4"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("使用这两种方法,我们都可以传递我们希望 "),s("code",[t._v("this")]),t._v(" 关键字引用的对象。但是,"),s("code",[t._v(".call")]),t._v(" 是"),s("strong",[t._v("立即执行")]),t._v("的。")]),t._v(" "),s("p",[s("code",[t._v(".bind")]),t._v(" 返回函数的"),s("strong",[t._v("副本")]),t._v(",但带有绑定上下文!它不是立即执行的。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_34-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_34-输出是什么"}},[t._v("#")]),t._v(" 34. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"object"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"number"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"function"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"undefined"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-8"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-8"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("sayHi")]),t._v(" 方法返回的是立即执行函数 (IIFE) 的返回值。此立即执行函数的返回值是 "),s("code",[t._v("0")]),t._v(",类型是 "),s("code",[t._v("number")])]),t._v(" "),s("p",[t._v("参考:只有 7 种内置类型:"),s("code",[t._v("null")]),t._v(","),s("code",[t._v("undefined")]),t._v(","),s("code",[t._v("boolean")]),t._v(","),s("code",[t._v("number")]),t._v(","),s("code",[t._v("string")]),t._v(","),s("code",[t._v("object")]),t._v(", "),s("code",[t._v("symbol")]),t._v(" 和 "),s("code",[t._v("bigint")]),t._v("。"),s("code",[t._v("function")]),t._v(" 不是一种类型,函数是对象,它的类型是"),s("code",[t._v("object")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_35-下面哪些值是-falsy"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_35-下面哪些值是-falsy"}},[t._v("#")]),t._v(" 35. 下面哪些值是 falsy?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Number")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('" "')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Boolean")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("undefined")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("0")]),t._v(", "),s("code",[t._v("''")]),t._v(", "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("0")]),t._v(", "),s("code",[t._v("new Number(0)")]),t._v(", "),s("code",[t._v("''")]),t._v(", "),s("code",[t._v("new Boolean(false)")]),t._v(", "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("0")]),t._v(", "),s("code",[t._v("''")]),t._v(", "),s("code",[t._v("new Boolean(false)")]),t._v(", "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: All of them are falsy")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-12"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-12"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("只有 8 种 "),s("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy",target:"_blank",rel:"noopener noreferrer"}},[t._v("falsy"),s("OutboundLink")],1),t._v(" 值:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("undefined")])]),t._v(" "),s("li",[s("code",[t._v("null")])]),t._v(" "),s("li",[s("code",[t._v("NaN")])]),t._v(" "),s("li",[s("code",[t._v("false")])]),t._v(" "),s("li",[s("code",[t._v("''")]),t._v(" (empty string)")]),t._v(" "),s("li",[s("code",[t._v("0")])]),t._v(" "),s("li",[s("code",[t._v("-0")])]),t._v(" "),s("li",[s("code",[t._v("0n")]),t._v(" (BigInt(0))")])]),t._v(" "),s("p",[s("code",[t._v("Function")]),t._v(" 构造函数,比如 "),s("code",[t._v("new Number")]),t._v(" 和 "),s("code",[t._v("new Boolean")]),t._v(",是 "),s("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy",target:"_blank",rel:"noopener noreferrer"}},[t._v("truthy"),s("OutboundLink")],1),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_36-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_36-输出是什么"}},[t._v("#")]),t._v(" 36. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"number"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"string"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"object"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"undefined"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-9"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-9"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("typeof 1")]),t._v(" 返回 "),s("code",[t._v('"number"')]),t._v("。\n"),s("code",[t._v('typeof "number"')]),t._v(" 返回 "),s("code",[t._v('"string"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_37-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_37-输出是什么"}},[t._v("#")]),t._v(" 37. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" numbers "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nnumbers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("numbers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[1, 2, 3, 7 x null, 11]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[1, 2, 3, 11]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[1, 2, 3, 7 x empty, 11]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-12"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-12"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v('当你为数组设置超过数组长度的值的时候,JavaScript 会创建名为 "empty slots" 的东西。它们的值实际上是 '),s("code",[t._v("undefined")]),t._v("。你会看到以下场景:")]),t._v(" "),s("p",[s("code",[t._v("[1, 2, 3, 7 x empty, 11]")])]),t._v(" "),s("p",[t._v("这取决于你的运行环境(每个浏览器,以及 node 环境,都有可能不同)")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_38-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_38-输出是什么"}},[t._v("#")]),t._v(" 38. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("try")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("throw")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("catch")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-13"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-13"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("catch")]),t._v(" 代码块接收参数 "),s("code",[t._v("x")]),t._v("。当我们传递参数时,这与之前定义的变量 "),s("code",[t._v("x")]),t._v(" 不同。这个 "),s("code",[t._v("x")]),t._v(" 是属于 "),s("code",[t._v("catch")]),t._v(" 块级作用域的。")]),t._v(" "),s("p",[t._v("然后,我们将块级作用域中的变量赋值为 "),s("code",[t._v("1")]),t._v(",同时也设置了变量 "),s("code",[t._v("y")]),t._v(" 的值。现在,我们打印块级作用域中的变量 "),s("code",[t._v("x")]),t._v(",值为 "),s("code",[t._v("1")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("catch")]),t._v(" 块之外的变量 "),s("code",[t._v("x")]),t._v(" 的值仍为 "),s("code",[t._v("undefined")]),t._v(","),s("code",[t._v("y")]),t._v(" 的值为 "),s("code",[t._v("2")]),t._v("。当我们在 "),s("code",[t._v("catch")]),t._v(" 块之外执行 "),s("code",[t._v("console.log(x)")]),t._v(" 时,返回 "),s("code",[t._v("undefined")]),t._v(","),s("code",[t._v("y")]),t._v(" 返回 "),s("code",[t._v("2")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_39-javascript-中的一切都是"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_39-javascript-中的一切都是"}},[t._v("#")]),t._v(" 39. JavaScript 中的一切都是?")]),t._v(" "),s("ul",[s("li",[t._v("A: 基本类型与对象")]),t._v(" "),s("li",[t._v("B: 函数与对象")]),t._v(" "),s("li",[t._v("C: 只有对象")]),t._v(" "),s("li",[t._v("D: 数字与对象\n")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-14"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-14"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("JavaScript 只有基本类型和对象。")]),t._v(" "),s("p",[t._v("基本类型包括 "),s("code",[t._v("boolean")]),t._v(", "),s("code",[t._v("null")]),t._v(", "),s("code",[t._v("undefined")]),t._v(", "),s("code",[t._v("bigint")]),t._v(", "),s("code",[t._v("number")]),t._v(", "),s("code",[t._v("string")]),t._v(", "),s("code",[t._v("symbol")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_40-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_40-输出是什么"}},[t._v("#")]),t._v(" 40. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reduce")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("acc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" cur")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" acc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("concat")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cur"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[0, 1, 2, 3, 1, 2]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[6, 1, 2]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[1, 2, 0, 1, 2, 3]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("[1, 2, 6]")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-13"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-13"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("[1, 2]")]),t._v("是初始值。初始值将会作为首次调用时第一个参数 "),s("code",[t._v("acc")]),t._v(" 的值。在第一次执行时,"),s("code",[t._v("acc")]),t._v(" 的值是 "),s("code",[t._v("[1, 2]")]),t._v(","),s("code",[t._v("cur")]),t._v(" 的值是 "),s("code",[t._v("[0, 1]")]),t._v("。合并它们,结果为 "),s("code",[t._v("[1, 2, 0, 1]")]),t._v("。\n第二次执行,"),s("code",[t._v("acc")]),t._v(" 的值是 "),s("code",[t._v("[1, 2, 0, 1]")]),t._v(","),s("code",[t._v("cur")]),t._v(" 的值是 "),s("code",[t._v("[2, 3]")]),t._v("。合并它们,最终结果为 "),s("code",[t._v("[1, 2, 0, 1, 2, 3]")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_41-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_41-输出是什么"}},[t._v("#")]),t._v(" 41. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-10"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-10"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("null")]),t._v(" 是 "),s("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy",target:"_blank",rel:"noopener noreferrer"}},[t._v("falsy"),s("OutboundLink")],1),t._v("。"),s("code",[t._v("!null")]),t._v(" 的值是 "),s("code",[t._v("true")]),t._v("。"),s("code",[t._v("!true")]),t._v(" 的值是 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v('""')]),t._v(" 是 "),s("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy",target:"_blank",rel:"noopener noreferrer"}},[t._v("falsy"),s("OutboundLink")],1),t._v("。"),s("code",[t._v('!""')]),t._v(" 的值是 "),s("code",[t._v("true")]),t._v("。"),s("code",[t._v("!true")]),t._v(" 的值是 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("1")]),t._v(" 是 "),s("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy",target:"_blank",rel:"noopener noreferrer"}},[t._v("truthy"),s("OutboundLink")],1),t._v("。"),s("code",[t._v("!1")]),t._v(" 的值是 "),s("code",[t._v("false")]),t._v("。"),s("code",[t._v("!false")]),t._v(" 的值是 "),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_42-setinterval-方法的返回值是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_42-setinterval-方法的返回值是什么"}},[t._v("#")]),t._v(" 42. "),s("code",[t._v("setInterval")]),t._v(" 方法的返回值是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setInterval")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hi"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 一个唯一的 id")]),t._v(" "),s("li",[t._v("B: 该方法指定的毫秒数")]),t._v(" "),s("li",[t._v("C: 传递的函数")]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-15"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-15"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("setInterval")]),t._v(" 返回一个唯一的 id。此 id 可被用于 "),s("code",[t._v("clearInterval")]),t._v(" 函数来取消定时。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_43-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_43-输出是什么"}},[t._v("#")]),t._v(" 43. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('["L", "y", "d", "i", "a"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["Lydia"]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('[[], "Lydia"]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('[["L", "y", "d", "i", "a"]]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-16"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-16"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("string 类型是可迭代的。扩展运算符将迭代的每个字符映射成一个元素。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_44-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_44-输出是什么"}},[t._v("#")]),t._v(" 44. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generator")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("i")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" gen "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generator")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gen"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gen"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[0, 10], [10, 20]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("20, 20")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("10, 20")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("0, 10 and 10, 20")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-14"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-14"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("一般的函数在执行之后是不能中途停下的。但是,生成器函数却可以中途“停下”,之后可以再从停下的地方继续。当生成器遇到"),s("code",[t._v("yield")]),t._v("关键字的时候,会生成"),s("code",[t._v("yield")]),t._v("后面的值。注意,生成器在这种情况下不 "),s("em",[t._v("返回")]),t._v(" ("),s("em",[t._v("return")]),t._v(" ) 值,而是 "),s("em",[t._v("生成")]),t._v(" ("),s("em",[t._v("yield")]),t._v(") 值。")]),t._v(" "),s("p",[t._v("首先,我们用"),s("code",[t._v("10")]),t._v("作为参数"),s("code",[t._v("i")]),t._v("来初始化生成器函数。然后使用"),s("code",[t._v("next()")]),t._v("方法一步步执行生成器。第一次执行生成器的时候,"),s("code",[t._v("i")]),t._v("的值为"),s("code",[t._v("10")]),t._v(",遇到第一个"),s("code",[t._v("yield")]),t._v("关键字,它要生成"),s("code",[t._v("i")]),t._v("的值。此时,生成器“暂停”,生成了"),s("code",[t._v("10")]),t._v("。")]),t._v(" "),s("p",[t._v("然后,我们再执行"),s("code",[t._v("next()")]),t._v("方法。生成器会从刚才暂停的地方继续,这个时候"),s("code",[t._v("i")]),t._v("还是"),s("code",[t._v("10")]),t._v("。于是我们走到了第二个"),s("code",[t._v("yield")]),t._v("关键字处,这时候需要生成的值是"),s("code",[t._v("i*2")]),t._v(","),s("code",[t._v("i")]),t._v("为"),s("code",[t._v("10")]),t._v(",那么此时生成的值便是"),s("code",[t._v("20")]),t._v("。所以这道题的最终结果是"),s("code",[t._v("10,20")]),t._v("。")]),t._v(" "),s("h6",{attrs:{id:"_45-返回值是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_45-返回值是什么"}},[t._v("#")]),t._v(" 45. 返回值是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" firstPromise "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Promise")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" rej")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("500")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"one"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" secondPromise "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Promise")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" rej")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"two"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("race")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("firstPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" secondPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"one"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"two"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"two" "one"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"one" "two"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-11"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-11"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("当我们向"),s("code",[t._v("Promise.race")]),t._v("方法中传入多个"),s("code",[t._v("Promise")]),t._v("时,会进行 "),s("em",[t._v("优先")]),t._v(" 解析。在这个例子中,我们用"),s("code",[t._v("setTimeout")]),t._v("给"),s("code",[t._v("firstPromise")]),t._v("和"),s("code",[t._v("secondPromise")]),t._v("分别设定了 500ms 和 100ms 的定时器。这意味着"),s("code",[t._v("secondPromise")]),t._v("会首先解析出字符串"),s("code",[t._v("two")]),t._v("。那么此时"),s("code",[t._v("res")]),t._v("参数即为"),s("code",[t._v("two")]),t._v(",是为输出结果。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_46-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_46-输出是什么"}},[t._v("#")]),t._v(" 46. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" members "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nperson "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("members"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("null")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[null]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[{}]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('[{ name: "Lydia" }]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-5"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-5"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("首先我们声明了一个拥有"),s("code",[t._v("name")]),t._v("属性的对象 "),s("code",[t._v("person")]),t._v("。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/TML1MbS.png",width:"200"}}),t._v(" "),s("p",[t._v("然后我们又声明了一个变量"),s("code",[t._v("members")]),t._v(". 将首个元素赋值为变量"),s("code",[t._v("person")]),t._v("。当设置两个对象彼此相等时,它们会通过 "),s("em",[t._v("引用")]),t._v(" 进行交互。但是当你将引用从一个变量分配至另一个变量时,其实只是执行了一个 "),s("em",[t._v("复制")]),t._v(" 操作。(注意一点,他们的引用 "),s("em",[t._v("并不相同")]),t._v("!)")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/FSG5K3F.png",width:"300"}}),t._v(" "),s("p",[t._v("接下来我们让"),s("code",[t._v("person")]),t._v("等于"),s("code",[t._v("null")]),t._v("。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/sYjcsMT.png",width:"300"}}),t._v(" "),s("p",[t._v("我们没有修改数组第一个元素的值,而只是修改了变量"),s("code",[t._v("person")]),t._v("的值,因为元素(复制而来)的引用与"),s("code",[t._v("person")]),t._v("不同。"),s("code",[t._v("members")]),t._v("的第一个元素仍然保持着对原始对象的引用。当我们输出"),s("code",[t._v("members")]),t._v("数组时,第一个元素会将引用的对象打印出来。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_47-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_47-输出是什么"}},[t._v("#")]),t._v(" 47. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" item "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ name: "Lydia" }, { age: 21 }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"name", "age"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"Lydia", 21')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('["name", "Lydia"], ["age", 21]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-12"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-12"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("在"),s("code",[t._v("for-in")]),t._v("循环中,我们可以通过对象的 key 来进行迭代,也就是这里的"),s("code",[t._v("name")]),t._v("和"),s("code",[t._v("age")]),t._v("。在底层,对象的 key 都是字符串(如果他们不是 Symbol 的话)。在每次循环中,我们将"),s("code",[t._v("item")]),t._v("设定为当前遍历到的 key.所以一开始,"),s("code",[t._v("item")]),t._v("是"),s("code",[t._v("name")]),t._v(",之后 "),s("code",[t._v("item")]),t._v("输出的则是"),s("code",[t._v("age")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_48-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_48-输出是什么"}},[t._v("#")]),t._v(" 48. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"5"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"345"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"75"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("12")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"12"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-13"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-13"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("当所有运算符的 "),s("em",[t._v("优先级")]),t._v(" 相同时,计算表达式需要确定运算符的结合顺序,即从右到左还是从左往右。在这个例子中,我们只有一类运算符"),s("code",[t._v("+")]),t._v(",对于加法来说,结合顺序就是从左到右。")]),t._v(" "),s("p",[s("code",[t._v("3 + 4")]),t._v("首先计算,得到数字"),s("code",[t._v("7")]),t._v(".")]),t._v(" "),s("p",[t._v("由于类型的强制转换,"),s("code",[t._v("7 + '5'")]),t._v("的结果是"),s("code",[t._v('"75"')]),t._v(". JavaScript 将"),s("code",[t._v("7")]),t._v("转换成了字符串,可以参考问题 15.我们可以用"),s("code",[t._v("+")]),t._v("号把两个字符串连接起来。"),s("code",[t._v('"7" + "5"')]),t._v(" 就得到了"),s("code",[t._v('"75"')]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_49-num的值是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_49-num的值是什么"}},[t._v("#")]),t._v(" 49. "),s("code",[t._v("num")]),t._v("的值是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parseInt")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"7*6"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("42")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"42"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("7")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("NaN")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-15"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-15"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("只返回了字符串中第一个字母。设定了 "),s("em",[t._v("进制")]),t._v(" 后 (也就是第二个参数,指定需要解析的数字是什么进制:十进制、十六机制、八进制、二进制等等……),"),s("code",[t._v("parseInt")]),t._v(" 检查字符串中的字符是否合法。一旦遇到一个在指定进制中不合法的字符后,立即停止解析并且忽略后面所有的字符。")]),t._v(" "),s("p",[s("code",[t._v("*")]),t._v("就是不合法的数字字符。所以只解析到"),s("code",[t._v('"7"')]),t._v(",并将其解析为十进制的"),s("code",[t._v("7")]),t._v(". "),s("code",[t._v("num")]),t._v("的值即为"),s("code",[t._v("7")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_50-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_50-输出是什么"}},[t._v("#")]),t._v(" 50. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("map")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("num")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"number"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[null, null, null]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[undefined, undefined, undefined]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("[ 3 x empty ]")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-16"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-16"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("对数组进行映射的时候,"),s("code",[t._v("num")]),t._v("就是当前循环到的元素。在这个例子中,所有的映射都是 number 类型,所以 if 中的判断"),s("code",[t._v('typeof num === "number"')]),t._v("结果都是"),s("code",[t._v("true")]),t._v(".map 函数创建了新数组并且将函数的返回值插入数组。")]),t._v(" "),s("p",[t._v("但是,没有任何值返回。当函数没有返回任何值时,即默认返回"),s("code",[t._v("undefined")]),t._v(".对数组中的每一个元素来说,函数块都得到了这个返回值,所以结果中每一个元素都是"),s("code",[t._v("undefined")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_51-输出的是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_51-输出的是什么"}},[t._v("#")]),t._v(" 51. 输出的是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getInfo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" year")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n year "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1998"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sarah"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" birthYear "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1997"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getInfo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" birthYear"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" birthYear"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ name: "Lydia" }, "1997"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ name: "Sarah" }, "1998"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ name: "Lydia" }, "1998"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('{ name: "Sarah" }, "1997"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-17"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-17"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("普通参数都是 "),s("em",[t._v("值")]),t._v(" 传递的,而对象则不同,是 "),s("em",[t._v("引用")]),t._v(" 传递。所以说,"),s("code",[t._v("birthYear")]),t._v("是值传递,因为他是个字符串而不是对象。当我们对参数进行值传递时,会创建一份该值的 "),s("em",[t._v("复制")]),t._v("。(可以参考问题 46)")]),t._v(" "),s("p",[t._v("变量"),s("code",[t._v("birthYear")]),t._v("有一个对"),s("code",[t._v('"1997"')]),t._v("的引用,而传入的参数也有一个对"),s("code",[t._v('"1997"')]),t._v("的引用,但二者的引用并不相同。当我们通过给 "),s("code",[t._v("year")]),t._v("赋值"),s("code",[t._v('"1998"')]),t._v("来更新"),s("code",[t._v("year")]),t._v("的值的时候我们只是更新了"),s("code",[t._v("year")]),t._v("(的引用)。此时"),s("code",[t._v("birthYear")]),t._v("仍然是"),s("code",[t._v('"1997"')]),t._v(".")]),t._v(" "),s("p",[t._v("而"),s("code",[t._v("person")]),t._v("是个对象。参数"),s("code",[t._v("member")]),t._v("引用与之 "),s("em",[t._v("相同的")]),t._v(" 对象。当我们修改"),s("code",[t._v("member")]),t._v("所引用对象的属性时,"),s("code",[t._v("person")]),t._v("的相应属性也被修改了,因为他们引用了相同的对象。"),s("code",[t._v("person")]),t._v("的 "),s("code",[t._v("name")]),t._v("属性也变成了 "),s("code",[t._v('"Lydia"')]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_52-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_52-输出是什么"}},[t._v("#")]),t._v(" 52. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("greeting")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("throw")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hello world!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("try")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("greeting")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"It worked!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("catch")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Oh no an error:"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"It worked! Hello world!"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Oh no an error: undefined')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("SyntaxError: can only throw Error objects")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"Oh no an error: Hello world!')])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-6"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-6"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("通过"),s("code",[t._v("throw")]),t._v("语句,我么可以创建自定义错误。而通过它,我们可以抛出异常。异常可以是一个"),s("b",[t._v("字符串")]),t._v(",一个 "),s("b",[t._v("数字")]),t._v(",一个 "),s("b",[t._v("布尔类型")]),t._v(" 或者是一个 "),s("b",[t._v("对象")]),t._v("。在本例中,我们的异常是字符串"),s("code",[t._v("'Hello world'")]),t._v(".")]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("catch")]),t._v("语句,我们可以设定当"),s("code",[t._v("try")]),t._v("语句块中抛出异常后应该做什么处理。在本例中抛出的异常是字符串"),s("code",[t._v("'Hello world'")]),t._v(". "),s("code",[t._v("e")]),t._v("就是这个字符串,因此被输出。最终结果就是"),s("code",[t._v("'Oh an error: Hello world'")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_53-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_53-输出是什么"}},[t._v("#")]),t._v(" 53. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Car")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("make "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lamborghini"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("make")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Maserati"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myCar "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Car")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("myCar"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("make"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Lamborghini"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Maserati"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-14"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-14"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("返回属性的时候,属性的值等于 "),s("em",[t._v("返回的")]),t._v(" 值,而不是构造函数中设定的值。我们返回了字符串 "),s("code",[t._v('"Maserati"')]),t._v(",所以 "),s("code",[t._v("myCar.make")]),t._v("等于"),s("code",[t._v('"Maserati"')]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_54-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_54-输出是什么"}},[t._v("#")]),t._v(" 54. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"undefined", "number"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"number", "number"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"object", "number"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"number", "undefined"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-18"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-18"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("let x = y = 10;")]),t._v(" 是下面这个表达式的缩写:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("我们设定"),s("code",[t._v("y")]),t._v("等于"),s("code",[t._v("10")]),t._v("时,我们实际上增加了一个属性"),s("code",[t._v("y")]),t._v("给全局对象 (浏览器里的"),s("code",[t._v("window")]),t._v(", Nodejs 里的"),s("code",[t._v("global")]),t._v(")。在浏览器中,"),s("code",[t._v("window.y")]),t._v("等于"),s("code",[t._v("10")]),t._v(".")]),t._v(" "),s("p",[t._v("然后我们声明了变量"),s("code",[t._v("x")]),t._v("等于"),s("code",[t._v("y")]),t._v(",也是"),s("code",[t._v("10")]),t._v(".但变量是使用 "),s("code",[t._v("let")]),t._v("声明的,它只作用于 "),s("em",[t._v("块级作用域")]),t._v(",仅在声明它的块中有效;就是案例中的立即调用表达式 (IIFE)。使用"),s("code",[t._v("typeof")]),t._v("操作符时,操作值 "),s("code",[t._v("x")]),t._v("没有被定义:因为我们在"),s("code",[t._v("x")]),t._v("声明块的外部,无法调用它。这就意味着"),s("code",[t._v("x")]),t._v("未定义。未分配或是未声明的变量类型为"),s("code",[t._v('"undefined"')]),t._v(". "),s("code",[t._v("console.log(typeof x)")]),t._v("返回"),s("code",[t._v('"undefined"')]),t._v(".")]),t._v(" "),s("p",[t._v("而我们创建了全局变量"),s("code",[t._v("y")]),t._v(",并且设定"),s("code",[t._v("y")]),t._v("等于"),s("code",[t._v("10")]),t._v(".这个值在我们的代码各处都访问的到。"),s("code",[t._v("y")]),t._v("已经被定义了,而且有一个"),s("code",[t._v('"number"')]),t._v("类型的值。"),s("code",[t._v("console.log(typeof y)")]),t._v("返回"),s("code",[t._v('"number"')]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_55-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_55-输出是什么"}},[t._v("#")]),t._v(" "),s("a",{attrs:{name:"20190629"}}),t._v("55. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("bark")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Woof I am ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pet "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Mara"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\npet"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("bark")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("delete")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("bark"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\npet"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("bark")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Woof I am Mara"')]),t._v(", "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Woof I am Mara"')]),t._v(","),s("code",[t._v('"Woof I am Mara"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"Woof I am Mara"')]),t._v(", "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")]),t._v(", "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-19"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-19"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("我们可以用"),s("code",[t._v("delete")]),t._v("关键字删除对象的属性,对原型也是适用的。删除了原型的属性后,该属性在原型链上就不可用了。在本例中,函数"),s("code",[t._v("bark")]),t._v("在执行了"),s("code",[t._v("delete Dog.prototype.bark")]),t._v("后不可用,然而后面的代码还在调用它。")]),t._v(" "),s("p",[t._v("当我们尝试调用一个不存在的函数时"),s("code",[t._v("TypeError")]),t._v("异常会被抛出。在本例中就是 "),s("code",[t._v("TypeError: pet.bark is not a function")]),t._v(",因为"),s("code",[t._v("pet.bark")]),t._v("是"),s("code",[t._v("undefined")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_56-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_56-输出是什么"}},[t._v("#")]),t._v(" 56. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" set "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Set")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("set"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[1, 1, 2, 3, 4]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[1, 2, 3, 4]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("{1, 1, 2, 3, 4}")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("{1, 2, 3, 4}")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-7"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-7"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("Set")]),t._v("对象是独一无二的值的集合:也就是说同一个值在其中仅出现一次。")]),t._v(" "),s("p",[t._v("我们传入了数组"),s("code",[t._v("[1, 1, 2, 3, 4]")]),t._v(",他有一个重复值"),s("code",[t._v("1")]),t._v(".以为一个集合里不能有两个重复的值,其中一个就被移除了。所以结果是 "),s("code",[t._v("{1, 2, 3, 4}")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_57-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_57-输出是什么"}},[t._v("#")]),t._v(" 57. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// counter.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" counter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("default")]),t._v(" counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// index.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" myCounter "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./counter"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nmyCounter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("myCounter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("10")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("11")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Error")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("NaN")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-17"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-17"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("引入的模块是 "),s("em",[t._v("只读")]),t._v(" 的:你不能修改引入的模块。只有导出他们的模块才能修改其值。")]),t._v(" "),s("p",[t._v("当我们给"),s("code",[t._v("myCounter")]),t._v("增加一个值的时候会抛出一个异常:"),s("code",[t._v("myCounter")]),t._v("是只读的,不能被修改。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_58-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_58-输出是什么"}},[t._v("#")]),t._v(" 58. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nage "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("delete")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("delete")]),t._v(" age"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")]),t._v(", "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Lydia"')]),t._v(", "),s("code",[t._v("21")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(", "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-20"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-20"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("delete")]),t._v("操作符返回一个布尔值:"),s("code",[t._v("true")]),t._v("指删除成功,否则返回"),s("code",[t._v("false")]),t._v(". 但是通过 "),s("code",[t._v("var")]),t._v(", "),s("code",[t._v("const")]),t._v(" 或 "),s("code",[t._v("let")]),t._v(" 关键字声明的变量无法用 "),s("code",[t._v("delete")]),t._v(" 操作符来删除。")]),t._v(" "),s("p",[s("code",[t._v("name")]),t._v("变量由"),s("code",[t._v("const")]),t._v("关键字声明,所以删除不成功:返回 "),s("code",[t._v("false")]),t._v(". 而我们设定"),s("code",[t._v("age")]),t._v("等于"),s("code",[t._v("21")]),t._v("时,我们实际上添加了一个名为"),s("code",[t._v("age")]),t._v("的属性给全局对象。对象中的属性是可以删除的,全局对象也是如此,所以"),s("code",[t._v("delete age")]),t._v("返回"),s("code",[t._v("true")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_59-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_59-输出是什么"}},[t._v("#")]),t._v(" 59. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" numbers "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" numbers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[[1, 2, 3, 4, 5]]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[1, 2, 3, 4, 5]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("1")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("[1]")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-18"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-18"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("我们可以通过解构赋值来解析来自对象的数组或属性的值,比如说:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("img",{attrs:{src:"https://i.imgur.com/ADFpVop.png",width:"200"}}),t._v(" "),s("p",[s("code",[t._v("a")]),t._v("的值现在是"),s("code",[t._v("1")]),t._v(","),s("code",[t._v("b")]),t._v("的值现在是"),s("code",[t._v("2")]),t._v(".而在题目中,我们是这么做的:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("img",{attrs:{src:"https://i.imgur.com/NzGkMNk.png",width:"200"}}),t._v(" "),s("p",[t._v("也就是说,"),s("code",[t._v("y")]),t._v("等于数组的第一个值就是数字"),s("code",[t._v("1")]),t._v(".我们输出"),s("code",[t._v("y")]),t._v(",返回"),s("code",[t._v("1")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_60-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_60-输出是什么"}},[t._v("#")]),t._v(" 60. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" user "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" admin "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("admin")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("user "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("admin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ admin: true, user: { name: "Lydia", age: 21 } }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ admin: true, name: "Lydia", age: 21 }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ admin: true, user: ["Lydia", 21] }')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("{ admin: true }")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-15"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-15"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("扩展运算符"),s("code",[t._v("...")]),t._v("为对象的组合提供了可能。你可以复制对象中的键值对,然后把它们加到另一个对象里去。在本例中,我们复制了"),s("code",[t._v("user")]),t._v("对象键值对,然后把它们加入到"),s("code",[t._v("admin")]),t._v("对象中。"),s("code",[t._v("admin")]),t._v("对象就拥有了这些键值对,所以结果为"),s("code",[t._v('{ admin: true, name: "Lydia", age: 21 }')]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_61-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_61-输出是什么"}},[t._v("#")]),t._v(" 61. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nObject"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("defineProperty")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"age"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("value")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Object"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("keys")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ name: "Lydia", age: 21 }')]),t._v(", "),s("code",[t._v('["name", "age"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ name: "Lydia", age: 21 }')]),t._v(", "),s("code",[t._v('["name"]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ name: "Lydia"}')]),t._v(", "),s("code",[t._v('["name", "age"]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('{ name: "Lydia"}')]),t._v(", "),s("code",[t._v('["age"]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-16"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-16"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("通过"),s("code",[t._v("defineProperty")]),t._v("方法,我们可以给对象添加一个新属性,或者修改已经存在的属性。而我们使用"),s("code",[t._v("defineProperty")]),t._v("方法给对象添加了一个属性之后,属性默认为 "),s("em",[t._v("不可枚举 (not enumerable)")]),t._v(". "),s("code",[t._v("Object.keys")]),t._v("方法仅返回对象中 "),s("em",[t._v("可枚举 (enumerable)")]),t._v(" 的属性,因此只剩下了"),s("code",[t._v('"name"')]),t._v(".")]),t._v(" "),s("p",[t._v("用"),s("code",[t._v("defineProperty")]),t._v("方法添加的属性默认不可变。你可以通过"),s("code",[t._v("writable")]),t._v(", "),s("code",[t._v("configurable")]),t._v(" 和 "),s("code",[t._v("enumerable")]),t._v("属性来改变这一行为。这样,"),s("code",[t._v("defineProperty")]),t._v("方法可以让您更好地控制要添加到对象的属性。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_62-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_62-输出是什么"}},[t._v("#")]),t._v(" 62. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" settings "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("username")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"lydiahallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("level")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("19")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("health")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("90")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("stringify")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("settings"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"level"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"health"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"{"level":19, "health":90}"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"{"username": "lydiahallie"}"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"["level", "health"]"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"{"username": "lydiahallie", "level":19, "health":90}"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-21"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-21"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("JSON.stringify")]),t._v("的第二个参数是 "),s("em",[t._v("替代者 (replacer)")]),t._v(". 替代者 (replacer) 可以是个函数或数组,用以控制哪些值如何被转换为字符串。")]),t._v(" "),s("p",[t._v("如果替代者 (replacer) 是个 "),s("em",[t._v("数组")]),t._v(",那么就只有包含在数组中的属性将会被转化为字符串。在本例中,只有名为"),s("code",[t._v('"level"')]),t._v(" 和 "),s("code",[t._v('"health"')]),t._v(" 的属性被包括进来,"),s("code",[t._v('"username"')]),t._v("则被排除在外。"),s("code",[t._v("data")]),t._v(" 就等于 "),s("code",[t._v('"{"level":19, "health":90}"')]),t._v(".")]),t._v(" "),s("p",[t._v("而如果替代者 (replacer) 是个 "),s("em",[t._v("函数")]),t._v(",这个函数将被对象的每个属性都调用一遍。\n函数返回的值会成为这个属性的值,最终体现在转化后的 JSON 字符串中(译者注:Chrome 下,经过实验,如果所有属性均返回同一个值的时候有异常,会直接将返回值作为结果输出而不会输出 JSON 字符串),而如果返回值为"),s("code",[t._v("undefined")]),t._v(",则该属性会被排除在外。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_63-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_63-输出是什么"}},[t._v("#")]),t._v(" 63. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("increaseNumber")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" num"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("increasePassedNumber")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("number")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" number"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" num1 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increaseNumber")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" num2 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increasePassedNumber")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num2"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("10")]),t._v(", "),s("code",[t._v("10")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("10")]),t._v(", "),s("code",[t._v("11")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("11")]),t._v(", "),s("code",[t._v("11")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("11")]),t._v(", "),s("code",[t._v("12")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-22"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-22"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("一元操作符 "),s("code",[t._v("++")]),t._v(" "),s("em",[t._v("先返回")]),t._v(" 操作值,"),s("em",[t._v("再累加")]),t._v(" 操作值。"),s("code",[t._v("num1")]),t._v("的值是"),s("code",[t._v("10")]),t._v(",因为"),s("code",[t._v("increaseNumber")]),t._v("函数首先返回"),s("code",[t._v("num")]),t._v("的值,也就是"),s("code",[t._v("10")]),t._v(",随后再进行 "),s("code",[t._v("num")]),t._v("的累加。")]),t._v(" "),s("p",[s("code",[t._v("num2")]),t._v("是"),s("code",[t._v("10")]),t._v("因为我们将 "),s("code",[t._v("num1")]),t._v("传入"),s("code",[t._v("increasePassedNumber")]),t._v(". "),s("code",[t._v("number")]),t._v("等于"),s("code",[t._v("10")]),t._v("("),s("code",[t._v("num1")]),t._v("的值。同样道理,"),s("code",[t._v("++")]),t._v(" "),s("em",[t._v("先返回")]),t._v(" 操作值,"),s("em",[t._v("再累加")]),t._v(" 操作值。)"),s("code",[t._v("number")]),t._v("是"),s("code",[t._v("10")]),t._v(",所以"),s("code",[t._v("num2")]),t._v("也是"),s("code",[t._v("10")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_64-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_64-输出什么"}},[t._v("#")]),t._v(" 64. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" value "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("number")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("multiply")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("value "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("number "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("multiply")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("multiply")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("multiply")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("multiply")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("40")]),t._v(", "),s("code",[t._v("80")]),t._v(", "),s("code",[t._v("160")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("40")]),t._v(", "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("40")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("40")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("NaN")]),t._v(", "),s("code",[t._v("NaN")]),t._v(", "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("40")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-19"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-19"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("在 ES6 中,我们可以使用默认值初始化参数。如果没有给函数传参,或者传的参值为 "),s("code",[t._v('"undefined"')]),t._v(",那么参数的值将是默认值。上述例子中,我们将 "),s("code",[t._v("value")]),t._v(" 对象进行了解构并传到一个新对象中,因此 "),s("code",[t._v("x")]),t._v(" 的默认值为 "),s("code",[t._v("{number:10}")]),t._v("。")]),t._v(" "),s("p",[t._v("默认参数在调用时才会进行计算,每次调用函数时,都会创建一个新的对象。我们前两次调用 "),s("code",[t._v("multiply")]),t._v(" 函数且不传递值,那么每一次 "),s("code",[t._v("x")]),t._v(" 的默认值都为 "),s("code",[t._v("{number:10}")]),t._v(",因此打印出该数字的乘积值为"),s("code",[t._v("20")]),t._v("。")]),t._v(" "),s("p",[t._v("第三次调用 "),s("code",[t._v("multiply")]),t._v(" 时,我们传递了一个参数,即对象"),s("code",[t._v("value")]),t._v("。"),s("code",[t._v("*=")]),t._v("运算符实际上是"),s("code",[t._v("x.number = x.number * 2")]),t._v("的简写,我们修改了"),s("code",[t._v("x.number")]),t._v("的值,并打印出值"),s("code",[t._v("20")]),t._v("。")]),t._v(" "),s("p",[t._v("第四次,我们再次传递"),s("code",[t._v("value")]),t._v("对象。"),s("code",[t._v("x.number")]),t._v("之前被修改为"),s("code",[t._v("20")]),t._v(",所以"),s("code",[t._v("x.number * = 2")]),t._v("打印为"),s("code",[t._v("40")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_65-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_65-输出什么"}},[t._v("#")]),t._v(" 65. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reduce")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("3")]),t._v(" and "),s("code",[t._v("6")]),t._v(" "),s("code",[t._v("4")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" and "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("4")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" and "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" and "),s("code",[t._v("4")]),t._v(" "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" and "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("3")]),t._v(" and "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("4")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-8"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-8"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("reducer")]),t._v(" 函数接收 4 个参数:")]),t._v(" "),s("ol",[s("li",[t._v("Accumulator (acc) (累计器)")]),t._v(" "),s("li",[t._v("Current Value (cur) (当前值)")]),t._v(" "),s("li",[t._v("Current Index (idx) (当前索引)")]),t._v(" "),s("li",[t._v("Source Array (src) (源数组)")])]),t._v(" "),s("p",[s("code",[t._v("reducer")]),t._v(" 函数的返回值将会分配给累计器,该返回值在数组的每个迭代中被记住,并最后成为最终的单个结果值。")]),t._v(" "),s("p",[s("code",[t._v("reducer")]),t._v(" 函数还有一个可选参数"),s("code",[t._v("initialValue")]),t._v(",该参数将作为第一次调用回调函数时的第一个参数的值。如果没有提供"),s("code",[t._v("initialValue")]),t._v(",则将使用数组中的第一个元素。")]),t._v(" "),s("p",[t._v("在上述例子,"),s("code",[t._v("reduce")]),t._v("方法接收的第一个参数 (Accumulator) 是"),s("code",[t._v("x")]),t._v(",第二个参数 (Current Value) 是"),s("code",[t._v("y")]),t._v("。")]),t._v(" "),s("p",[t._v("在第一次调用时,累加器"),s("code",[t._v("x")]),t._v("为"),s("code",[t._v("1")]),t._v(",当前值"),s("code",[t._v("“y”")]),t._v("为"),s("code",[t._v("2")]),t._v(",打印出累加器和当前值:"),s("code",[t._v("1")]),t._v("和"),s("code",[t._v("2")]),t._v("。")]),t._v(" "),s("p",[t._v("例子中我们的回调函数没有返回任何值,只是打印累加器的值和当前值。如果函数没有返回值,则默认返回"),s("code",[t._v("undefined")]),t._v("。在下一次调用时,累加器为"),s("code",[t._v("undefined")]),t._v(",当前值为“3”,因此"),s("code",[t._v("undefined")]),t._v("和"),s("code",[t._v("3")]),t._v("被打印出。")]),t._v(" "),s("p",[t._v("在第四次调用时,回调函数依然没有返回值。累加器再次为 "),s("code",[t._v("undefined")]),t._v(",当前值为“4”。"),s("code",[t._v("undefined")]),t._v("和"),s("code",[t._v("4")]),t._v("被打印出。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_66-使用哪个构造函数可以成功继承dog类"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_66-使用哪个构造函数可以成功继承dog类"}},[t._v("#")]),t._v(" 66. 使用哪个构造函数可以成功继承"),s("code",[t._v("Dog")]),t._v("类?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Labrador")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("extends")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 1")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("size "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" size"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 2")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("size "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" size"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 3")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("size "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" size"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 4")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("size "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" size"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 1")]),t._v(" "),s("li",[t._v("B: 2")]),t._v(" "),s("li",[t._v("C: 3")]),t._v(" "),s("li",[t._v("D: 4")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-17"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-17"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("在子类中,在调用"),s("code",[t._v("super")]),t._v("之前不能访问到"),s("code",[t._v("this")]),t._v("关键字。如果这样做,它将抛出一个"),s("code",[t._v("ReferenceError")]),t._v(":1 和 4 将引发一个引用错误。")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("super")]),t._v("关键字,需要用给定的参数来调用父类的构造函数。父类的构造函数接收"),s("code",[t._v("name")]),t._v("参数,因此我们需要将"),s("code",[t._v("name")]),t._v("传递给"),s("code",[t._v("super")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("Labrador")]),t._v("类接收两个参数,"),s("code",[t._v("name")]),t._v("参数是由于它继承了"),s("code",[t._v("Dog")]),t._v(","),s("code",[t._v("size")]),t._v("作为"),s("code",[t._v("Labrador")]),t._v("类的额外属性,它们都需要传递给"),s("code",[t._v("Labrador")]),t._v("的构造函数,因此使用构造函数 2 正确完成。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_67-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_67-输出什么"}},[t._v("#")]),t._v(" 67. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// index.js")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"running index.js"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./sum.js"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// sum.js")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"running sum.js"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("sum")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" b")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("running index.js")]),t._v(", "),s("code",[t._v("running sum.js")]),t._v(", "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("running sum.js")]),t._v(", "),s("code",[t._v("running index.js")]),t._v(", "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("running sum.js")]),t._v(", "),s("code",[t._v("3")]),t._v(", "),s("code",[t._v("running index.js")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("running index.js")]),t._v(", "),s("code",[t._v("undefined")]),t._v(", "),s("code",[t._v("running sum.js")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-18"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-18"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("import")]),t._v("命令是编译阶段执行的,在代码运行之前。因此这意味着被导入的模块会先运行,而导入模块的文件会后执行。")]),t._v(" "),s("p",[t._v("这是 CommonJS 中"),s("code",[t._v("require()")]),t._v("和"),s("code",[t._v("import")]),t._v("之间的区别。使用"),s("code",[t._v("require()")]),t._v(",您可以在运行代码时根据需要加载依赖项。如果我们使用"),s("code",[t._v("require")]),t._v("而不是"),s("code",[t._v("import")]),t._v(","),s("code",[t._v("running index.js")]),t._v(","),s("code",[t._v("running sum.js")]),t._v(","),s("code",[t._v("3")]),t._v("会被依次打印。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_68-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_68-输出什么"}},[t._v("#")]),t._v(" 68. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Number")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Number")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Boolean")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Boolean")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Symbol")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"foo"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Symbol")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"foo"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")]),t._v(", "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("false")]),t._v(", "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-23"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-23"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("每个"),s("code",[t._v("Symbol")]),t._v("都是完全唯一的。传递给"),s("code",[t._v("Symbol")]),t._v("的参数只是给"),s("code",[t._v("Symbol")]),t._v("的一个描述。"),s("code",[t._v("Symbol")]),t._v("的值不依赖于传递的参数。当我们测试相等时,我们创建了两个全新的符号:第一个"),s("code",[t._v("Symbol('foo')")]),t._v(",第二个"),s("code",[t._v("Symbol('foo')")]),t._v(",这两个值是唯一的,彼此不相等,因此返回"),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_69-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_69-输出什么"}},[t._v("#")]),t._v(" 69. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("padStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("13")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("padStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Lydia Hallie"')]),t._v(", "),s("code",[t._v('"Lydia Hallie"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('" Lydia Hallie"')]),t._v(", "),s("code",[t._v('" Lydia Hallie"')]),t._v(" ("),s("code",[t._v('"[13x whitespace]Lydia Hallie"')]),t._v(", "),s("code",[t._v('"[2x whitespace]Lydia Hallie"')]),t._v(")")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('" Lydia Hallie"')]),t._v(", "),s("code",[t._v('"Lydia Hallie"')]),t._v(" ("),s("code",[t._v('"[1x whitespace]Lydia Hallie"')]),t._v(", "),s("code",[t._v('"Lydia Hallie"')]),t._v(")")]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"Lydia Hallie"')]),t._v(", "),s("code",[t._v('"Lyd"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-20"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-20"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("padStart")]),t._v("方法,我们可以在字符串的开头添加填充。传递给此方法的参数是字符串的总长度(包含填充)。字符串"),s("code",[t._v("Lydia Hallie")]),t._v("的长度为"),s("code",[t._v("12")]),t._v(",因此"),s("code",[t._v("name.padStart(13)")]),t._v("在字符串的开头只会插入 1("),s("code",[t._v("13 - 12 = 1")]),t._v(")个空格。")]),t._v(" "),s("p",[t._v("如果传递给"),s("code",[t._v("padStart")]),t._v("方法的参数小于字符串的长度,则不会添加填充。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_70-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_70-输出什么"}},[t._v("#")]),t._v(" 70. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"💻"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"🥑💻"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("257548")])]),t._v(" "),s("li",[t._v("C: A string containing their code points")]),t._v(" "),s("li",[t._v("D: Error")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-24"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-24"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("+")]),t._v("运算符,您可以连接字符串。上述情况,我们将字符串"),s("code",[t._v("“🥑”")]),t._v("与字符串"),s("code",[t._v("”💻“")]),t._v("连接起来,产生"),s("code",[t._v("”🥑💻“")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_71-如何能打印出console-log语句后注释掉的值"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_71-如何能打印出console-log语句后注释掉的值"}},[t._v("#")]),t._v(" 71. 如何能打印出"),s("code",[t._v("console.log")]),t._v("语句后注释掉的值?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("startGame")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" 答案 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Do you love JavaScript?"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("答案 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Yes"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Oh wow... Guess we\'re gone here"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"JavaScript loves you back ❤️"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" game "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("startGame")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 1 */")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Do you love JavaScript?")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 2 */")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// JavaScript loves you back ❤️")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('game.next("Yes").value')]),t._v(" and "),s("code",[t._v("game.next().value")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('game.next.value("Yes")')]),t._v(" and "),s("code",[t._v("game.next.value()")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("game.next().value")]),t._v(" and "),s("code",[t._v('game.next("Yes").value')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("game.next.value()")]),t._v(" and "),s("code",[t._v('game.next.value("Yes")')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-21"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-21"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("generator")]),t._v("函数在遇到"),s("code",[t._v("yield")]),t._v("关键字时会“暂停”其执行。首先,我们需要让函数产生字符串"),s("code",[t._v("Do you love JavaScript?")]),t._v(",这可以通过调用"),s("code",[t._v("game.next().value")]),t._v("来完成。上述函数的第一行就有一个"),s("code",[t._v("yield")]),t._v("关键字,那么运行立即停止了,"),s("code",[t._v("yield")]),t._v("表达式本身没有返回值,或者说总是返回"),s("code",[t._v("undefined")]),t._v(",这意味着此时变量 "),s("code",[t._v("答案")]),t._v(" 为"),s("code",[t._v("undefined")])]),t._v(" "),s("p",[s("code",[t._v("next")]),t._v("方法可以带一个参数,该参数会被当作上一个 "),s("code",[t._v("yield")]),t._v(" 表达式的返回值。当我们调用"),s("code",[t._v('game.next("Yes").value')]),t._v("时,先前的 "),s("code",[t._v("yield")]),t._v(" 的返回值将被替换为传递给"),s("code",[t._v("next()")]),t._v("函数的参数"),s("code",[t._v('"Yes"')]),t._v("。此时变量 "),s("code",[t._v("答案")]),t._v(" 被赋值为 "),s("code",[t._v('"Yes"')]),t._v(","),s("code",[t._v("if")]),t._v("语句返回"),s("code",[t._v("false")]),t._v(",所以"),s("code",[t._v("JavaScript loves you back ❤️")]),t._v("被打印。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_72-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_72-输出什么"}},[t._v("#")]),t._v(" 72. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("String"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("raw"),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Hello\\nworld")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Hello world!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Hello")]),t._v(" "),s("br"),t._v(" "),s("code",[t._v("world")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Hello\\nworld")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Hello\\n")]),t._v(" "),s("br"),t._v(" "),s("code",[t._v("world")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-22"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-22"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("String.raw")]),t._v("函数是用来获取一个模板字符串的原始字符串的,它返回一个字符串,其中忽略了转义符("),s("code",[t._v("\\n")]),t._v(","),s("code",[t._v("\\v")]),t._v(","),s("code",[t._v("\\t")]),t._v("等)。但反斜杠可能造成问题,因为你可能会遇到下面这种类似情况:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" path "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("C:\\Documents\\Projects\\table.html")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nString"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("raw"),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("path"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("这将导致:")]),t._v(" "),s("p",[s("code",[t._v('"C:DocumentsProjects able.html"')])]),t._v(" "),s("p",[t._v("直接使用"),s("code",[t._v("String.raw")])]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("String"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("raw"),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("C:\\Documents\\Projects\\table.html")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("它会忽略转义字符并打印:"),s("code",[t._v("C:\\Documents\\Projects\\table.html")])]),t._v(" "),s("p",[t._v("上述情况,字符串是"),s("code",[t._v("Hello\\nworld")]),t._v("被打印出。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_73-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_73-输出什么"}},[t._v("#")]),t._v(" 73. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getData")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I made it!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getData")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"I made it!"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('Promise {: "I made it!"}')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Promise {}")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-23"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-23"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("异步函数始终返回一个 promise。"),s("code",[t._v("await")]),t._v("仍然需要等待 promise 的解决:当我们调用"),s("code",[t._v("getData()")]),t._v("并将其赋值给"),s("code",[t._v("data")]),t._v(",此时"),s("code",[t._v("data")]),t._v("为"),s("code",[t._v("getData")]),t._v("方法返回的一个挂起的 promise,该 promise 并没有解决。")]),t._v(" "),s("p",[t._v("如果我们想要访问已解决的值"),s("code",[t._v('"I made it!"')]),t._v(",可以在"),s("code",[t._v("data")]),t._v("上使用"),s("code",[t._v(".then()")]),t._v("方法:")]),t._v(" "),s("p",[s("code",[t._v("data.then(res => console.log(res))")])]),t._v(" "),s("p",[t._v("这样将打印 "),s("code",[t._v('"I made it!"')])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_74-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_74-输出什么"}},[t._v("#")]),t._v(" 74. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addToList")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" list")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" result "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addToList")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"apple"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"banana"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("result"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("['apple', 'banana']")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-19"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-19"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("push()")]),t._v("方法返回新数组的长度。一开始,数组包含一个元素(字符串"),s("code",[t._v('"banana"')]),t._v("),长度为 1。在数组中添加字符串"),s("code",[t._v('"apple"')]),t._v("后,长度变为 2,并将从"),s("code",[t._v("addToList")]),t._v("函数返回。")]),t._v(" "),s("p",[s("code",[t._v("push")]),t._v("方法修改原始数组,如果你想从函数返回数组而不是数组长度,那么应该在 push "),s("code",[t._v("item")]),t._v("之后返回"),s("code",[t._v("list")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_75-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_75-输出什么"}},[t._v("#")]),t._v(" 75. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" box "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("y")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nObject"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("freeze")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("box"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" shape "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" box"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nshape"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("shape"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("{ x: 100, y: 20 }")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("{ x: 10, y: 20 }")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("{ x: 100 }")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-20"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-20"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("Object.freeze")]),t._v("使得无法添加、删除或修改对象的属性(除非属性的值是另一个对象)。")]),t._v(" "),s("p",[t._v("当我们创建变量"),s("code",[t._v("shape")]),t._v("并将其设置为等于冻结对象"),s("code",[t._v("box")]),t._v("时,"),s("code",[t._v("shape")]),t._v("指向的也是冻结对象。你可以使用"),s("code",[t._v("Object.isFrozen")]),t._v("检查一个对象是否被冻结,上述情况,"),s("code",[t._v("Object.isFrozen(shape)")]),t._v("将返回"),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[t._v("由于"),s("code",[t._v("shape")]),t._v("被冻结,并且"),s("code",[t._v("x")]),t._v("的值不是对象,所以我们不能修改属性"),s("code",[t._v("x")]),t._v("。"),s("code",[t._v("x")]),t._v("仍然等于"),s("code",[t._v("10")]),t._v(","),s("code",[t._v("{x:10,y:20}")]),t._v("被打印。")]),t._v(" "),s("p",[t._v("注意,上述例子我们对属性"),s("code",[t._v("x")]),t._v("进行修改,可能会导致抛出 TypeError 异常(最常见但不仅限于严格模式下时)。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_76-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_76-输出什么"}},[t._v("#")]),t._v(" 76. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" myName "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Lydia"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"myName"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-9"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-9"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("当我们从右侧的对象解构属性"),s("code",[t._v("name")]),t._v("时,我们将其值"),s("code",[t._v("Lydia")]),t._v("分配给名为"),s("code",[t._v("myName")]),t._v("的变量。")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("{name:myName}")]),t._v(",我们是在告诉 JavaScript 我们要创建一个名为"),s("code",[t._v("myName")]),t._v("的新变量,并且其值是右侧对象的"),s("code",[t._v("name")]),t._v("属性的值。")]),t._v(" "),s("p",[t._v("当我们尝试打印"),s("code",[t._v("name")]),t._v(",一个未定义的变量时,就会引发"),s("code",[t._v("ReferenceError")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_77-以下是个纯函数么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_77-以下是个纯函数么"}},[t._v("#")]),t._v(" 77. 以下是个纯函数么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" b")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: Yes")]),t._v(" "),s("li",[t._v("B: No")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-25"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-25"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("纯函数在相同的输入值时,需产生相同的输出,其输出的结果,与输入值以外的其他隐藏信息或状态无关,也和由 I/O 设备产生的外部输出无关。\n纯函数不会产生副作用。")]),t._v(" "),s("p",[t._v("纯函数与副作用的定义可参考:\nhttps://zh.wikipedia.org/wiki/%E5%89%AF%E4%BD%9C%E7%94%A8_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_78-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_78-输出什么"}},[t._v("#")]),t._v(" 78. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("add")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" cache "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("num")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("From cache! ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" result "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" result"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Calculated! ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("result"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" addFunction "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Calculated! 20")]),t._v(" "),s("code",[t._v("Calculated! 20")]),t._v(" "),s("code",[t._v("Calculated! 20")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Calculated! 20")]),t._v(" "),s("code",[t._v("From cache! 20")]),t._v(" "),s("code",[t._v("Calculated! 20")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Calculated! 20")]),t._v(" "),s("code",[t._v("From cache! 20")]),t._v(" "),s("code",[t._v("From cache! 20")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Calculated! 20")]),t._v(" "),s("code",[t._v("From cache! 20")]),t._v(" "),s("code",[t._v("Error")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-24"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-24"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("add")]),t._v("函数是一个记忆函数。通过记忆化,我们可以缓存函数的结果,以加快其执行速度。上述情况,我们创建一个"),s("code",[t._v("cache")]),t._v("对象,用于存储先前返回过的值。")]),t._v(" "),s("p",[t._v("如果我们使用相同的参数多次调用"),s("code",[t._v("addFunction")]),t._v("函数,它首先检查缓存中是否已有该值,如果有,则返回缓存值,这将节省执行时间。如果没有,那么它将计算该值,并存储在缓存中。")]),t._v(" "),s("p",[t._v("我们用相同的值三次调用了"),s("code",[t._v("addFunction")]),t._v("函数:")]),t._v(" "),s("p",[t._v("在第一次调用,"),s("code",[t._v("num")]),t._v("等于"),s("code",[t._v("10")]),t._v("时函数的值尚未缓存,if 语句"),s("code",[t._v("num in cache")]),t._v("返回"),s("code",[t._v("false")]),t._v(",else 块的代码被执行:"),s("code",[t._v("Calculated! 20")]),t._v(",并且其结果被添加到缓存对象,"),s("code",[t._v("cache")]),t._v("现在看起来像"),s("code",[t._v("{10:20}")]),t._v("。")]),t._v(" "),s("p",[t._v("第二次,"),s("code",[t._v("cache")]),t._v("对象包含"),s("code",[t._v("10")]),t._v("的返回值。if 语句 "),s("code",[t._v("num in cache")]),t._v(" 返回"),s("code",[t._v("true")]),t._v(","),s("code",[t._v("From cache! 20")]),t._v("被打印。")]),t._v(" "),s("p",[t._v("第三次,我们将"),s("code",[t._v("5 * 2")]),t._v("(值为 10) 传递给函数。"),s("code",[t._v("cache")]),t._v("对象包含"),s("code",[t._v("10")]),t._v("的返回值。if 语句 "),s("code",[t._v("num in cache")]),t._v(" 返回"),s("code",[t._v("true")]),t._v(","),s("code",[t._v("From cache! 20")]),t._v("被打印。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_79-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_79-输出什么"}},[t._v("#")]),t._v(" "),s("a",{attrs:{name:"20190726"}}),t._v("79. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myLifeSummedUp "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"☕"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"💻"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍷"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍫"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" item "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" myLifeSummedUp"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" item "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("of")]),t._v(" myLifeSummedUp"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("0")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")]),t._v(" and "),s("code",[t._v('"☕"')]),t._v(" "),s("code",[t._v('"💻"')]),t._v(" "),s("code",[t._v('"🍷"')]),t._v(" "),s("code",[t._v('"🍫"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"☕"')]),t._v(" "),s("code",[t._v('"💻"')]),t._v(" "),s("code",[t._v('"🍷"')]),t._v(" "),s("code",[t._v('"🍫"')]),t._v(" and "),s("code",[t._v('"☕"')]),t._v(" "),s("code",[t._v('"💻"')]),t._v(" "),s("code",[t._v('"🍷"')]),t._v(" "),s("code",[t._v('"🍫"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"☕"')]),t._v(" "),s("code",[t._v('"💻"')]),t._v(" "),s("code",[t._v('"🍷"')]),t._v(" "),s("code",[t._v('"🍫"')]),t._v(" and "),s("code",[t._v("0")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("0")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")]),t._v(" and "),s("code",[t._v('{0: "☕", 1: "💻", 2: "🍷", 3: "🍫"}')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-26"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-26"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("通过"),s("code",[t._v("for-in")]),t._v("循环,我们可以遍历一个对象"),s("strong",[t._v("自有的")]),t._v("、"),s("strong",[t._v("继承的")]),t._v("、"),s("strong",[t._v("可枚举的")]),t._v("、"),s("strong",[t._v("非 Symbol 的")]),t._v("属性。在数组中,可枚举属性是数组元素的“键”,即它们的索引。类似于下面这个对象:")]),t._v(" "),s("p",[s("code",[t._v('{0: "☕", 1: "💻", 2: "🍷", 3: "🍫"}')])]),t._v(" "),s("p",[t._v("其中键则是可枚举属性,因此 "),s("code",[t._v("0")]),t._v(","),s("code",[t._v("1")]),t._v(","),s("code",[t._v("2")]),t._v(","),s("code",[t._v("3")]),t._v("被记录。")]),t._v(" "),s("p",[t._v("通过"),s("code",[t._v("for-of")]),t._v("循环,我们可以迭代"),s("strong",[t._v("可迭代对象")]),t._v("(包括 "),s("code",[t._v("Array")]),t._v(","),s("code",[t._v("Map")]),t._v(","),s("code",[t._v("Set")]),t._v(","),s("code",[t._v("String")]),t._v(","),s("code",[t._v("arguments")]),t._v("等)。当我们迭代数组时,在每次迭代中,不同属性的值将被分配给变量"),s("code",[t._v("item")]),t._v(",因此"),s("code",[t._v("“☕”")]),t._v(","),s("code",[t._v("“💻”")]),t._v(","),s("code",[t._v("“🍷”")]),t._v(","),s("code",[t._v("“🍫”")]),t._v("被打印。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_80-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_80-输出什么"}},[t._v("#")]),t._v(" 80. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" list "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('["1 + 2", "1 * 2", "1 / 2"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["12", 2, 0.5]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[3, 2, 0.5]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("[1, 1, 1]")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-25"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-25"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("数组元素可以包含任何值。数字,字符串,布尔值,对象,数组,"),s("code",[t._v("null")]),t._v(","),s("code",[t._v("undefined")]),t._v(",以及其他表达式,如日期,函数和计算。")]),t._v(" "),s("p",[t._v("元素将等于返回的值。"),s("code",[t._v("1 + 2")]),t._v("返回"),s("code",[t._v("3")]),t._v(","),s("code",[t._v("1 * 2")]),t._v("返回'2"),s("code",[t._v(",'1 / 2")]),t._v("返回"),s("code",[t._v("0.5")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_81-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_81-输出什么"}},[t._v("#")]),t._v(" 81. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Hi there, ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Hi there,")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Hi there, undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Hi there, null")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-21"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-21"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("默认情况下,如果不给函数传参,参数的值将为"),s("code",[t._v("undefined")]),t._v("。上述情况,我们没有给参数"),s("code",[t._v("name")]),t._v("传值。"),s("code",[t._v("name")]),t._v("等于"),s("code",[t._v("undefined")]),t._v(",并被打印。")]),t._v(" "),s("p",[t._v("在 ES6 中,我们可以使用默认参数覆盖此默认的"),s("code",[t._v("undefined")]),t._v("值。例如:")]),t._v(" "),s("p",[s("code",[t._v("function sayHi (name =“Lydia”){...}")])]),t._v(" "),s("p",[t._v("在这种情况下,如果我们没有传递值或者如果我们传递"),s("code",[t._v("undefined")]),t._v(","),s("code",[t._v("name")]),t._v("总是等于字符串"),s("code",[t._v("Lydia")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_82-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_82-输出什么"}},[t._v("#")]),t._v(" 82. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" status "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"😎"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" status "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"😍"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("status")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getStatus")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("status"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getStatus")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getStatus")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("call")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"🥑"')]),t._v(" and "),s("code",[t._v('"😍"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"🥑"')]),t._v(" and "),s("code",[t._v('"😎"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"😍"')]),t._v(" and "),s("code",[t._v('"😎"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"😎"')]),t._v(" and "),s("code",[t._v('"😎"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-22"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-22"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("this")]),t._v("关键字的指向取决于使用它的位置。在"),s("strong",[t._v("函数")]),t._v("中,比如"),s("code",[t._v("getStatus")]),t._v(","),s("code",[t._v("this")]),t._v("指向的是调用它的对象,上述例子中"),s("code",[t._v("data")]),t._v("对象调用了"),s("code",[t._v("getStatus")]),t._v(",因此"),s("code",[t._v("this")]),t._v("指向的就是"),s("code",[t._v("data")]),t._v("对象。当我们打印"),s("code",[t._v("this.status")]),t._v("时,"),s("code",[t._v("data")]),t._v("对象的"),s("code",[t._v("status")]),t._v("属性被打印,即"),s("code",[t._v('"🥑"')]),t._v("。")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("call")]),t._v("方法,可以更改"),s("code",[t._v("this")]),t._v("指向的对象。"),s("code",[t._v("data.getStatus.call(this)")]),t._v("是将"),s("code",[t._v("this")]),t._v("的指向由"),s("code",[t._v("data")]),t._v("对象更改为全局对象。在全局对象上,有一个名为"),s("code",[t._v("status")]),t._v("的变量,其值为"),s("code",[t._v("”😎“")]),t._v("。因此打印"),s("code",[t._v("this.status")]),t._v("时,会打印"),s("code",[t._v("“😎”")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_83-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_83-输出什么"}},[t._v("#")]),t._v(" 83. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" city "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("city"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ncity "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Amsterdam"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ name: "Lydia", age: 21 }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ name: "Lydia", age: 21, city: "Amsterdam" }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ name: "Lydia", age: 21, city: undefined }')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"Amsterdam"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-27"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-27"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("我们将变量"),s("code",[t._v("city")]),t._v("设置为等于"),s("code",[t._v("person")]),t._v("对象上名为"),s("code",[t._v("city")]),t._v("的属性的值。这个对象上没有名为"),s("code",[t._v("city")]),t._v("的属性,因此变量"),s("code",[t._v("city")]),t._v("的值为"),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("请注意,我们没有引用"),s("code",[t._v("person")]),t._v("对象本身,只是将变量"),s("code",[t._v("city")]),t._v("设置为等于"),s("code",[t._v("person")]),t._v("对象上"),s("code",[t._v("city")]),t._v("属性的当前值。")]),t._v(" "),s("p",[t._v("然后,我们将"),s("code",[t._v("city")]),t._v("设置为等于字符串"),s("code",[t._v("“Amsterdam”")]),t._v("。这不会更改 person 对象:没有对该对象的引用。")]),t._v(" "),s("p",[t._v("因此打印"),s("code",[t._v("person")]),t._v("对象时,会返回未修改的对象。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_84-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_84-输出什么"}},[t._v("#")]),t._v(" 84. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("checkAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" message "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sorry, you\'re too young."')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" message "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Yay! You\'re old enough!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" message"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("checkAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Sorry, you\'re too young."')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Yay! You\'re old enough!"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-26"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-26"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("const")]),t._v("和"),s("code",[t._v("let")]),t._v("声明的变量是具有"),s("strong",[t._v("块级作用域")]),t._v("的,块是大括号("),s("code",[t._v("{}")]),t._v(")之间的任何东西,即上述情况"),s("code",[t._v("if / else")]),t._v("语句的花括号。由于块级作用域,我们无法在声明的块之外引用变量,因此抛出"),s("code",[t._v("ReferenceError")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_85-什么样的信息将被打印"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_85-什么样的信息将被打印"}},[t._v("#")]),t._v(" 85. 什么样的信息将被打印?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("fetch")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://www.website.com/api/user/1"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("json")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("fetch")]),t._v("方法的结果")]),t._v(" "),s("li",[t._v("B: 第二次调用"),s("code",[t._v("fetch")]),t._v("方法的结果")]),t._v(" "),s("li",[t._v("C: 前一个"),s("code",[t._v(".then()")]),t._v("中回调方法返回的结果")]),t._v(" "),s("li",[t._v("D: 总是"),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-27"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-27"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("第二个"),s("code",[t._v(".then")]),t._v("中"),s("code",[t._v("res")]),t._v("的值等于前一个"),s("code",[t._v(".then")]),t._v("中的回调函数返回的值。你可以像这样继续链接"),s("code",[t._v(".then")]),t._v(",将值传递给下一个处理程序。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_86-哪个选项是将hasname设置为true的方法-前提是不能将true作为参数传递"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_86-哪个选项是将hasname设置为true的方法-前提是不能将true作为参数传递"}},[t._v("#")]),t._v(" 86. 哪个选项是将"),s("code",[t._v("hasName")]),t._v("设置为"),s("code",[t._v("true")]),t._v("的方法,前提是不能将"),s("code",[t._v("true")]),t._v("作为参数传递?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" hasName "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("!!name")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("name")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("new Boolean(name)")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("name.length")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-28"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-28"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("使用逻辑非运算符"),s("code",[t._v("!")]),t._v(",将返回一个布尔值,使用"),s("code",[t._v("!! name")]),t._v(",我们可以确定"),s("code",[t._v("name")]),t._v("的值是真的还是假的。如果"),s("code",[t._v("name")]),t._v("是真实的,那么"),s("code",[t._v("!name")]),t._v("返回"),s("code",[t._v("false")]),t._v("。"),s("code",[t._v("!false")]),t._v("返回"),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[t._v("通过将"),s("code",[t._v("hasName")]),t._v("设置为"),s("code",[t._v("name")]),t._v(",可以将"),s("code",[t._v("hasName")]),t._v("设置为等于传递给"),s("code",[t._v("getName")]),t._v("函数的值,而不是布尔值"),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("new Boolean(true)")]),t._v("返回一个对象包装器,而不是布尔值本身。")]),t._v(" "),s("p",[s("code",[t._v("name.length")]),t._v("返回传递的参数的长度,而不是布尔值"),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("h6",{attrs:{id:"_87-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_87-输出什么"}},[t._v("#")]),t._v(" 87. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I want pizza"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"""')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"I"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-23"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-23"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("可以使用方括号表示法获取字符串中特定索引的字符,字符串中的第一个字符具有索引 0,依此类推。在这种情况下,我们想要得到索引为 0 的元素,字符"),s("code",[t._v("'I'")]),t._v("被记录。")]),t._v(" "),s("p",[t._v("请注意,IE7 及更低版本不支持此方法。在这种情况下,应该使用"),s("code",[t._v(".charAt()")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_88-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_88-输出什么"}},[t._v("#")]),t._v(" 88. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("num1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" num2 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" num1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num1 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" num2"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("20")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-24"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-24"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("您可以将默认参数的值设置为函数的另一个参数,只要另一个参数定义在其之前即可。我们将值"),s("code",[t._v("10")]),t._v("传递给"),s("code",[t._v("sum")]),t._v("函数。如果"),s("code",[t._v("sum")]),t._v("函数只接收 1 个参数,则意味着没有传递"),s("code",[t._v("num2")]),t._v("的值,这种情况下,"),s("code",[t._v("num1")]),t._v("的值等于传递的值"),s("code",[t._v("10")]),t._v("。"),s("code",[t._v("num2")]),t._v("的默认值是"),s("code",[t._v("num1")]),t._v("的值,即"),s("code",[t._v("10")]),t._v("。"),s("code",[t._v("num1 + num2")]),t._v("返回"),s("code",[t._v("20")]),t._v("。")]),t._v(" "),s("p",[t._v("如果您尝试将默认参数的值设置为后面定义的参数,则可能导致参数的值尚未初始化,从而引发错误。比如:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("m "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("m"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Uncaught ReferenceError: Cannot access 'n' before initialization")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 3 2")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 3 4")]),t._v("\n")])])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_89-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_89-输出什么"}},[t._v("#")]),t._v(" 89. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// module.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("default")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hello world"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// index.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("as")]),t._v(" data "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./module"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ default: function default(), name: "Lydia" }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("{ default: function default() }")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ default: "Hello world", name: "Lydia" }')])]),t._v(" "),s("li",[t._v("D: Global object of "),s("code",[t._v("module.js")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-29"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-29"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("import * as name")]),t._v("语法,我们将"),s("code",[t._v("module.js")]),t._v("文件中所有"),s("code",[t._v("export")]),t._v("导入到"),s("code",[t._v("index.js")]),t._v("文件中,并且创建了一个名为"),s("code",[t._v("data")]),t._v("的新对象。在"),s("code",[t._v("module.js")]),t._v("文件中,有两个导出:默认导出和命名导出。默认导出是一个返回字符串“Hello World”的函数,命名导出是一个名为"),s("code",[t._v("name")]),t._v("的变量,其值为字符串"),s("code",[t._v("“Lydia”")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("data")]),t._v("对象具有默认导出的"),s("code",[t._v("default")]),t._v("属性,其他属性具有指定 exports 的名称及其对应的值。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_90-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_90-输出什么"}},[t._v("#")]),t._v(" 90. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" member "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"John"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"class"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"function"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"object"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"string"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-28"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-28"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("类是构造函数的语法糖,如果用构造函数的方式来重写"),s("code",[t._v("Person")]),t._v("类则将是:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("通过"),s("code",[t._v("new")]),t._v("来调用构造函数,将会生成构造函数"),s("code",[t._v("Person")]),t._v("的实例,对实例执行"),s("code",[t._v("typeof")]),t._v("关键字将返回"),s("code",[t._v('"object"')]),t._v(",上述情况打印出"),s("code",[t._v('"object"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_91-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_91-输出什么"}},[t._v("#")]),t._v(" 91. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" newList "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("newList"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[1, 2, 3, 4, 5]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[1, 2, 3, 5]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[1, 2, 3, 4]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Error")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-10"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-10"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v(".push")]),t._v("方法返回数组的长度,而不是数组本身!通过将"),s("code",[t._v("newList")]),t._v("设置为"),s("code",[t._v("[1,2,3].push(4)")]),t._v(",实际上"),s("code",[t._v("newList")]),t._v("等于数组的新长度:"),s("code",[t._v("4")]),t._v("。")]),t._v(" "),s("p",[t._v("然后,尝试在"),s("code",[t._v("newList")]),t._v("上使用"),s("code",[t._v(".push")]),t._v("方法。由于"),s("code",[t._v("newList")]),t._v("是数值"),s("code",[t._v("4")]),t._v(",抛出 TypeError。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_92-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_92-输出什么"}},[t._v("#")]),t._v(" 92. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("giveLydiaPizza")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Here is pizza!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("giveLydiaChocolate")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Here\'s chocolate... now go hit the gym already."')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("giveLydiaPizza"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("giveLydiaChocolate"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("{ constructor: ...}")]),t._v(" "),s("code",[t._v("{ constructor: ...}")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("{}")]),t._v(" "),s("code",[t._v("{ constructor: ...}")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("{ constructor: ...}")]),t._v(" "),s("code",[t._v("{}")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("{ constructor: ...}")]),t._v(" "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-11"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-11"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("常规函数,例如"),s("code",[t._v("giveLydiaPizza")]),t._v("函数,有一个"),s("code",[t._v("prototype")]),t._v("属性,它是一个带有"),s("code",[t._v("constructor")]),t._v("属性的对象(原型对象)。然而,箭头函数,例如"),s("code",[t._v("giveLydiaChocolate")]),t._v("函数,没有这个"),s("code",[t._v("prototype")]),t._v("属性。尝试使用"),s("code",[t._v("giveLydiaChocolate.prototype")]),t._v("访问"),s("code",[t._v("prototype")]),t._v("属性时会返回"),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_93-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_93-输出什么"}},[t._v("#")]),t._v(" 93. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("of")]),t._v(" Object"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("entries")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("name")]),t._v(" "),s("code",[t._v("Lydia")]),t._v(" and "),s("code",[t._v("age")]),t._v(" "),s("code",[t._v("21")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["name", "Lydia"]')]),t._v(" and "),s("code",[t._v('["age", 21]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('["name", "age"]')]),t._v(" and "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Error")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-30"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-30"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("Object.entries()")]),t._v("方法返回一个给定对象自身可枚举属性的键值对数组,上述情况返回一个二维数组,数组每个元素是一个包含键和值的数组:")]),t._v(" "),s("p",[s("code",[t._v("[['name','Lydia'],['age', 21]]")])]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("for-of")]),t._v("循环,我们可以迭代数组中的每个元素,上述情况是子数组。我们可以使用"),s("code",[t._v("const [x,y]")]),t._v("在"),s("code",[t._v("for-of")]),t._v("循环中解构子数组。"),s("code",[t._v("x")]),t._v("等于子数组中的第一个元素,"),s("code",[t._v("y")]),t._v("等于子数组中的第二个元素。")]),t._v(" "),s("p",[t._v("第一个子阵列是"),s("code",[t._v("[“name”,“Lydia”]")]),t._v(",其中"),s("code",[t._v("x")]),t._v("等于"),s("code",[t._v("name")]),t._v(",而"),s("code",[t._v("y")]),t._v("等于"),s("code",[t._v("Lydia")]),t._v("。\n第二个子阵列是"),s("code",[t._v("[“age”,21]")]),t._v(",其中"),s("code",[t._v("x")]),t._v("等于"),s("code",[t._v("age")]),t._v(",而"),s("code",[t._v("y")]),t._v("等于"),s("code",[t._v("21")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_94-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_94-输出什么"}},[t._v("#")]),t._v(" 94. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getItems")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("fruitList"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("args"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" favoriteFruit")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("fruitList"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("args"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" favoriteFruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getItems")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"banana"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"apple"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"pear"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"orange"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('["banana", "apple", "pear", "orange"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('[["banana", "apple"], "pear", "orange"]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('["banana", "apple", ["pear"], "orange"]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-12"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-12"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("... args")]),t._v("是剩余参数,剩余参数的值是一个包含所有剩余参数的数组,"),s("strong",[t._v("并且只能作为最后一个参数")]),t._v("。上述示例中,剩余参数是第二个参数,这是不可能的,并会抛出语法错误。")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getItems")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("fruitList"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" favoriteFruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("args")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("fruitList"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("args"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" favoriteFruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getItems")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"banana"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"apple"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"pear"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"orange"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("上述例子是有效的,将会返回数组:"),s("code",[t._v("[ 'banana', 'apple', 'orange', 'pear' ]")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_95-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_95-输出什么"}},[t._v("#")]),t._v(" "),s("a",{attrs:{name:"20190817"}}),t._v("95. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("nums")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" b")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a is bigger"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b is bigger"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("nums")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("nums")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("a is bigger")]),t._v(", "),s("code",[t._v("6")]),t._v(" and "),s("code",[t._v("b is bigger")]),t._v(", "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("a is bigger")]),t._v(", "),s("code",[t._v("undefined")]),t._v(" and "),s("code",[t._v("b is bigger")]),t._v(", "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")]),t._v(" and "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-25"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-25"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("在 JavaScript 中,我们不必显式地编写分号 ("),s("code",[t._v(";")]),t._v("),但是 JavaScript 引擎仍然在语句之后自动添加分号。这称为"),s("strong",[t._v("自动分号插入")]),t._v("。例如,一个语句可以是变量,或者像"),s("code",[t._v("throw")]),t._v("、"),s("code",[t._v("return")]),t._v("、"),s("code",[t._v("break")]),t._v("这样的关键字。")]),t._v(" "),s("p",[t._v("在这里,我们在新的一行上写了一个"),s("code",[t._v("return")]),t._v("语句和另一个值"),s("code",[t._v("a + b")]),t._v("。然而,由于它是一个新行,引擎并不知道它实际上是我们想要返回的值。相反,它会在"),s("code",[t._v("return")]),t._v("后面自动添加分号。你可以这样看:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\na "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("这意味着永远不会到达"),s("code",[t._v("a + b")]),t._v(",因为函数在"),s("code",[t._v("return")]),t._v("关键字之后停止运行。如果没有返回值,就像这里,函数返回"),s("code",[t._v("undefined")]),t._v("。注意,在"),s("code",[t._v("if/else")]),t._v("语句之后没有自动插入!")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_96-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_96-输出什么"}},[t._v("#")]),t._v(" 96. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nPerson "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("AnotherPerson")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sarah"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" member "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Lydia"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Sarah"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Error: cannot redeclare Person")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-26"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-26"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("我们可以将类设置为等于其他类/函数构造函数。在这种情况下,我们将"),s("code",[t._v("Person")]),t._v("设置为"),s("code",[t._v("AnotherPerson")]),t._v("。这个构造函数的名字是"),s("code",[t._v("Sarah")]),t._v(",所以新的"),s("code",[t._v("Person")]),t._v("实例"),s("code",[t._v("member")]),t._v("上的 name 属性是"),s("code",[t._v("Sarah")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_97-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_97-输出什么"}},[t._v("#")]),t._v(" 97. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" info "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Symbol")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("info"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Object"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("keys")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("info"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("{Symbol('a'): 'b'}")]),t._v(" and "),s("code",[t._v("[\"{Symbol('a')\"]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("{}")]),t._v(" and "),s("code",[t._v("[]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ a: "b" }')]),t._v(" and "),s("code",[t._v('["a"]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("{Symbol('a'): 'b'}")]),t._v(" and "),s("code",[t._v("[]")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-13"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-13"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("Symbol")]),t._v("类型是不可枚举的。"),s("code",[t._v("Object.keys")]),t._v("方法返回对象上的所有可枚举的键属性。"),s("code",[t._v("Symbol")]),t._v("类型是不可见的,并返回一个空数组。记录整个对象时,所有属性都是可见的,甚至是不可枚举的属性。")]),t._v(" "),s("p",[t._v("这是"),s("code",[t._v("Symbol")]),t._v("的众多特性之一:除了表示完全唯一的值(防止对象意外名称冲突,例如当使用 2 个想要向同一对象添加属性的库时),您还可以"),s("code",[t._v("隐藏")]),t._v("这种方式对象的属性(尽管不完全。你仍然可以使用"),s("code",[t._v("Object.getOwnPropertySymbols()")]),t._v("方法访问 "),s("code",[t._v("Symbol")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_98-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_98-输出什么"}},[t._v("#")]),t._v(" 98. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("getList")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("getUser")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("user")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("age "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" list "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" user "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getList")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[1, [2, 3, 4]]")]),t._v(" and "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[1, [2, 3, 4]]")]),t._v(" and "),s("code",[t._v('{ name: "Lydia", age: 21 }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[1, 2, 3, 4]")]),t._v(" and "),s("code",[t._v('{ name: "Lydia", age: 21 }')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Error")]),t._v(" and "),s("code",[t._v('{ name: "Lydia", age: 21 }')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-31"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-31"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("getList")]),t._v("函数接收一个数组作为其参数。在"),s("code",[t._v("getList")]),t._v("函数的括号之间,我们立即解构这个数组。您可以将其视为:")]),t._v(" "),s("p",[s("code",[t._v("[x, ...y] = [1, 2, 3, 4]")])]),t._v(" "),s("p",[t._v("使用剩余的参数"),s("code",[t._v("... y")]),t._v(",我们将所有剩余参数放在一个数组中。在这种情况下,其余的参数是"),s("code",[t._v("2")]),t._v(","),s("code",[t._v("3")]),t._v("和"),s("code",[t._v("4")]),t._v("。 "),s("code",[t._v("y")]),t._v("的值是一个数组,包含所有其余参数。在这种情况下,"),s("code",[t._v("x")]),t._v("的值等于"),s("code",[t._v("1")]),t._v(",所以当我们打印"),s("code",[t._v("[x,y]")]),t._v("时,会打印"),s("code",[t._v("[1,[2,3,4]]")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("getUser")]),t._v("函数接收一个对象。对于箭头函数,如果只返回一个值,我们不必编写花括号。但是,如果您想从一个箭头函数返回一个对象,您必须将它写在圆括号之间,否则两个花括号之间的所有内容都将被解释为一个块语句!在这种情况下,花括号之间的代码不是有效的 JavaScript 代码,因此会抛出 SyntaxError。")]),t._v(" "),s("p",[t._v("以下函数将返回一个对象:")]),t._v(" "),s("p",[s("code",[t._v("const getUser = user => ({ name: user.name, age: user.age })")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_99-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_99-输出什么"}},[t._v("#")]),t._v(" 99. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-29"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-29"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("变量"),s("code",[t._v("name")]),t._v("保存字符串的值,该字符串不是函数,因此无法调用。")]),t._v(" "),s("p",[t._v("当值不是预期类型时,会抛出"),s("code",[t._v("TypeErrors")]),t._v("。JavaScript 期望"),s("code",[t._v("name")]),t._v("是一个函数,因为我们试图调用它。但它是一个字符串,因此抛出"),s("code",[t._v("TypeError")]),t._v(":"),s("code",[t._v("name is not a function")])]),t._v(" "),s("p",[t._v("当你编写了一些非有效的 JavaScript 时,会抛出语法错误,例如当你把"),s("code",[t._v("return")]),t._v("这个词写成"),s("code",[t._v("retrun")]),t._v("时。\n当 JavaScript 无法找到您尝试访问的值的引用时,抛出"),s("code",[t._v("ReferenceErrors")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_100-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_100-输出什么"}},[t._v("#")]),t._v(" 100. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 🎉✨ This is my 100th question! ✨🎉")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" output "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Im"')]),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("possible!\nYou should")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("n't")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" see a therapist after so much JavaScript lol")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("possible! You should see a therapist after so much JavaScript lol")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Impossible! You should see a therapist after so much JavaScript lol")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("possible! You shouldn't see a therapist after so much JavaScript lol")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Impossible! You shouldn't see a therapist after so much JavaScript lol")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-27"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-27"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("[]")]),t._v("是一个真值。使用"),s("code",[t._v("&&")]),t._v("运算符,如果左侧值是真值,则返回右侧值。在这种情况下,左侧值"),s("code",[t._v("[]")]),t._v("是一个真值,所以返回"),s("code",[t._v("Im")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v('""')]),t._v("是一个假值。如果左侧值是假的,则不返回任何内容。"),s("code",[t._v("n't")]),t._v("不会被退回。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_101-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_101-输出什么"}},[t._v("#")]),t._v(" 101.输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" one "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" two "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" three "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" three"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("[]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v('""')]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("{}")]),t._v(" "),s("code",[t._v('""')]),t._v(" "),s("code",[t._v("[]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-30"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-30"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("||")]),t._v("运算符,我们可以返回第一个真值。如果所有值都是假值,则返回最后一个值。")]),t._v(" "),s("p",[s("code",[t._v("(false || {} || null)")]),t._v(":空对象"),s("code",[t._v("{}")]),t._v("是一个真值。这是第一个(也是唯一的)真值,它将被返回。"),s("code",[t._v("one")]),t._v("等于"),s("code",[t._v("{}")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("(null || false ||“”)")]),t._v(":所有值都是假值。这意味着返回传递的值"),s("code",[t._v('""')]),t._v("。"),s("code",[t._v("two")]),t._v("等于"),s("code",[t._v('""')]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("([] || 0 ||“”)")]),t._v(":空数组"),s("code",[t._v("[]")]),t._v("是一个真值。这是第一个返回的真值。"),s("code",[t._v("three")]),t._v("等于"),s("code",[t._v("[]")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_102-依次输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_102-依次输出什么"}},[t._v("#")]),t._v(" 102. 依次输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("myPromise")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I have resolved!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("firstFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myPromise")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"second"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("secondFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myPromise")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"second"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("firstFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("secondFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("I have resolved!")]),t._v(", "),s("code",[t._v("second")]),t._v(" and "),s("code",[t._v("I have resolved!")]),t._v(", "),s("code",[t._v("second")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("second")]),t._v(", "),s("code",[t._v("I have resolved!")]),t._v(" and "),s("code",[t._v("second")]),t._v(", "),s("code",[t._v("I have resolved!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("I have resolved!")]),t._v(", "),s("code",[t._v("second")]),t._v(" and "),s("code",[t._v("second")]),t._v(", "),s("code",[t._v("I have resolved!")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("second")]),t._v(", "),s("code",[t._v("I have resolved!")]),t._v(" and "),s("code",[t._v("I have resolved!")]),t._v(", "),s("code",[t._v("second")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-14"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-14"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("有了 promise,我们通常会说:当我想要调用某个方法,但是由于它可能需要一段时间,因此暂时将它放在一边。只有当某个值被 resolved/rejected,并且执行栈为空时才使用这个值。")]),t._v(" "),s("p",[t._v("我们可以在"),s("code",[t._v("async")]),t._v("函数中通过"),s("code",[t._v(".then")]),t._v("和"),s("code",[t._v("await")]),t._v("关键字获得该值。尽管我们可以通过"),s("code",[t._v(".then")]),t._v("和"),s("code",[t._v("await")]),t._v("获得 promise 的价值,但是它们的工作方式有所不同。")]),t._v(" "),s("p",[t._v("在 "),s("code",[t._v("firstFunction")]),t._v("中,当运行到"),s("code",[t._v("myPromise")]),t._v("方法时我们将其放在一边,即 promise 进入微任务队列,其他后面的代码("),s("code",[t._v("console.log('second')")]),t._v(")照常运行,因此"),s("code",[t._v("second")]),t._v("被打印出,"),s("code",[t._v("firstFunction")]),t._v("方法到此执行完毕,执行栈中宏任务队列被清空,此时开始执行微任务队列中的任务,"),s("code",[t._v("I have resolved")]),t._v("被打印出。")]),t._v(" "),s("p",[t._v("在"),s("code",[t._v("secondFunction")]),t._v("方法中,我们通过"),s("code",[t._v("await")]),t._v("关键字,暂停了后面代码的执行,直到异步函数的值被解析才开始后面代码的执行。这意味着,它会等着直到 "),s("code",[t._v("myPromise")]),t._v(" 以值"),s("code",[t._v("I have resolved")]),t._v("被解决之后,下一行"),s("code",[t._v("second")]),t._v("才开始执行。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_103-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_103-输出什么"}},[t._v("#")]),t._v(" 103. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" set "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Set")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nset"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nset"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nset"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" item "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("of")]),t._v(" set"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("3")]),t._v(", "),s("code",[t._v("NaN")]),t._v(", "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("3")]),t._v(", "),s("code",[t._v("7")]),t._v(", "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("3")]),t._v(", "),s("code",[t._v("Lydia2")]),t._v(", "),s("code",[t._v("[Object object]2")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"12"')]),t._v(", "),s("code",[t._v("Lydia2")]),t._v(", "),s("code",[t._v("[Object object]2")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-31"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-31"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("“+”运算符不仅用于添加数值,还可以使用它来连接字符串。每当 JavaScript 引擎发现一个或多个值不是数字时,就会将数字强制为字符串。")]),t._v(" "),s("p",[t._v("第一个是数字 1。1 + 2 返回数字 3。")]),t._v(" "),s("p",[t._v("但是,第二个是字符串“Lydia”。 “Lydia”是一个字符串,2 是一个数字:2 被强制转换为字符串。 “Lydia”和“2”被连接起来,产生字符串“Lydia2”。")]),t._v(" "),s("p",[s("code",[t._v("{name:“Lydia”}")]),t._v("是一个对象。数字和对象都不是字符串,因此将二者都字符串化。每当我们对常规对象进行字符串化时,它就会变成"),s("code",[t._v("[Object object]")]),t._v("。与“2”串联的“ [Object object]”成为“[Object object]2”。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_104-结果是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_104-结果是什么"}},[t._v("#")]),t._v(" 104. 结果是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("5")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Promise {: 5}")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Promise {: 5}")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Error")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-32"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-32"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("我们可以将我们想要的任何类型的值传递"),s("code",[t._v("Promise.resolve")]),t._v(",无论是否"),s("code",[t._v("promise")]),t._v("。该方法本身返回带有已解析值的"),s("code",[t._v("Promise")]),t._v(" ("),s("code",[t._v("")]),t._v(")。如果您传递常规函数,它将是具有常规值的已解决"),s("code",[t._v("promise")]),t._v("。如果你通过了 promise,它将是一个已经 resolved 的且带有传的值的 promise。")]),t._v(" "),s("p",[t._v("上述情况,我们传了数字 5,因此返回一个 resolved 状态的 promise,resolve 值为"),s("code",[t._v("5")])]),t._v(" "),s("h6",{attrs:{id:"_105-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_105-输出什么"}},[t._v("#")]),t._v(" 105. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("compareMembers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("person1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" person2 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person1 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!==")]),t._v(" person2"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Not the same!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"They are the same!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("compareMembers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Not the same!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("They are the same!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-28"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-28"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("对象通过引用传递。当我们检查对象的严格相等性(===)时,我们正在比较它们的引用。")]),t._v(" "),s("p",[t._v("我们将“person2”的默认值设置为“person”对象,并将“person”对象作为“person1”的值传递。")]),t._v(" "),s("p",[t._v("这意味着两个值都引用内存中的同一位置,因此它们是相等的。")]),t._v(" "),s("p",[t._v("运行“else”语句中的代码块,并记录"),s("code",[t._v("They are the same!")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_106-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_106-输出什么"}},[t._v("#")]),t._v(" 106. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" colorConfig "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("red")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("blue")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("green")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("black")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("yellow")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" colors "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"pink"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"red"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"blue"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("colorConfig"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("colors"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-15"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-15"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("在 JavaScript 中,我们有两种访问对象属性的方法:括号表示法或点表示法。在此示例中,我们使用点表示法("),s("code",[t._v("colorConfig.colors")]),t._v(")代替括号表示法("),s("code",[t._v("colorConfig [“colors”]")]),t._v(")。")]),t._v(" "),s("p",[t._v("使用点表示法,JavaScript 会尝试使用该确切名称在对象上查找属性。在此示例中,JavaScript 尝试在 colorConfig 对象上找到名为 colors 的属性。没有名为“colors”的属性,因此返回“undefined”。\n然后,我们尝试使用"),s("code",[t._v("[1]")]),t._v("访问第一个元素的值。我们无法对未定义的值执行此操作,因此会抛出"),s("code",[t._v("Cannot read property '1' of undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("JavaScript 解释(或取消装箱)语句。当我们使用方括号表示法时,它会看到第一个左方括号"),s("code",[t._v("[")]),t._v("并一直进行下去,直到找到右方括号"),s("code",[t._v("]")]),t._v("。只有这样,它才会评估该语句。如果我们使用了 colorConfig [colors [1]],它将返回 colorConfig 对象上 red 属性的值。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_107-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_107-输出什么"}},[t._v("#")]),t._v(" 107. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"❤️"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"❤️"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-32"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-32"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("在内部,表情符号是 unicode。heat 表情符号的 unicode 是"),s("code",[t._v("“U + 2764 U + FE0F”")]),t._v("。对于相同的表情符号,它们总是相同的,因此我们将两个相等的字符串相互比较,这将返回 true。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_108-哪些方法修改了原数组"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_108-哪些方法修改了原数组"}},[t._v("#")]),t._v(" 108. 哪些方法修改了原数组?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" emojis "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"😍"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("map")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("filter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("find")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reduce")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("acc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" cur")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" acc "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("slice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("splice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("All of them")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("map")]),t._v(" "),s("code",[t._v("reduce")]),t._v(" "),s("code",[t._v("slice")]),t._v(" "),s("code",[t._v("splice")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("map")]),t._v(" "),s("code",[t._v("slice")]),t._v(" "),s("code",[t._v("splice")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("splice")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-16"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-16"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("splice")]),t._v("方法,我们通过删除,替换或添加元素来修改原始数组。在这种情况下,我们从索引 1 中删除了 2 个元素(我们删除了"),s("code",[t._v("'🥑'")]),t._v("和"),s("code",[t._v("'😍'")]),t._v("),同时添加了 ✨emoji 表情。")]),t._v(" "),s("p",[s("code",[t._v("map")]),t._v(","),s("code",[t._v("filter")]),t._v("和"),s("code",[t._v("slice")]),t._v("返回一个新数组,"),s("code",[t._v("find")]),t._v("返回一个元素,而"),s("code",[t._v("reduce")]),t._v("返回一个减小的值。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_109-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_109-输出什么"}},[t._v("#")]),t._v(" "),s("a",{attrs:{name:"20191009"}}),t._v("109. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" food "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍕"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍫"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍔"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" info "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("favoriteFood")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" food"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\ninfo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("favoriteFood "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍝"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("food"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("['🍕', '🍫', '🥑', '🍔']")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("['🍝', '🍫', '🥑', '🍔']")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("['🍝', '🍕', '🍫', '🥑', '🍔']")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-33"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-33"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("我们将"),s("code",[t._v("info")]),t._v("对象上的"),s("code",[t._v("favoriteFood")]),t._v("属性的值设置为披萨表情符号“🍕”的字符串。字符串是原始数据类型。在 JavaScript 中,原始数据类型通过值起作用")]),t._v(" "),s("p",[t._v("在这种情况下,我们将"),s("code",[t._v("info")]),t._v("对象上的"),s("code",[t._v("favoriteFood")]),t._v("属性的值设置为等于"),s("code",[t._v("food")]),t._v("数组中的第一个元素的值,字符串为披萨表情符号("),s("code",[t._v("'🍕'")]),t._v(")。字符串是原始数据类型,并且通过值进行交互,我们更改"),s("code",[t._v("info")]),t._v("对象上"),s("code",[t._v("favoriteFood")]),t._v("属性的值。food 数组没有改变,因为 favoriteFood 的值只是该数组中第一个元素的值的复制,并且与该元素上的元素没有相同的内存引用食物"),s("code",[t._v("[0]")]),t._v("。当我们记录食物时,它仍然是原始数组"),s("code",[t._v("['🍕','🍫','🥑','🍔']")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_110-这个函数干了什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_110-这个函数干了什么"}},[t._v("#")]),t._v(" 110. 这个函数干了什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: Parses JSON to a JavaScript value")]),t._v(" "),s("li",[t._v("B: Parses a JavaScript object to JSON")]),t._v(" "),s("li",[t._v("C: Parses any JavaScript value to JSON")]),t._v(" "),s("li",[t._v("D: Parses JSON to a JavaScript object only")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-34"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-34"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("JSON.parse()")]),t._v("方法,我们可以将 JSON 字符串解析为 JavaScript 值。")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 将数字字符串化为有效的 JSON,然后将 JSON 字符串解析为 JavaScript 值:")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" jsonNumber "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("stringify")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// '4'")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("jsonNumber"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 4")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 将数组值字符串化为有效的 JSON,然后将 JSON 字符串解析为 JavaScript 值:")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" jsonArray "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("stringify")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// '[1, 2, 3]'")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("jsonArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// [1, 2, 3]")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 将对象字符串化为有效的 JSON,然后将 JSON 字符串解析为 JavaScript 值:")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" jsonArray "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("stringify")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// \'{"name":"Lydia"}\'')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("jsonArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// { name: 'Lydia' }")]),t._v("\n")])])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_111-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_111-输出什么"}},[t._v("#")]),t._v(" 111. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sarah"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: Lydia")]),t._v(" "),s("li",[t._v("B: Sarah")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-17"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-17"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("每个函数都有其自己的执行上下文。"),s("code",[t._v("getName")]),t._v("函数首先在其自身的上下文(范围)内查找,以查看其是否包含我们尝试访问的变量"),s("code",[t._v("name")]),t._v("。上述情况,"),s("code",[t._v("getName")]),t._v("函数包含其自己的"),s("code",[t._v("name")]),t._v("变量:我们用"),s("code",[t._v("let")]),t._v("关键字和"),s("code",[t._v("Sarah")]),t._v("的值声明变量"),s("code",[t._v("name")]),t._v("。")]),t._v(" "),s("p",[t._v("带有"),s("code",[t._v("let")]),t._v("关键字(和"),s("code",[t._v("const")]),t._v(")的变量被提升,但是与"),s("code",[t._v("var")]),t._v("不同,它不会被**_ 初始化_**。在我们声明(初始化)它们之前,无法访问它们。这称为“暂时性死区”。当我们尝试在声明变量之前访问变量时,JavaScript 会抛出"),s("code",[t._v("ReferenceError: Cannot access 'name' before initialization")]),t._v("。")]),t._v(" "),s("p",[t._v("如果我们不在"),s("code",[t._v("getName")]),t._v("函数中声明"),s("code",[t._v("name")]),t._v("变量,则 javascript 引擎会查看原型链。会找到其外部作用域有一个名为"),s("code",[t._v("name")]),t._v("的变量,其值为"),s("code",[t._v("Lydia")]),t._v("。在这种情况下,它将打印"),s("code",[t._v("Lydia")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Lydia")]),t._v("\n")])])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_112-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_112-输出什么"}},[t._v("#")]),t._v(" 112. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generatorOne")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generatorTwo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" one "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generatorOne")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" two "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generatorTwo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("a")]),t._v(" and "),s("code",[t._v("a")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("a")]),t._v(" and "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("['a', 'b', 'c']")]),t._v(" and "),s("code",[t._v("a")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("a")]),t._v(" and "),s("code",[t._v("['a', 'b', 'c']")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-33"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-33"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("yield")]),t._v(" 关键字,我们在 "),s("code",[t._v("Generator")]),t._v(" 函数里执行"),s("code",[t._v("yield")]),t._v("表达式。通过 "),s("code",[t._v("yield*")]),t._v(" 关键字,我们可以在一个"),s("code",[t._v("Generator")]),t._v(" 函数里面执行("),s("code",[t._v("yield")]),t._v("表达式)另一个 "),s("code",[t._v("Generator")]),t._v(" 函数,或可遍历的对象 (如数组).")]),t._v(" "),s("p",[t._v("在函数 "),s("code",[t._v("generatorOne")]),t._v(" 中,我们通过 "),s("code",[t._v("yield")]),t._v(" 关键字 yield 了一个完整的数组 "),s("code",[t._v("['a', 'b', 'c']")]),t._v("。函数"),s("code",[t._v("one")]),t._v("通过"),s("code",[t._v("next")]),t._v("方法返回的对象的"),s("code",[t._v("value")]),t._v(" 属性的值 ("),s("code",[t._v("one.next().value")]),t._v(") 等价于数组 "),s("code",[t._v("['a', 'b', 'c']")]),t._v(".")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ['a', 'b', 'c']")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// undefined")]),t._v("\n")])])]),s("p",[t._v("在函数 "),s("code",[t._v("generatorTwo")]),t._v(" 中,我们使用 "),s("code",[t._v("yield*")]),t._v(" 关键字。就相当于函数"),s("code",[t._v("two")]),t._v("第一个"),s("code",[t._v("yield")]),t._v("的值,等价于在迭代器中第一个 "),s("code",[t._v("yield")]),t._v(" 的值。数组"),s("code",[t._v("['a', 'b', 'c']")]),t._v("就是这个迭代器。第一个 "),s("code",[t._v("yield")]),t._v(" 的值就是 "),s("code",[t._v("a")]),t._v(",所以我们第一次调用 "),s("code",[t._v("two.next().value")]),t._v("时,就返回"),s("code",[t._v("a")]),t._v("。")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 'a'")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 'b'")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 'c'")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// undefined")]),t._v("\n")])])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_113-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_113-输出什么"}},[t._v("#")]),t._v(" 113. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I love"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" to program")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("I love to program")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("undefined to program")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("${(x => x)('I love') to program")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-35"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-35"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("带有模板字面量的表达式首先被执行。相当于字符串会包含表达式,这个立即执行函数 "),s("code",[t._v("(x => x)('I love')")]),t._v(" 返回的值。我们向箭头函数 "),s("code",[t._v("x => x")]),t._v(" 传递 "),s("code",[t._v("'I love'")]),t._v(" 作为参数。"),s("code",[t._v("x")]),t._v(" 等价于返回的 "),s("code",[t._v("'I love'")]),t._v("。这就是结果 "),s("code",[t._v("I love to program")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_114-将会发生什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_114-将会发生什么"}},[t._v("#")]),t._v(" 114. 将会发生什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" config "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("alert")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setInterval")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Alert!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconfig "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("setInterval")]),t._v(" 的回调不会被调用")]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("setInterval")]),t._v(" 的回调被调用一次")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("setInterval")]),t._v(" 的回调仍然会被每秒钟调用")]),t._v(" "),s("li",[t._v("D: 我们从没调用过 "),s("code",[t._v("config.alert()")]),t._v(", config 为 "),s("code",[t._v("null")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-34"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-34"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("一般情况下当我们将对象赋值为 "),s("code",[t._v("null")]),t._v(",那些对象会被进行 "),s("em",[t._v("垃圾回收(garbage collected)")]),t._v(" 因为已经没有对这些对象的引用了。然而,"),s("code",[t._v("setInterval")]),t._v("的参数是一个箭头函数(所以上下文绑定到对象 "),s("code",[t._v("config")]),t._v(" 了),回调函数仍然保留着对 "),s("code",[t._v("config")]),t._v("的引用。只要存在引用,对象就不会被垃圾回收。因为没有被垃圾回收,"),s("code",[t._v("setInterval")]),t._v(" 的回调每 1000ms (1s) 会被调用一次。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_115-哪一个方法会返回-hello-world"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_115-哪一个方法会返回-hello-world"}},[t._v("#")]),t._v(" 115. 哪一个方法会返回 "),s("code",[t._v("'Hello world!'")]),t._v(" ?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myMap "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Map")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("myFunc")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"greeting"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nmyMap"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("set")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("myFunc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hello world!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//1")]),t._v("\nmyMap"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"greeting"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//2")]),t._v("\nmyMap"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("myFunc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//3")]),t._v("\nmyMap"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"greeting"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 1")]),t._v(" "),s("li",[t._v("B: 2")]),t._v(" "),s("li",[t._v("C: 2 and 3")]),t._v(" "),s("li",[t._v("D: All of them")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-29"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-29"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("当通过 "),s("code",[t._v("set")]),t._v(" 方法添加一个键值对,一个传递给 "),s("code",[t._v("set")]),t._v("方法的参数将会是键名,第二个参数将会是值。在这个 case 里,键名为 "),s("em",[t._v("函数")]),t._v(" "),s("code",[t._v("() => 'greeting'")]),t._v(",值为"),s("code",[t._v("'Hello world'")]),t._v("。 "),s("code",[t._v("myMap")]),t._v(" 现在就是 "),s("code",[t._v("{ () => 'greeting' => 'Hello world!' }")]),t._v("。")]),t._v(" "),s("p",[t._v("1 是错的,因为键名不是 "),s("code",[t._v("'greeting'")]),t._v(" 而是 "),s("code",[t._v("() => 'greeting'")]),t._v("。\n3 是错的,因为我们给"),s("code",[t._v("get")]),t._v(" 方法传递了一个新的函数。对象受 "),s("em",[t._v("引用")]),t._v(" 影响。函数也是对象,因此两个函数严格上并不等价,尽管他们相同:他们有两个不同的内存引用地址。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_116-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_116-输出什么"}},[t._v("#")]),t._v(" 116. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("changeAge")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("person "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("changeAgeAndName")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("person "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sarah"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("changeAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("changeAgeAndName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{name: "Sarah", age: 22}')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{name: "Sarah", age: 23}')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{name: "Lydia", age: 22}')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('{name: "Lydia", age: 23}')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-35"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-35"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("函数 "),s("code",[t._v("changeAge")]),t._v(" 和函数 "),s("code",[t._v("changeAgeAndName")]),t._v(" 有着不同的参数,定义一个 "),s("em",[t._v("新")]),t._v(" 生成的对象 "),s("code",[t._v("{ ...person }")]),t._v("。这个对象有着所有 "),s("code",[t._v("person")]),t._v(" 对象 中 k/v 值的副本。")]),t._v(" "),s("p",[t._v("首项,我们调用 "),s("code",[t._v("changeAge")]),t._v(" 函数并传递 "),s("code",[t._v("person")]),t._v(" 对象作为它的参数。这个函数对 "),s("code",[t._v("age")]),t._v(" 属性进行加一操作。"),s("code",[t._v("person")]),t._v(" 现在是 "),s("code",[t._v('{ name: "Lydia", age: 22 }')]),t._v("。")]),t._v(" "),s("p",[t._v("然后,我们调用函数 "),s("code",[t._v("changeAgeAndName")]),t._v(",然而我们没有传递参数。取而代之,"),s("code",[t._v("x")]),t._v(" 的值等价 "),s("em",[t._v("new")]),t._v(" 生成的对象:"),s("code",[t._v("{ ...person }")]),t._v("。因为它是一个新生成的对象,它并不会对对象 "),s("code",[t._v("person")]),t._v(" 造成任何副作用。"),s("code",[t._v("person")]),t._v(" 仍然等价于 "),s("code",[t._v('{ name: "Lydia", age: 22 }')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_117-下面那个选项将会返回-6"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_117-下面那个选项将会返回-6"}},[t._v("#")]),t._v(" 117. 下面那个选项将会返回 "),s("code",[t._v("6")]),t._v("?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sumValues")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" z")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" z"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("sumValues([...1, 2, 3])")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("sumValues([...[1, 2, 3]])")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("sumValues(...[1, 2, 3])")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("sumValues([1, 2, 3])")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-36"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-36"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("通过展开操作符 "),s("code",[t._v("...")]),t._v(",我们可以 "),s("em",[t._v("暂开")]),t._v(" 单个可迭代的元素。函数 "),s("code",[t._v("sumValues")]),t._v(" function 接收三个参数:"),s("code",[t._v("x")]),t._v(", "),s("code",[t._v("y")]),t._v(" 和 "),s("code",[t._v("z")]),t._v("。"),s("code",[t._v("...[1, 2, 3]")]),t._v(" 的执行结果为 "),s("code",[t._v("1, 2, 3")]),t._v(",将会传递给函数 "),s("code",[t._v("sumValues")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_118-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_118-输出什么"}},[t._v("#")]),t._v(" 118. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" list "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥳"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🤠"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥰"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🤪"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("🤠")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("🥰")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-30"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-30"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("+=")]),t._v(" 操作符,我们对值 "),s("code",[t._v("num")]),t._v(" 进行加 "),s("code",[t._v("1")]),t._v(" 操作。"),s("code",[t._v("num")]),t._v(" 有初始值 "),s("code",[t._v("1")]),t._v(",因此 "),s("code",[t._v("1 + 1")]),t._v(" 的执行结果为 "),s("code",[t._v("2")]),t._v("。数组 "),s("code",[t._v("list")]),t._v(" 的第二项为 🥰,"),s("code",[t._v("console.log(list[2])")]),t._v(" 输出 🥰.")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_119-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_119-输出什么"}},[t._v("#")]),t._v(" 119. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("firstName")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("lastName")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("pet")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Mara"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("breed")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Dutch Tulip Hound"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFullName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("firstName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("pet"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("pet"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),t._v("family"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("getFullName"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("getLastName"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Mara")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("Lydia Hallie")]),t._v(" "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Mara")]),t._v(" "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("Lydia Hallie")]),t._v(" "),s("code",[t._v("null")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("ReferenceError")]),t._v(" "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-31"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-31"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("通过 ES10 或 TS3.7+"),s("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"}},[t._v("可选链操作符 "),s("code",[t._v("?.")]),s("OutboundLink")],1),t._v(",我们不再需要显式检测更深层的嵌套值是否有效。如果我们尝试获取 "),s("code",[t._v("undefined")]),t._v(" 或 "),s("code",[t._v("null")]),t._v(" 的值 ("),s("em",[t._v("nullish")]),t._v("),表达将会短路并返回 "),s("code",[t._v("undefined")]),t._v(".")]),t._v(" "),s("p",[s("code",[t._v("person.pet?.name")]),t._v(":"),s("code",[t._v("person")]),t._v(" 有一个名为 "),s("code",[t._v("pet")]),t._v(" 的属性:"),s("code",[t._v("person.pet")]),t._v(" 不是 nullish。它有个名为 "),s("code",[t._v("name")]),t._v(" 的属性,并返回字符串 "),s("code",[t._v("Mara")]),t._v("。\n"),s("code",[t._v("person.pet?.family?.name")]),t._v(":"),s("code",[t._v("person")]),t._v(" 有一个名为 "),s("code",[t._v("pet")]),t._v(" 的属性:"),s("code",[t._v("person.pet")]),t._v(" 不是 nullish. "),s("code",[t._v("pet")]),t._v(" "),s("em",[t._v("并没有")]),t._v(" 一个名为 "),s("code",[t._v("family")]),t._v(" 的属性,"),s("code",[t._v("person.pet.family")]),t._v(" 是 nullish。表达式返回 "),s("code",[t._v("undefined")]),t._v("。\n"),s("code",[t._v("person.getFullName?.()")]),t._v(":"),s("code",[t._v("person")]),t._v(" 有一个名为 "),s("code",[t._v("getFullName")]),t._v(" 的属性:"),s("code",[t._v("person.getFullName()")]),t._v(" 不是 nullish 并可以被调用,返回字符串 "),s("code",[t._v("Lydia Hallie")]),t._v("。\n"),s("code",[t._v("member.getLastName?.()")]),t._v(": 变量"),s("code",[t._v("member")]),t._v(" 不存在,因此会抛出错误"),s("code",[t._v("ReferenceError")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_120-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_120-输出什么"}},[t._v("#")]),t._v(" 120. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" groceries "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"banana"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"apple"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"peanuts"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("groceries"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("indexOf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"banana"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"We have to buy bananas!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("We don't have to buy bananas!")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: We have to buy bananas!")]),t._v(" "),s("li",[t._v("B: We don't have to buy bananas")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("1")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-32"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-32"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("我们传递了一个状态 "),s("code",[t._v('groceries.indexOf("banana")')]),t._v(" 给 if 条件语句。"),s("code",[t._v('groceries.indexOf("banana")')]),t._v(" 返回 "),s("code",[t._v("0")]),t._v(",一个 falsy 的值。因为 if 条件语句的状态为 falsy,"),s("code",[t._v("else")]),t._v(" 块区内的代码执行,并且 "),s("code",[t._v("We don't have to buy bananas!")]),t._v(" 被输出。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_121-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_121-输出什么"}},[t._v("#")]),t._v(" 121. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" config "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("languages")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("set")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("language")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("lang")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("languages"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("lang"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("language"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("function language(lang) { this.languages.push(lang }")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("0")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-18"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-18"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("方法 "),s("code",[t._v("language")]),t._v(" 是一个 "),s("code",[t._v("setter")]),t._v("。Setters 并不保存一个实际值,它们的使命在于 "),s("em",[t._v("修改")]),t._v(" 属性。当调用方法 "),s("code",[t._v("setter")]),t._v(",返回 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_122-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_122-输出什么"}},[t._v("#")]),t._v(" 122. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"object"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"string"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-37"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-37"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("typeof name")]),t._v(" 返回 "),s("code",[t._v('"string"')]),t._v("。字符串 "),s("code",[t._v('"string"')]),t._v(" 是一个 truthy 的值,因此 "),s("code",[t._v("!typeof name")]),t._v(" 返回一个布尔值 "),s("code",[t._v("false")]),t._v("。"),s("code",[t._v('false === "object"')]),t._v(" 和 "),s("code",[t._v('false === "string"')]),t._v(" 都返回 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("p",[t._v("(如果我们想检测一个值的类型,我们应该用 "),s("code",[t._v("!==")]),t._v(" 而不是 "),s("code",[t._v("!typeof")]),t._v(")")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_123-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_123-输出什么"}},[t._v("#")]),t._v(" 123. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("add")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("y")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("z")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" z"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" z"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("6")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("4")]),t._v(" "),s("code",[t._v("5")]),t._v(" "),s("code",[t._v("6")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("6")]),t._v(" "),s("code",[t._v("5")]),t._v(" "),s("code",[t._v("4")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("4")]),t._v(" "),s("code",[t._v("function")]),t._v(" "),s("code",[t._v("function")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("6")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-36"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-36"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("函数 "),s("code",[t._v("add")]),t._v(" 是一个返回 返回箭头函数的箭头函数 的箭头函数(still with me?)。第一个函数接收一个值为 "),s("code",[t._v("4")]),t._v(" 的参数 "),s("code",[t._v("x")]),t._v("。我们调用第二个函数,它接收一个值为 "),s("code",[t._v("5")]),t._v(" 的参数 "),s("code",[t._v("y")]),t._v("。然后我们调用第三个函数,它接收一个值为 "),s("code",[t._v("6")]),t._v(" 的参数 "),s("code",[t._v("z")]),t._v("。当我们尝试在最后一个箭头函数中获取 "),s("code",[t._v("x")]),t._v(", "),s("code",[t._v("y")]),t._v(" 和 "),s("code",[t._v("z")]),t._v(" 的值,JS 引擎根据作用域链去找 "),s("code",[t._v("x")]),t._v(" 和 "),s("code",[t._v("y")]),t._v(" 的值。得到 "),s("code",[t._v("4")]),t._v(" "),s("code",[t._v("5")]),t._v(" "),s("code",[t._v("6")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_124-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_124-输出什么"}},[t._v("#")]),t._v(" 124. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("range")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("start"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" end")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" start"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" end"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" gen "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("range")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" item "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("of")]),t._v(" gen"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Promise {1}")]),t._v(" "),s("code",[t._v("Promise {2}")]),t._v(" "),s("code",[t._v("Promise {3}")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Promise {}")]),t._v(" "),s("code",[t._v("Promise {}")]),t._v(" "),s("code",[t._v("Promise {}")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-38"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-38"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("我们给 函数 range 传递:"),s("code",[t._v("Promise{1}")]),t._v(", "),s("code",[t._v("Promise{2}")]),t._v(", "),s("code",[t._v("Promise{3}")]),t._v(",Generator 函数 "),s("code",[t._v("range")]),t._v(" 返回一个全是 async object promise 数组。我们将 async object 赋值给变量 "),s("code",[t._v("gen")]),t._v(",之后我们使用"),s("code",[t._v("for await ... of")]),t._v(" 进行循环遍历。我们将返回的 Promise 实例赋值给 "),s("code",[t._v("item")]),t._v(":第一个返回 "),s("code",[t._v("Promise{1}")]),t._v(",第二个返回 "),s("code",[t._v("Promise{2}")]),t._v(",之后是 "),s("code",[t._v("Promise{3}")]),t._v("。因为我们正 "),s("em",[t._v("awaiting")]),t._v(" "),s("code",[t._v("item")]),t._v(" 的值,resolved 状态的 promise,promise 数组的 resolved "),s("em",[t._v("值")]),t._v(" 以此为:"),s("code",[t._v("1")]),t._v(","),s("code",[t._v("2")]),t._v(","),s("code",[t._v("3")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_125-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_125-输出什么"}},[t._v("#")]),t._v(" 125. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("myFunc")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" z "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" z"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("{1: 1}")]),t._v(" "),s("code",[t._v("{2: 2}")]),t._v(" "),s("code",[t._v("{3: 3}")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("{ 1: undefined }")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-19"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-19"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("myFunc")]),t._v(" 期望接收一个包含 "),s("code",[t._v("x")]),t._v(", "),s("code",[t._v("y")]),t._v(" 和 "),s("code",[t._v("z")]),t._v(" 属性的对象作为它的参数。因为我们仅仅传递三个单独的数字值 (1, 2, 3) 而不是一个含有 "),s("code",[t._v("x")]),t._v(", "),s("code",[t._v("y")]),t._v(" 和 "),s("code",[t._v("z")]),t._v(" 属性的对象 ({x: 1, y: 2, z: 3}),"),s("code",[t._v("x")]),t._v(", "),s("code",[t._v("y")]),t._v(" 和 "),s("code",[t._v("z")]),t._v(" 有着各自的默认值 "),s("code",[t._v("undefined")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_126-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_126-输出什么"}},[t._v("#")]),t._v(" 126. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFine")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("speed"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" amount")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" formattedSpeed "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Intl"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("NumberFormat")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"en-US"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("style")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"unit"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("unit")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"mile-per-hour"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("format")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("speed"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" formattedAmount "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Intl"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("NumberFormat")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"en-US"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("style")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"currency"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("currency")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"USD"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("format")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("amount"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("The driver drove ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("formattedSpeed"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" and has to pay ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("formattedAmount"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFine")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("130")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("300")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: The driver drove 130 and has to pay 300")]),t._v(" "),s("li",[t._v("B: The driver drove 130 mph and has to pay $300.00")]),t._v(" "),s("li",[t._v("C: The driver drove undefined and has to pay undefined")]),t._v(" "),s("li",[t._v("D: The driver drove 130.00 and has to pay 300.00")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-33"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-33"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("通过方法 "),s("code",[t._v("Intl.NumberFormat")]),t._v(",我们可以格式化任意区域的数字值。我们对数字值 "),s("code",[t._v("130")]),t._v(" 进行 "),s("code",[t._v("mile-per-hour")]),t._v(" 作为 "),s("code",[t._v("unit")]),t._v(" 的 "),s("code",[t._v("en-US")]),t._v(" 区域 格式化,结果为 "),s("code",[t._v("130 mph")]),t._v("。对数字值 "),s("code",[t._v("300")]),t._v(" 进行 "),s("code",[t._v("USD")]),t._v(" 作为 "),s("code",[t._v("currency")]),t._v(" 的 "),s("code",[t._v("en-US")]),t._v(" 区域格式化,结果为 "),s("code",[t._v("$300.00")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_127-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_127-输出什么"}},[t._v("#")]),t._v(" 127. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" spookyItems "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"👻"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🎃"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🕸"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("item")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" spookyItems"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("item")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"💀"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("spookyItems"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('["👻", "🎃", "🕸"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["👻", "🎃", "🕸", "💀"]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('["👻", "🎃", "🕸", { item: "💀" }]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('["👻", "🎃", "🕸", "[object Object]"]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-34"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-34"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v('通过解构对象们,我们可以从右手边的对象中拆出值,并且将拆出的值分配给左手边对象同名的属性。在这种情况下,我们将值 "💀" 分配给 '),s("code",[t._v("spookyItems[3]")]),t._v("。相当于我们正在篡改数组 "),s("code",[t._v("spookyItems")]),t._v(',我们给它添加了值 "💀"。当输出 '),s("code",[t._v("spookyItems")]),t._v(" 时,结果为 "),s("code",[t._v('["👻", "🎃", "🕸", "💀"]')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_128-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_128-输出什么"}},[t._v("#")]),t._v(" 128. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("isNaN")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("isNaN")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("isNaN")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("isNaN")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-39"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-39"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("通过方法 "),s("code",[t._v("Number.isNaN")]),t._v(",你可以检测你传递的值是否为 "),s("em",[t._v("数字值")]),t._v(" 并且是否等价于 "),s("code",[t._v("NaN")]),t._v("。"),s("code",[t._v("name")]),t._v(" 不是一个数字值,因此 "),s("code",[t._v("Number.isNaN(name)")]),t._v(" 返回 "),s("code",[t._v("false")]),t._v("。"),s("code",[t._v("age")]),t._v(" 是一个数字值,但它不等价于 "),s("code",[t._v("NaN")]),t._v(",因此 "),s("code",[t._v("Number.isNaN(age)")]),t._v(" 返回 "),s("code",[t._v("false")]),t._v(".")]),t._v(" "),s("p",[t._v("通过方法 "),s("code",[t._v("isNaN")]),t._v(",你可以检测你传递的值是否一个 number。"),s("code",[t._v("name")]),t._v(" 不是一个 "),s("code",[t._v("number")]),t._v(",因此 "),s("code",[t._v("isNaN(name)")]),t._v(" 返回 "),s("code",[t._v("true")]),t._v(". "),s("code",[t._v("age")]),t._v(" 是一个 "),s("code",[t._v("number")]),t._v(" 因此 "),s("code",[t._v("isNaN(age)")]),t._v(" 返回 "),s("code",[t._v("false")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_129-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_129-输出什么"}},[t._v("#")]),t._v(" 129. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" randomValue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getInfo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" randomValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" randomValue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getInfo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"number"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"string"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-20"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-20"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("const")]),t._v(" 关键字声明的变量在被初始化之前不可被引用:这被称之为 "),s("em",[t._v("暂时性死区")]),t._v("。在函数 "),s("code",[t._v("getInfo")]),t._v(" 中,变量 "),s("code",[t._v("randomValue")]),t._v(" 声明在"),s("code",[t._v("getInfo")]),t._v(" 的作用域的此法环境中。在想要对 "),s("code",[t._v("typeof randomValue")]),t._v(" 进行 log 之前,变量 "),s("code",[t._v("randomValue")]),t._v(" 仍未被初始化:错误"),s("code",[t._v("ReferenceError")]),t._v(" 被抛出!JS 引擎并不会根据作用域链网上寻找该变量,因为我们已经在 "),s("code",[t._v("getInfo")]),t._v(" 函数中声明了 "),s("code",[t._v("randomValue")]),t._v(" 变量。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_130-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_130-输出什么"}},[t._v("#")]),t._v(" 130. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myPromise "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Woah some cool data"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("try")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" myPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("catch")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("throw")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Oops didn't work")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("finally")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Oh finally!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Woah some cool data")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Oh finally!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Woah some cool data")]),t._v(" "),s("code",[t._v("Oh finally!")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Oops didn't work")]),t._v(" "),s("code",[t._v("Oh finally!")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-40"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-40"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("在 "),s("code",[t._v("try")]),t._v(" 块区,我们打印 "),s("code",[t._v("myPromise")]),t._v(" 变量的 awaited 值:"),s("code",[t._v('"Woah some cool data"')]),t._v("。因为"),s("code",[t._v("try")]),t._v(" 块区没有错误抛出,"),s("code",[t._v("catch")]),t._v(" 块区的代码并不执行。"),s("code",[t._v("finally")]),t._v(" 块区的代码 "),s("em",[t._v("总是")]),t._v(" 执行,"),s("code",[t._v('"Oh finally!"')]),t._v(" 被输出。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_131-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_131-输出什么"}},[t._v("#")]),t._v(" 131. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" emojis "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍕"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍕"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("emojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("flat")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("['🥑', ['✨', '✨', ['🍕', '🍕']]]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("['🥑', '✨', '✨', ['🍕', '🍕']]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("['🥑', ['✨', '✨', '🍕', '🍕']]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("['🥑', '✨', '✨', '🍕', '🍕']")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-35"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-35"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("通过方法 "),s("code",[t._v("flat")]),t._v(",我们可以创建一个新的,已被扁平化的数组。被扁平化的深度取决于我们传递的值。在这个 case 里,我们传递了值 "),s("code",[t._v("1")]),t._v(" (并不必要,这是默认值),相当于只有第一层的数组才会被连接。即这个 case 里的 "),s("code",[t._v("['🥑']")]),t._v(" and "),s("code",[t._v("['✨', '✨', ['🍕', '🍕']]")]),t._v("。连接这两个数组得到结果 "),s("code",[t._v("['🥑', '✨', '✨', ['🍕', '🍕']]")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_132-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_132-输出什么"}},[t._v("#")]),t._v(" "),s("a",{attrs:{name:"20191224"}}),t._v("132. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" counterOne "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ncounterOne"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ncounterOne"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" counterTwo "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" counterOne"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ncounterTwo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("counterOne"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("0")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("1")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("3")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-21"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-21"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("counterOne")]),t._v(" 是类 "),s("code",[t._v("Counter")]),t._v(" 的一个实例。类 Counter 包含一个"),s("code",[t._v("count")]),t._v(" 属性在它的构造函数里,和一个 "),s("code",[t._v("increment")]),t._v(" 方法。首先,我们通过 "),s("code",[t._v("counterOne.increment()")]),t._v(" 调用方法 "),s("code",[t._v("increment")]),t._v(" 两次。现在,"),s("code",[t._v("counterOne.count")]),t._v(" 为 "),s("code",[t._v("2")]),t._v(".")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/KxLlTm9.png",width:"400"}}),t._v(" "),s("p",[t._v("然后,我们创建一个新的变量 "),s("code",[t._v("counterTwo")]),t._v(" 并将 "),s("code",[t._v("counterOne")]),t._v(" 的引用地址赋值给它。因为对象受引用地址的影响,我们刚刚创建了一个新的对象,其引用地址和 "),s("code",[t._v("counterOne")]),t._v(" 的等价。因此它们指向同一块内存地址,任何对其的副作用都会影响 "),s("code",[t._v("counterTwo")]),t._v("。现在 "),s("code",[t._v("counterTwo.count")]),t._v(" 为 "),s("code",[t._v("2")]),t._v("。")]),t._v(" "),s("p",[t._v("我们调用 "),s("code",[t._v("counterTwo.increment()")]),t._v(" 将 "),s("code",[t._v("count")]),t._v(" 的值设为 "),s("code",[t._v("3")]),t._v("。然后,我们打印 "),s("code",[t._v("counterOne")]),t._v(" 里的 count,结果为 "),s("code",[t._v("3")]),t._v("。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/BNBHXmc.png",width:"400"}}),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_133-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_133-输出什么"}},[t._v("#")]),t._v(" 133. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myPromise "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Promise!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("funcOne")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n myPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Timeout!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Last line!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("funcTwo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" res "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" myPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Timeout!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Last line!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("funcOne")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("funcTwo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Promise! Last line! Promise! Last line! Last line! Promise!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Last line! Timeout! Promise! Last line! Timeout! Promise!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Promise! Last line! Last line! Promise! Timeout! Timeout!")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Last line! Promise! Promise! Last line! Timeout! Timeout!")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-22"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-22"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("首先,我们调用 "),s("code",[t._v("funcOne")]),t._v("。在函数 "),s("code",[t._v("funcOne")]),t._v(" 的第一行,我们调用"),s("code",[t._v("myPromise")]),t._v(" promise "),s("em",[t._v("异步操作")]),t._v("。当 JS 引擎在忙于执行 promise,它继续执行函数 "),s("code",[t._v("funcOne")]),t._v("。下一行 "),s("em",[t._v("异步操作")]),t._v(" "),s("code",[t._v("setTimeout")]),t._v(",其回调函数被 Web API 调用。 (详情请参考我关于 event loop 的文章.)")]),t._v(" "),s("p",[t._v("promise 和 timeout 都是异步操作,函数继续执行当 JS 引擎忙于执行 promise 和 处理 "),s("code",[t._v("setTimeout")]),t._v(" 的回调。相当于 "),s("code",[t._v("Last line!")]),t._v(" 首先被输出,因为它不是异步操作。执行完 "),s("code",[t._v("funcOne")]),t._v(" 的最后一行,promise 状态转变为 resolved,"),s("code",[t._v("Promise!")]),t._v(" 被打印。然而,因为我们调用了 "),s("code",[t._v("funcTwo()")]),t._v(",调用栈不为空,"),s("code",[t._v("setTimeout")]),t._v(" 的回调仍不能入栈。")]),t._v(" "),s("p",[t._v("我们现在处于 "),s("code",[t._v("funcTwo")]),t._v(",先 "),s("em",[t._v("awaiting")]),t._v(" myPromise。通过 "),s("code",[t._v("await")]),t._v(" 关键字,我们暂停了函数的执行直到 promise 状态变为 resolved (或 rejected)。然后,我们输出 "),s("code",[t._v("res")]),t._v(" 的 awaited 值(因为 promise 本身返回一个 promise)。接着输出 "),s("code",[t._v("Promise!")]),t._v("。")]),t._v(" "),s("p",[t._v("下一行就是 "),s("em",[t._v("异步操作")]),t._v(" "),s("code",[t._v("setTimeout")]),t._v(",其回调函数被 Web API 调用。")]),t._v(" "),s("p",[t._v("我们执行到函数 "),s("code",[t._v("funcTwo")]),t._v(" 的最后一行,输出 "),s("code",[t._v("Last line!")]),t._v("。现在,因为 "),s("code",[t._v("funcTwo")]),t._v(" 出栈,调用栈为空。在事件队列中等待的回调函数("),s("code",[t._v('() => console.log("Timeout!")')]),t._v(" from "),s("code",[t._v("funcOne")]),t._v(", and "),s("code",[t._v('() => console.log("Timeout!")')]),t._v(" from "),s("code",[t._v("funcTwo")]),t._v(")以此入栈。第一个回调输出 "),s("code",[t._v("Timeout!")]),t._v(",并出栈。然后,第二个回调输出 "),s("code",[t._v("Timeout!")]),t._v(",并出栈。得到结果 "),s("code",[t._v("Last line! Promise! Promise! Last line! Timeout! Timeout!")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_134-我们怎样才能在-index-js-中调用-sum-js-中的-sum"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_134-我们怎样才能在-index-js-中调用-sum-js-中的-sum"}},[t._v("#")]),t._v(" 134. 我们怎样才能在 "),s("code",[t._v("index.js")]),t._v(" 中调用 "),s("code",[t._v("sum.js?")]),t._v(" 中的 "),s("code",[t._v("sum")]),t._v("?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// sum.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("default")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// index.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("as")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./sum"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("sum(4)")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("sum.sum(4)")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("sum.default(4)")])]),t._v(" "),s("li",[t._v("D: 默认导出不用 "),s("code",[t._v("*")]),t._v(" 来导入,只能具名导出")])]),t._v(" "),s("h4",{attrs:{id:"答案-c-41"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-41"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用符号 "),s("code",[t._v("*")]),t._v(",我们引入文件中的所有值,包括默认和具名。如果我们有以下文件:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// info.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("default")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I love JavaScript"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// index.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("as")]),t._v(" info "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./info"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("info"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("将会输出以下内容:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("default")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I love JavaScript"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("以 "),s("code",[t._v("sum")]),t._v(" 为例,相当于以下形式引入值 "),s("code",[t._v("sum")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("default")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("我们可以通过调用 "),s("code",[t._v("sum.default")]),t._v(" 来调用该函数")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_135-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_135-输出什么"}},[t._v("#")]),t._v(" 135. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" handler "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("set")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Added a new property!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("get")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Accessed a property!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Proxy")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" handler"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nperson"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nperson"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Added a new property!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Accessed a property!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Added a new property!")]),t._v(" "),s("code",[t._v("Accessed a property!")])]),t._v(" "),s("li",[t._v("D: 没有任何输出")])]),t._v(" "),s("h4",{attrs:{id:"答案-c-42"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-42"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用 Proxy 对象,我们可以给一个对象添加自定义行为。在这个 case,我们传递一个包含以下属性的对象 "),s("code",[t._v("handler")]),t._v(" : "),s("code",[t._v("set")]),t._v(" and "),s("code",[t._v("get")]),t._v("。每当我们 "),s("em",[t._v("设置")]),t._v(" 属性值时 "),s("code",[t._v("set")]),t._v(" 被调用,每当我们 "),s("em",[t._v("获取")]),t._v(" 时 "),s("code",[t._v("get")]),t._v(" 被调用。")]),t._v(" "),s("p",[t._v("第一个参数是一个空对象 "),s("code",[t._v("{}")]),t._v(",作为 "),s("code",[t._v("person")]),t._v(" 的值。对于这个对象,自定义行为被定义在对象 "),s("code",[t._v("handler")]),t._v("。如果我们向对象 "),s("code",[t._v("person")]),t._v(" 添加属性,"),s("code",[t._v("set")]),t._v(" 将被调用。如果我们获取 "),s("code",[t._v("person")]),t._v(" 的属性,"),s("code",[t._v("get")]),t._v(" 将被调用。")]),t._v(" "),s("p",[t._v("首先,我们向 proxy 对象 ("),s("code",[t._v('person.name = "Lydia"')]),t._v(") 添加一个属性 "),s("code",[t._v("name")]),t._v("。"),s("code",[t._v("set")]),t._v(" 被调用并输出 "),s("code",[t._v('"Added a new property!"')]),t._v("。")]),t._v(" "),s("p",[t._v("然后,我们获取 proxy 对象的一个属性,对象 handler 的属性 "),s("code",[t._v("get")]),t._v(" 被调用。输出 "),s("code",[t._v('"Accessed a property!"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_136-以下哪一项会对对象-person-有副作用"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_136-以下哪一项会对对象-person-有副作用"}},[t._v("#")]),t._v(" 136. 以下哪一项会对对象 "),s("code",[t._v("person")]),t._v(" 有副作用?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nObject"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("seal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('person.name = "Evan Bacon"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("person.age = 21")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("delete person.name")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Object.assign(person, { age: 21 })")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-37"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-37"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("使用 "),s("code",[t._v("Object.seal")]),t._v(" 我们可以防止新属性 "),s("em",[t._v("被添加")]),t._v(",或者存在属性 "),s("em",[t._v("被移除")]),t._v(".")]),t._v(" "),s("p",[t._v("然而,你仍然可以对存在属性进行更改。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_137-以下哪一项会对对象-person-有副作用"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_137-以下哪一项会对对象-person-有副作用"}},[t._v("#")]),t._v(" 137. 以下哪一项会对对象 "),s("code",[t._v("person")]),t._v(" 有副作用?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("address")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("street")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"100 Main St"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nObject"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("freeze")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('person.name = "Evan Bacon"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("delete person.address")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('person.address.street = "101 Main St"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('person.pet = { name: "Mara" }')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-43"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-43"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用方法 "),s("code",[t._v("Object.freeze")]),t._v(" 对一个对象进行 "),s("em",[t._v("冻结")]),t._v("。不能对属性进行添加,修改,删除。")]),t._v(" "),s("p",[t._v("然而,它仅 对对象进行 "),s("em",[t._v("浅")]),t._v(" 冻结,意味着只有 对象中的 "),s("em",[t._v("直接")]),t._v(" 属性被冻结。如果属性是另一个 object,像案例中的 "),s("code",[t._v("address")]),t._v(","),s("code",[t._v("address")]),t._v(" 中的属性没有被冻结,仍然可以被修改。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_138-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_138-输出什么"}},[t._v("#")]),t._v(" 138. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("add")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" value "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("4")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("6")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("NaN")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("Error")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("6")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("4")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("Error")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-38"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-38"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("首先我们不传递任何参数调用 "),s("code",[t._v("myFunc()")]),t._v("。因为我们没有传递参数,"),s("code",[t._v("num")]),t._v(" 和 "),s("code",[t._v("value")]),t._v(" 获取它们各自的默认值:num 为 "),s("code",[t._v("2")]),t._v(",而 "),s("code",[t._v("value")]),t._v(" 为函数 "),s("code",[t._v("add")]),t._v(" 的返回值。对于函数 "),s("code",[t._v("add")]),t._v(",我们传递值为 2 的 "),s("code",[t._v("num")]),t._v(" 作为参数。函数 "),s("code",[t._v("add")]),t._v(" 返回 "),s("code",[t._v("4")]),t._v(" 作为 "),s("code",[t._v("value")]),t._v(" 的值。")]),t._v(" "),s("p",[t._v("然后,我们调用 "),s("code",[t._v("myFunc(3)")]),t._v(" 并传递值 "),s("code",[t._v("3")]),t._v(" 参数 "),s("code",[t._v("num")]),t._v(" 的值。我们没有给 "),s("code",[t._v("value")]),t._v(" 传递值。因为我们没有给参数 "),s("code",[t._v("value")]),t._v(" 传递值,它获取默认值:函数 "),s("code",[t._v("add")]),t._v(" 的返回值。对于函数 "),s("code",[t._v("add")]),t._v(",我们传递值为 3 的 "),s("code",[t._v("num")]),t._v("给它。函数 "),s("code",[t._v("add")]),t._v(" 返回 "),s("code",[t._v("6")]),t._v(" 作为 "),s("code",[t._v("value")]),t._v(" 的值。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_139-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_139-输出什么"}},[t._v("#")]),t._v(" 139. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n #number "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("#number"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getNum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("#number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" counter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ncounter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("#number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("10")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("11")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-23"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-23"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("在 ES2020 中,通过 "),s("code",[t._v("#")]),t._v(" 我们可以给 class 添加私有变量。在 class 的外部我们无法获取该值。当我们尝试输出 "),s("code",[t._v("counter.#number")]),t._v(",语法错误被抛出:我们无法在 class "),s("code",[t._v("Counter")]),t._v(" 外部获取它!")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_140-选择哪一个"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_140-选择哪一个"}},[t._v("#")]),t._v(" 140. 选择哪一个?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" teams "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Team 1"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("members")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Paul"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lisa"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Team 2"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("members")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Laura"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Tim"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getMembers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("members")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" members"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" members"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getTeams")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("teams")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" teams"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ✨ SOMETHING IS MISSING HERE ✨")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" obj "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getTeams")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("teams"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nobj"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// { value: "Paul", done: false }')]),t._v("\nobj"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// { value: "Lisa", done: false }')]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("yield getMembers(teams[i].members)")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("yield* getMembers(teams[i].members)")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("return getMembers(teams[i].members)")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("return yield getMembers(teams[i].members)")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-36"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-36"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("为了遍历 "),s("code",[t._v("teams")]),t._v(" 数组中对象的属性 "),s("code",[t._v("members")]),t._v(" 中的每一项,我们需要将 "),s("code",[t._v("teams[i].members")]),t._v(" 传递给 Generator 函数 "),s("code",[t._v("getMembers")]),t._v("。Generator 函数返回一个 generator 对象。为了遍历这个 generator 对象中的每一项,我们需要使用 "),s("code",[t._v("yield*")]),t._v(".")]),t._v(" "),s("p",[t._v("如果我们没有写 "),s("code",[t._v("yield")]),t._v(","),s("code",[t._v("return yield")]),t._v(" 或者 "),s("code",[t._v("return")]),t._v(",整个 Generator 函数不会第一时间 return 当我们调用 "),s("code",[t._v("next")]),t._v(" 方法。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_141-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_141-输出什么"}},[t._v("#")]),t._v(" 141. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("hobbies")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"coding"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addHobby")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("hobby"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" hobbies "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("hobbies")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n hobbies"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("hobby"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" hobbies"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addHobby")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"running"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addHobby")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"dancing"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addHobby")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"baking"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("hobbies"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("hobbies"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('["coding"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["coding", "dancing"]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('["coding", "dancing", "baking"]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('["coding", "running", "dancing", "baking"]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-44"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-44"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("函数 "),s("code",[t._v("addHobby")]),t._v(" 接受两个参数,"),s("code",[t._v("hobby")]),t._v(" 和有着对象 "),s("code",[t._v("person")]),t._v(" 中数组 "),s("code",[t._v("hobbies")]),t._v(" 默认值的 "),s("code",[t._v("hobbies")]),t._v("。")]),t._v(" "),s("p",[t._v("首相,我们调用函数 "),s("code",[t._v("addHobby")]),t._v(",并给 "),s("code",[t._v("hobby")]),t._v(" 传递 "),s("code",[t._v('"running"')]),t._v(" 以及给 "),s("code",[t._v("hobbies")]),t._v(" 传递一个空数组。因为我们给 "),s("code",[t._v("hobbies")]),t._v(" 传递了空数组,"),s("code",[t._v('"running"')]),t._v(" 被添加到这个空数组。")]),t._v(" "),s("p",[t._v("然后,我们调用函数 "),s("code",[t._v("addHobby")]),t._v(",并给 "),s("code",[t._v("hobby")]),t._v(" 传递 "),s("code",[t._v('"dancing"')]),t._v("。我们不向 "),s("code",[t._v("hobbies")]),t._v(" 传递值,因此它获取其默认值 —— 对象 "),s("code",[t._v("person")]),t._v(" 的 属性 "),s("code",[t._v("hobbies")]),t._v("。我们向数组 "),s("code",[t._v("person.hobbies")]),t._v(" push "),s("code",[t._v("dancing")]),t._v("。")]),t._v(" "),s("p",[t._v("最后,我们调用函数 "),s("code",[t._v("addHobby")]),t._v(",并向 "),s("code",[t._v("hobby")]),t._v(" 传递 值 "),s("code",[t._v('"baking"')]),t._v(",并且向 "),s("code",[t._v("hobbies")]),t._v(" 传递 "),s("code",[t._v("person.hobbies")]),t._v("。我们向数组 "),s("code",[t._v("person.hobbies")]),t._v(" push "),s("code",[t._v("dancing")]),t._v("。")]),t._v(" "),s("p",[t._v("pushing "),s("code",[t._v("dancing")]),t._v(" 和 "),s("code",[t._v("baking")]),t._v(" 之后,"),s("code",[t._v("person.hobbies")]),t._v(" 的值为 "),s("code",[t._v('["coding", "dancing", "baking"]')])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_142-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_142-输出什么"}},[t._v("#")]),t._v(" 142. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Bird")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I\'m a bird. 🦢"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Flamingo")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("extends")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Bird")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I\'m pink. 🌸"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pet "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Flamingo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("I'm pink. 🌸")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("I'm pink. 🌸")]),t._v(" "),s("code",[t._v("I'm a bird. 🦢")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("I'm a bird. 🦢")]),t._v(" "),s("code",[t._v("I'm pink. 🌸")])]),t._v(" "),s("li",[t._v("D: Nothing, we didn't call any method")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-37"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-37"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("我们创建了类 "),s("code",[t._v("Flamingo")]),t._v(" 的实例 "),s("code",[t._v("pet")]),t._v("。当我们实例化这个实例,"),s("code",[t._v("Flamingo")]),t._v(" 中的 "),s("code",[t._v("constructor")]),t._v(" 被调用。首相,输出 "),s("code",[t._v('"I\'m pink. 🌸"')]),t._v(",之后我们调用"),s("code",[t._v("super()")]),t._v("。"),s("code",[t._v("super()")]),t._v(" 调用父类的构造函数,"),s("code",[t._v("Bird")]),t._v("。"),s("code",[t._v("Bird")]),t._v(" 的构造函数被调用,并输出 "),s("code",[t._v('"I\'m a bird. 🦢"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_143-哪一个选项会导致报错"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_143-哪一个选项会导致报错"}},[t._v("#")]),t._v(" 143. 哪一个选项会导致报错?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" emojis "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🎄"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🎅🏼"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🎁"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"⭐"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 1 */")]),t._v(" emojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🦌"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 2 */")]),t._v(" emojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("splice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 3 */")]),t._v(" emojis "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("emojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥂"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 4 */")]),t._v(" emojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 1")]),t._v(" "),s("li",[t._v("B: 1 and 2")]),t._v(" "),s("li",[t._v("C: 3 and 4")]),t._v(" "),s("li",[t._v("D: 3")])]),t._v(" "),s("h4",{attrs:{id:"答案-d-24"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-24"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("const")]),t._v(" 关键字意味着我们不能 "),s("em",[t._v("重定义")]),t._v(" 变量中的值,它 "),s("em",[t._v("仅可读")]),t._v("。然而,值本身不可修改。数组 "),s("code",[t._v("emojis")]),t._v(" 中的值可被修改,如 push 新的值,拼接,又或者将数组的长度设置为 0。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_144-我们需要向对象-person-添加什么-以致执行-person-时获得形如-lydia-hallie-21-的输出"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_144-我们需要向对象-person-添加什么-以致执行-person-时获得形如-lydia-hallie-21-的输出"}},[t._v("#")]),t._v(" 144. 我们需要向对象 "),s("code",[t._v("person")]),t._v(" 添加什么,以致执行 "),s("code",[t._v("[...person]")]),t._v(" 时获得形如 "),s("code",[t._v('["Lydia Hallie", 21]')]),t._v(" 的输出?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// ["Lydia Hallie", 21]')]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 不需要,对象默认就是可迭代的")]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("*[Symbol.iterator]() { for (let x in this) yield* this[x] }")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("*[Symbol.iterator]() { yield* Object.values(this) }")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("*[Symbol.iterator]() { for (let x in this) yield this }")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-45"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-45"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("对象默认并不是可迭代的。如果迭代规则被定义,则一个对象是可迭代的(An iterable is an iterable if the iterator protocol is present)。我们可以通过添加迭代器 symbol "),s("code",[t._v("[Symbol.iterator]")]),t._v(" 来定义迭代规则,其返回一个 generator 对象,比如说构建一个 generator 函数 "),s("code",[t._v("*[Symbol.iterator]() {}")]),t._v("。如果我们想要返回数组 "),s("code",[t._v('["Lydia Hallie", 21]')]),t._v(": "),s("code",[t._v("yield* Object.values(this)")]),t._v(",这个 generator 函数一定要 yield 对象 "),s("code",[t._v("person")]),t._v(" 的"),s("code",[t._v("Object.values")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_145-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_145-输出什么"}},[t._v("#")]),t._v(" 145. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" nums "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nnums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("forEach")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("num")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 1")]),t._v(" "),s("li",[t._v("B: 2")]),t._v(" "),s("li",[t._v("C: 3")]),t._v(" "),s("li",[t._v("D: 4\n")])]),t._v(" "),s("h4",{attrs:{id:"答案-c-46"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-46"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("在 "),s("code",[t._v("forEach")]),t._v(" 循环内部的 "),s("code",[t._v("if")]),t._v(" 会判断 "),s("code",[t._v("num")]),t._v(" 的值是 truthy 或者是 falsy。因为 "),s("code",[t._v("nums")]),t._v(" 数组的第一个数字是 "),s("code",[t._v("0")]),t._v(",一个 falsy 值,"),s("code",[t._v("if")]),t._v(" 语句代码块不会被执行。"),s("code",[t._v("count")]),t._v(" 仅仅在 "),s("code",[t._v("nums")]),t._v(" 数组的其他 3 个数字 "),s("code",[t._v("1")]),t._v(","),s("code",[t._v("2")]),t._v(","),s("code",[t._v("3")]),t._v(" 时加 1。因为 "),s("code",[t._v("count")]),t._v(" 执行了 3 次加 "),s("code",[t._v("1")]),t._v(" 运算,所以 "),s("code",[t._v("count")]),t._v(" 的值为 "),s("code",[t._v("3")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_146-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_146-输出是什么"}},[t._v("#")]),t._v(" 146. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFruit")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("fruits")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("fruits"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFruit")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍊"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍌"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍍"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFruit")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFruit")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍍"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍊"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍌"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("null")]),t._v(", "),s("code",[t._v("undefined")]),t._v(", 🍌")]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[]")]),t._v(", "),s("code",[t._v("null")]),t._v(", 🍌")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[]")]),t._v(", "),s("code",[t._v("[]")]),t._v(", 🍌")]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(", "),s("code",[t._v("undefined")]),t._v(", 🍌")])]),t._v(" "),s("h4",{attrs:{id:"答案-d-25"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-25"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("?")]),t._v(" 允许我们去选择性地访问对象内部更深层的嵌套属性。我们尝试打印 "),s("code",[t._v("fruits")]),t._v(" 数组索引值为 "),s("code",[t._v("1")]),t._v(" 的子数组内部的索引值为 "),s("code",[t._v("1")]),t._v(" 的元素。如果在 "),s("code",[t._v("fruits")]),t._v(" 数组索引值 为 "),s("code",[t._v("1")]),t._v(" 的位置不存在元素,会直接返回 "),s("code",[t._v("undefined")]),t._v("。如果 "),s("code",[t._v("fruits")]),t._v(" 数组在索引值为 "),s("code",[t._v("1")]),t._v(" 的位置存在元素,但是子数组在索引值为 "),s("code",[t._v("1")]),t._v(" 的位置不存在元素,也会返回 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("首先,我们尝试打印 "),s("code",[t._v("[['🍊', '🍌'], ['🍍']]")]),t._v(" 的子数组 "),s("code",[t._v("['🍍']")]),t._v(" 的第 2 个元素。这个子数组只包含一个元素,也就意味着在索引值为 "),s("code",[t._v("1")]),t._v(" 的位置不存在元素,所以返回的是 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("其次,我们在没有传入任何参数调用了 "),s("code",[t._v("getFruits")]),t._v(" 函数,也就意味着形参 "),s("code",[t._v("fruits")]),t._v(" 的默认值为"),s("code",[t._v("undefined")]),t._v("。因为我们选择性地链接了 "),s("code",[t._v("fruits")]),t._v(" 在索引值为 "),s("code",[t._v("1")]),t._v(" 的元素,因为在索引值为 "),s("code",[t._v("1")]),t._v(" 的位置不存在元素,因此返回的是 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("最后,我们尝试打印 "),s("code",[t._v("['🍍'], ['🍊', '🍌']")]),t._v(" 的子数组 "),s("code",[t._v("['🍊', '🍌']")]),t._v(" 的第 2 个元素。子数组索引值为 "),s("code",[t._v("1")]),t._v("的位置为 "),s("code",[t._v("🍌")]),t._v(",因此它被打印出了。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_147-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_147-输出什么"}},[t._v("#")]),t._v(" 147. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Calc")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increase")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" calc "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Calc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Calc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increase")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("calc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("0")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("1")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-39"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-39"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("我们设置 "),s("code",[t._v("calc")]),t._v(" 变量为 "),s("code",[t._v("Calc")]),t._v(" 类的一个新实例。然后,我们初始化一个 "),s("code",[t._v("Calc")]),t._v(" 的新实例,而且调用了这个实例的 "),s("code",[t._v("increase")]),t._v(" 方法。因为 count 属性是在 "),s("code",[t._v("Calc")]),t._v(" class 的 constructor 内部的,所以 count 属性不会在 "),s("code",[t._v("Calc")]),t._v(" 的原型链上共享出去。这就意味着 calc 实例的 count 值不会被更新,count 仍然是 "),s("code",[t._v("0")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_148-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_148-输出什么"}},[t._v("#")]),t._v(" 148. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" user "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("email")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"e@mail.com"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("password")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"12345"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("updateUser")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" password "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n Object"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("assign")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" email "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("password"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("password "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" password"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" updatedUser "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("updateUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("email")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"new@email.com"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("updatedUser "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-38"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-38"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("updateUser")]),t._v(" 函数更新 user 的 "),s("code",[t._v("email")]),t._v(" 和 "),s("code",[t._v("password")]),t._v(" 属性的值,如果它们的值传入函数,函数返回的就是 "),s("code",[t._v("user")]),t._v(" 对象。"),s("code",[t._v("updateUser")]),t._v(" 函数的返回值是 "),s("code",[t._v("user")]),t._v(" 对象,意味着 updatedUser 的值与 "),s("code",[t._v("user")]),t._v(" 指向的是同一个 "),s("code",[t._v("user")]),t._v(" 对象。"),s("code",[t._v("updatedUser === user")]),t._v(" 为 "),s("code",[t._v("true")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_149-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_149-输出什么"}},[t._v("#")]),t._v(" 149. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" fruit "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍌"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍊"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍎"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nfruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("slice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nfruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("splice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nfruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("unshift")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍇"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("fruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("['🍌', '🍊', '🍎']")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("['🍊', '🍎']")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("['🍇', '🍊', '🍎']")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("['🍇', '🍌', '🍊', '🍎']")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-47"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-47"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("首先,我们在 fruit 数组上调用 "),s("code",[t._v("slice")]),t._v(" 方法。slice 方法不会修改原始数组,但是会返回从数组切片下来的值:香蕉 emoji。\n其次,我们在 fruit 数组上调用 "),s("code",[t._v("splice")]),t._v(" 方法。splice 方法会修改原始数组,也就意味着 fruit 数组此时为 "),s("code",[t._v("['🍊', '🍎']")]),t._v("。\n最后,我们在 fruit 数组上调用 "),s("code",[t._v("unshift")]),t._v(" 方法,通过添加一个值的方式改变了原始数组,添加的是'🍇',它成为了数组的第一个元素。现在 fruit 数组的组成为 "),s("code",[t._v("['🍇', '🍊', '🍎']")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_150-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_150-输出什么"}},[t._v("#")]),t._v(" 150. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" animals "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" dog "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("emoji")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🐶"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" cat "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("emoji")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🐈"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nanimals"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("dog"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("dog"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Mara"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nanimals"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("cat"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("cat"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sara"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("animals"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("dog"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ emoji: "🐶", name: "Mara" }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ emoji: "🐈", name: "Sara" }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-39"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-39"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("对象的键会被转换为字符串。")]),t._v(" "),s("p",[t._v("因为 "),s("code",[t._v("dog")]),t._v(" 的值是一个对象,"),s("code",[t._v("animals[dog]")]),t._v(" 实际上意味着我们创建了一个叫做 "),s("code",[t._v('"object Object"')]),t._v(" 的属性来代表新的对象。"),s("code",[t._v('animals["object Object"]')]),t._v(" 现在等于 "),s("code",[t._v('{ emoji: "🐶", name: "Mara"}')]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("cat")]),t._v(" 也是一个对象,"),s("code",[t._v("animals[cat]")]),t._v(" 实际上意味着我们在用新的 cat 的属性覆盖 "),s("code",[t._v('animals[``"``object Object``"``]')]),t._v(" 的值。")]),t._v(" "),s("p",[t._v("打印 "),s("code",[t._v("animals[dog]")]),t._v(",实际上是"),s("code",[t._v('animals["object Object"]')]),t._v(",这是因为转化"),s("code",[t._v("dog")]),t._v("对象为一个字符串结果 "),s("code",[t._v('"object Object"')]),t._v(",所以返回 "),s("code",[t._v('{ emoji: "🐈", name: "Sara" }')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_151-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_151-输出什么"}},[t._v("#")]),t._v(" 151. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" user "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("email")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"my@email.com"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("updateEmail")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("email")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("email "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nuser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("updateEmail")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"new@email.com"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("my@email.com")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("new@email.com")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-40"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-40"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("updateEmail")]),t._v(" 函数是一个箭头函数,它没有和 "),s("code",[t._v("user")]),t._v(" 对象绑定。这就意味着 "),s("code",[t._v("this")]),t._v(" 关键字不会引用到 "),s("code",[t._v("user")]),t._v(" 对象,但是会引用到全局对象。"),s("code",[t._v("user")]),t._v(" 对象内部的 "),s("code",[t._v("email")]),t._v(" 的值不会更新。当打印 "),s("code",[t._v("user.email")]),t._v(" 的时候,原始值 "),s("code",[t._v("my@email.com")]),t._v(" 被返回。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_152-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_152-输出什么"}},[t._v("#")]),t._v(" 152. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" promise1 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"First"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" promise2 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Second"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" promise3 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reject")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Third"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" promise4 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Fourth"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("runPromises")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" res1 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("all")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("promise1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" promise2"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" res2 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("all")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("promise3"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" promise4"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("res1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" res2"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("runPromises")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("catch")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("err")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[['First', 'Second'], ['Fourth']]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[['First', 'Second'], ['Third', 'Fourth']]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[['First', 'Second']]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("'Third'")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-26"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-26"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("Promise.all")]),t._v(" 方法可以并行式运行 promise。如果其中一个 promise 失败了,"),s("code",[t._v("Promise.all")]),t._v(" 方法会带上被 reject 的 promise 的值"),s("em",[t._v("rejects")]),t._v("。在这个例子中,"),s("code",[t._v("promise3")]),t._v(" 带着 "),s("code",[t._v('"Third"')]),t._v(" 值 reject。我们在调用 "),s("code",[t._v("runPromises")]),t._v(" 时在 "),s("code",[t._v("runPromises")]),t._v(" 函数内部的 "),s("code",[t._v("catch")]),t._v(" 方法去捕获任意 error 从而捕获到被 reject 的值。因为 "),s("code",[t._v("promise3")]),t._v(" 带着 "),s("code",[t._v('"Third"')]),t._v(" 被 reject,所以只有 "),s("code",[t._v('"Third"')]),t._v(" 打印。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_153-哪个作为method的值可以打印-name-lydia-age-22"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_153-哪个作为method的值可以打印-name-lydia-age-22"}},[t._v("#")]),t._v(" 153. 哪个作为"),s("code",[t._v("method")]),t._v("的值可以打印"),s("code",[t._v('{ name: "Lydia", age: 22 }')]),t._v("?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" keys "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"name"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"age"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" values "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" method "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* ?? */")]),t._v("\n Object"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("method"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n keys"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("map")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("_"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" i")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("keys"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" values"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// { name: "Lydia", age: 22 }')]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("entries")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("values")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("fromEntries")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("forEach")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-48"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-48"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("fromEntries")]),t._v(" 方法可以将二维数组转换为对象。在每个子数组的第一个元素是 key,在每个子数组的第二个元素是 value。在这个例子中,我们映射了 "),s("code",[t._v("keys")]),t._v(" 数组,它返回了一个数组,数组的第一个元素为 keys 数组当前索引的值,第二个元素为 values 数组当前索引的值。")]),t._v(" "),s("p",[t._v("这样就创建了一个包含正确 keys 和 values 的子数组的数组,因此结果为"),s("code",[t._v('{ name: "Lydia", age: 22 }')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_154-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_154-输出什么"}},[t._v("#")]),t._v(" 154. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("createMember")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" address "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" validEmail "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token regex"}},[s("span",{pre:!0,attrs:{class:"token regex-delimiter"}},[t._v("/")]),s("span",{pre:!0,attrs:{class:"token regex-source language-regex"}},[t._v(".+\\@.+\\..+")]),s("span",{pre:!0,attrs:{class:"token regex-delimiter"}},[t._v("/")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),t._v("validEmail"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("throw")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Valid email pls"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("address")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" address "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?")]),t._v(" address "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" member "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("createMember")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("email")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"my@email.com"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ email: "my@email.com", address: null }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ email: "my@email.com" }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ email: "my@email.com", address: {} }')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('{ email: "my@email.com", address: undefined }')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-49"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-49"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("address")]),t._v(" 的默认值是一个空对象 "),s("code",[t._v("{}")]),t._v("。当我们设置 "),s("code",[t._v("member")]),t._v(" 变量为 "),s("code",[t._v("createMember")]),t._v(" 函数返回的对象,我们没有为 address 参数传值,意味着 address 的值为默认的空对象 "),s("code",[t._v("{}")]),t._v("。一个空对象是一个 truthy 值,意味着 "),s("code",[t._v("address ? address : null")]),t._v(" 条件会返回 "),s("code",[t._v("true")]),t._v("。address 的值为空对象 "),s("code",[t._v("{}")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_155-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_155-输出什么"}},[t._v("#")]),t._v(" 155. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" randomValue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nrandomValue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("23")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" randomValue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"string"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"It\'s not a string!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Yay it\'s a string!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("It's not a string!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Yay it's a string!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-40"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-40"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("if")]),t._v(" 语句的条件判断 "),s("code",[t._v("!typeof randomValue")]),t._v(" 的值是否等于 "),s("code",[t._v('"string"')]),t._v("。"),s("code",[t._v("!")]),t._v(" 操作符将这个值转化为一个布尔值。如果值是 truthy 的话,返回值会是 "),s("code",[t._v("false")]),t._v(",如果值是 falsy,返回值会是 "),s("code",[t._v("true")]),t._v("。在这里,"),s("code",[t._v("typeof randomValue")]),t._v(" 的返回值是一个 truthy 值 "),s("code",[t._v('"number"')]),t._v(",意味着 "),s("code",[t._v("!typeof randomValue")]),t._v(" 的值是一个布尔值 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v('!typeof randomValue === "string"')]),t._v(" 总是返回 false,因为我们实际上是在执行 "),s("code",[t._v('false === "string"')]),t._v("。因为条件返回的是 "),s("code",[t._v("false")]),t._v(",所以 "),s("code",[t._v("else")]),t._v(" 语句中的代码块会被运行,因此打印 "),s("code",[t._v("Yay it's a string!")]),t._v("。")])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[34],{462:function(t,s,a){"use strict";a.r(s);var n=a(30),e=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"javascript-问题列表"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#javascript-问题列表"}},[t._v("#")]),t._v(" JavaScript 问题列表")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_1-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-输出是什么"}},[t._v("#")]),t._v(" 1. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Lydia")]),t._v(" 和 "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Lydia")]),t._v(" 和 "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")]),t._v(" 和 "),s("code",[t._v("21")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(" 和 "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("在函数内部,我们首先通过 "),s("code",[t._v("var")]),t._v(" 关键字声明了 "),s("code",[t._v("name")]),t._v(" 变量。这意味着变量被提升了(内存空间在创建阶段就被设置好了),直到程序运行到定义变量位置之前默认值都是 "),s("code",[t._v("undefined")]),t._v("。因为当我们打印 "),s("code",[t._v("name")]),t._v(" 变量时还没有执行到定义变量的位置,因此变量的值保持为 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("let")]),t._v(" 和 "),s("code",[t._v("const")]),t._v(" 关键字声明的变量也会提升,但是和 "),s("code",[t._v("var")]),t._v(" 不同,它们不会被"),s("i",[t._v("初始化")]),t._v("。在我们声明(初始化)之前是不能访问它们的。这个行为被称之为暂时性死区。当我们试图在声明之前访问它们时,JavaScript 将会抛出一个 "),s("code",[t._v("ReferenceError")]),t._v(" 错误。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_2-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-输出是什么"}},[t._v("#")]),t._v(" 2. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("0 1 2")]),t._v(" 和 "),s("code",[t._v("0 1 2")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("0 1 2")]),t._v(" 和 "),s("code",[t._v("3 3 3")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("3 3 3")]),t._v(" 和 "),s("code",[t._v("0 1 2")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("由于 JavaScript 的事件循环,"),s("code",[t._v("setTimeout")]),t._v(" 回调会在"),s("em",[t._v("遍历结束后")]),t._v("才执行。因为在第一个遍历中遍历 "),s("code",[t._v("i")]),t._v(" 是通过 "),s("code",[t._v("var")]),t._v(" 关键字声明的,所以这个值是全局作用域下的。在遍历过程中,我们通过一元操作符 "),s("code",[t._v("++")]),t._v(" 来每次递增 "),s("code",[t._v("i")]),t._v(" 的值。当 "),s("code",[t._v("setTimeout")]),t._v(" 回调执行的时候,"),s("code",[t._v("i")]),t._v(" 的值等于 3。")]),t._v(" "),s("p",[t._v("在第二个遍历中,遍历 "),s("code",[t._v("i")]),t._v(" 是通过 "),s("code",[t._v("let")]),t._v(" 关键字声明的:通过 "),s("code",[t._v("let")]),t._v(" 和 "),s("code",[t._v("const")]),t._v(" 关键字声明的变量是拥有块级作用域(指的是任何在 {} 中的内容)。在每次的遍历过程中,"),s("code",[t._v("i")]),t._v(" 都有一个新值,并且每个值都在循环内的作用域中。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_3-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-输出是什么"}},[t._v("#")]),t._v(" 3. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" shape "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("radius")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("diameter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("radius "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("perimeter")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" Math"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("PI")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("radius"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nshape"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("diameter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nshape"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("perimeter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("20")]),t._v(" and "),s("code",[t._v("62.83185307179586")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("20")]),t._v(" and "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("20")]),t._v(" and "),s("code",[t._v("63")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("NaN")]),t._v(" and "),s("code",[t._v("63")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("注意 "),s("code",[t._v("diameter")]),t._v(" 的值是一个常规函数,但是 "),s("code",[t._v("perimeter")]),t._v(" 的值是一个箭头函数。")]),t._v(" "),s("p",[t._v("对于箭头函数,"),s("code",[t._v("this")]),t._v(" 关键字指向的是它当前周围作用域(简单来说是包含箭头函数的常规函数,如果没有常规函数的话就是全局对象),这个行为和常规函数不同。这意味着当我们调用 "),s("code",[t._v("perimeter")]),t._v(" 时,"),s("code",[t._v("this")]),t._v(" 不是指向 "),s("code",[t._v("shape")]),t._v(" 对象,而是它的周围作用域(在例子中是 "),s("code",[t._v("window")]),t._v(")。")]),t._v(" "),s("p",[t._v("在 "),s("code",[t._v("window")]),t._v(" 中没有 "),s("code",[t._v("radius")]),t._v(" 这个属性,因此返回 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_4-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-输出是什么"}},[t._v("#")]),t._v(" 4. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" and "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")]),t._v(" and "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("false")]),t._v(" and "),s("code",[t._v("false")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("一元操作符加号尝试将 bool 转为 number。"),s("code",[t._v("true")]),t._v(" 转换为 number 的话为 "),s("code",[t._v("1")]),t._v(","),s("code",[t._v("false")]),t._v(" 为 "),s("code",[t._v("0")]),t._v("。")]),t._v(" "),s("p",[t._v("字符串 "),s("code",[t._v("'Lydia'")]),t._v(" 是一个真值,真值取反那么就返回 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_5-哪一个是正确的"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_5-哪一个是正确的"}},[t._v("#")]),t._v(" 5. 哪一个是正确的?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" bird "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("size")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"small"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" mouse "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Mickey"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("small")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("mouse.bird.size")]),t._v("是无效的")]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("mouse[bird.size]")]),t._v("是无效的")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('mouse[bird["size"]]')]),t._v("是无效的")]),t._v(" "),s("li",[t._v("D: 以上三个选项都是有效的")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-2"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-2"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("在 JavaScript 中,所有对象的 keys 都是字符串(除非对象是 Symbol)。尽管我们可能不会定义它们为字符串,但它们在底层总会被转换为字符串。")]),t._v(" "),s("p",[t._v("当我们使用括号语法时([]),JavaScript 会解释(或者 unboxes)语句。它首先看到第一个开始括号 "),s("code",[t._v("[")]),t._v(" 并继续前进直到找到结束括号 "),s("code",[t._v("]")]),t._v("。只有这样,它才会计算语句的值。")]),t._v(" "),s("p",[s("code",[t._v("mouse[bird.size]")]),t._v(":首先计算 "),s("code",[t._v("bird.size")]),t._v(",这会得到 "),s("code",[t._v("small")]),t._v("。"),s("code",[t._v('mouse["small"]')]),t._v(" 返回 "),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[t._v("然后使用点语法的话,上面这一切都不会发生。"),s("code",[t._v("mouse")]),t._v(" 没有 "),s("code",[t._v("bird")]),t._v(" 这个 key,这也就意味着 "),s("code",[t._v("mouse.bird")]),t._v(" 是 "),s("code",[t._v("undefined")]),t._v("。然后当我们使用点语法 "),s("code",[t._v("mouse.bird.size")]),t._v(" 时,因为 "),s("code",[t._v("mouse.bird")]),t._v(" 是 "),s("code",[t._v("undefined")]),t._v(",这也就变成了 "),s("code",[t._v("undefined.size")]),t._v("。这个行为是无效的,并且会抛出一个错误类似 "),s("code",[t._v('Cannot read property "size" of undefined')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_6-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_6-输出是什么"}},[t._v("#")]),t._v(" 6. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" c "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("greeting")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hey!"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" d"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nd "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" c"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("greeting "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hello"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("d"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("greeting"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Hello")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-3"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-3"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("在 JavaScript 中,当设置两个对象彼此相等时,它们会通过"),s("em",[t._v("引用")]),t._v("进行交互。")]),t._v(" "),s("p",[t._v("首先,变量 "),s("code",[t._v("c")]),t._v(" 的值是一个对象。接下来,我们给 "),s("code",[t._v("d")]),t._v(" 分配了一个和 "),s("code",[t._v("c")]),t._v(" 对象相同的引用。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/ko5k0fs.png",width:"200"}}),t._v(" "),s("p",[t._v("因此当我们改变其中一个对象时,其实是改变了所有的对象。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_7-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_7-输出是什么"}},[t._v("#")]),t._v(" 7. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" b "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Number")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" c "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("b "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" c"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-2"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-2"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("new Number()")]),t._v(" 是一个内建的函数构造器。虽然它看着像是一个 number,但它实际上并不是一个真实的 number:它有一堆额外的功能并且它是一个对象。")]),t._v(" "),s("p",[t._v("当我们使用 "),s("code",[t._v("==")]),t._v(" 操作符时,它只会检查两者是否拥有相同的"),s("em",[t._v("值")]),t._v("。因为它们的值都是 "),s("code",[t._v("3")]),t._v(",因此返回 "),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[t._v("然后,当我们使用 "),s("code",[t._v("===")]),t._v(" 操作符时,两者的值以及"),s("em",[t._v("类型")]),t._v("都应该是相同的。"),s("code",[t._v("new Number()")]),t._v(" 是一个对象而不是 number,因此返回 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_8-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_8-输出是什么"}},[t._v("#")]),t._v(" 8. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Chameleon")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("static")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("colorChange")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("newColor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("newColor "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" newColor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("newColor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" newColor "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"green"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("newColor "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" newColor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" freddie "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Chameleon")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("newColor")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"purple"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nfreddie"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("colorChange")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"orange"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("orange")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("purple")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("green")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-2"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-2"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("colorChange")]),t._v(" 是一个静态方法。静态方法被设计为只能被创建它们的构造器使用(也就是 "),s("code",[t._v("Chameleon")]),t._v("),并且不能传递给实例。因为 "),s("code",[t._v("freddie")]),t._v(" 是一个实例,静态方法不能被实例使用,因此抛出了 "),s("code",[t._v("TypeError")]),t._v(" 错误。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_9-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_9-输出是什么"}},[t._v("#")]),t._v(" 9. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" greeting"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ngreetign "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Typo!")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("greetign"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("{}")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("ReferenceError: greetign is not defined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-4"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-4"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("代码打印出了一个对象,这是因为我们在全局对象上创建了一个空对象!当我们将 "),s("code",[t._v("greeting")]),t._v(" 写错成 "),s("code",[t._v("greetign")]),t._v(" 时,JS 解释器实际在上浏览器中将它视为 "),s("code",[t._v("global.greetign = {}")]),t._v("(或者 "),s("code",[t._v("window.greetign = {}")]),t._v(")。")]),t._v(" "),s("p",[t._v('为了避免这个为题,我们可以使用 `"use strict"。这能确保当你声明变量时必须赋值。')]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_10-当我们这么做时-会发生什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_10-当我们这么做时-会发生什么"}},[t._v("#")]),t._v(" 10. 当我们这么做时,会发生什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("bark")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Woof!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nbark"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("animal "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"dog"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 正常运行!")]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("SyntaxError")]),t._v(". 你不能通过这种方式给函数增加属性。")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-5"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-5"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("这在 JavaScript 中是可以的,因为函数是对象!(除了基本类型之外其他都是对象)")]),t._v(" "),s("p",[t._v("函数是一个特殊的对象。你写的这个代码其实不是一个实际的函数。函数是一个拥有属性的对象,并且属性也可被调用。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_11-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_11-输出是什么"}},[t._v("#")]),t._v(" 11. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("firstName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" lastName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("firstName "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" firstName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastName "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" lastName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" member "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nPerson"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("getFullName")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("firstName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFullName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Lydia Hallie")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-6"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-6"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("你不能像常规对象那样,给构造函数添加属性。如果你想一次性给所有实例添加特性,你应该使用原型。因此本例中,使用如下方式:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("getFullName")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("firstName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("这才会使 "),s("code",[t._v("member.getFullName()")]),t._v(" 起作用。为什么这么做有益的?假设我们将这个方法添加到构造函数本身里。也许不是每个 "),s("code",[t._v("Person")]),t._v(" 实例都需要这个方法。这将浪费大量内存空间,因为它们仍然具有该属性,这将占用每个实例的内存空间。相反,如果我们只将它添加到原型中,那么它只存在于内存中的一个位置,但是所有实例都可以访问它!")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_12-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_12-输出是什么"}},[t._v("#")]),t._v(" 12. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("firstName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" lastName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("firstName "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" firstName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastName "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" lastName"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" lydia "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" sarah "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sarah"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Smith"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("lydia"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("sarah"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),t._v(" and "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),t._v(" and "),s("code",[t._v('Person {firstName: "Sarah", lastName: "Smith"}')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),t._v(" and "),s("code",[t._v("{}")])]),t._v(" "),s("li",[t._v("D:"),s("code",[t._v('Person {firstName: "Lydia", lastName: "Hallie"}')]),t._v(" and "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-7"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-7"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("对于 "),s("code",[t._v("sarah")]),t._v(",我们没有使用 "),s("code",[t._v("new")]),t._v(" 关键字。当使用 "),s("code",[t._v("new")]),t._v(" 时,"),s("code",[t._v("this")]),t._v(" 引用我们创建的空对象。当未使用 "),s("code",[t._v("new")]),t._v(" 时,"),s("code",[t._v("this")]),t._v(" 引用的是"),s("strong",[t._v("全局对象")]),t._v("(global object)。")]),t._v(" "),s("p",[t._v("我们说 "),s("code",[t._v("this.firstName")]),t._v(" 等于 "),s("code",[t._v('"Sarah"')]),t._v(",并且 "),s("code",[t._v("this.lastName")]),t._v(" 等于 "),s("code",[t._v('"Smith"')]),t._v("。实际上我们做的是,定义了 "),s("code",[t._v("global.firstName = 'Sarah'")]),t._v(" 和 "),s("code",[t._v("global.lastName = 'Smith'")]),t._v("。而 "),s("code",[t._v("sarah")]),t._v(" 本身是 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_13-事件传播的三个阶段是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_13-事件传播的三个阶段是什么"}},[t._v("#")]),t._v(" 13. 事件传播的三个阶段是什么?")]),t._v(" "),s("ul",[s("li",[t._v("A: Target > Capturing > Bubbling")]),t._v(" "),s("li",[t._v("B: Bubbling > Target > Capturing")]),t._v(" "),s("li",[t._v("C: Target > Bubbling > Capturing")]),t._v(" "),s("li",[t._v("D: Capturing > Target > Bubbling")])]),t._v(" "),s("h4",{attrs:{id:"答案-d-3"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-3"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("在"),s("strong",[t._v("捕获")]),t._v("(capturing)阶段中,事件从祖先元素向下传播到目标元素。当事件达到"),s("strong",[t._v("目标")]),t._v("(target)元素后,"),s("strong",[t._v("冒泡")]),t._v("(bubbling)才开始。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/N18oRgd.png",width:"200"}}),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_14-所有对象都有原型。"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_14-所有对象都有原型。"}},[t._v("#")]),t._v(" 14. 所有对象都有原型。")]),t._v(" "),s("ul",[s("li",[t._v("A: 对")]),t._v(" "),s("li",[t._v("B: 错")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-2"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-2"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("除了"),s("strong",[t._v("基本对象")]),t._v("(base object),所有对象都有原型。基本对象可以访问一些方法和属性,比如 "),s("code",[t._v(".toString")]),t._v("。这就是为什么你可以使用内置的 JavaScript 方法!所有这些方法在原型上都是可用的。虽然 JavaScript 不能直接在对象上找到这些方法,但 JavaScript 会沿着原型链找到它们,以便于你使用。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_15-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_15-输出是什么"}},[t._v("#")]),t._v(" 15. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" b")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"2"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"12"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("3")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-3"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-3"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("JavaScript 是一种"),s("strong",[t._v("动态类型语言")]),t._v(":我们不指定某些变量的类型。值可以在你不知道的情况下自动转换成另一种类型,这种类型称为"),s("strong",[t._v("隐式类型转换")]),t._v("(implicit type coercion)。"),s("strong",[t._v("Coercion")]),t._v(" 是指将一种类型转换为另一种类型。")]),t._v(" "),s("p",[t._v("在本例中,JavaScript 将数字 "),s("code",[t._v("1")]),t._v(" 转换为字符串,以便函数有意义并返回一个值。在数字类型("),s("code",[t._v("1")]),t._v(")和字符串类型("),s("code",[t._v("'2'")]),t._v(")相加时,该数字被视为字符串。我们可以连接字符串,比如 "),s("code",[t._v('"Hello" + "World"')]),t._v(",这里发生的是 "),s("code",[t._v('"1" + "2"')]),t._v(",它返回 "),s("code",[t._v('"12"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_16-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_16-输出是什么"}},[t._v("#")]),t._v(" 16. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" number "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("number"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("0")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("0")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-4"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-4"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("一元"),s("strong",[t._v("后自增")]),t._v("运算符 "),s("code",[t._v("++")]),t._v(":")]),t._v(" "),s("ol",[s("li",[t._v("返回值(返回 "),s("code",[t._v("0")]),t._v(")")]),t._v(" "),s("li",[t._v("值自增(number 现在是 "),s("code",[t._v("1")]),t._v(")")])]),t._v(" "),s("p",[t._v("一元"),s("strong",[t._v("前自增")]),t._v("运算符 "),s("code",[t._v("++")]),t._v(":")]),t._v(" "),s("ol",[s("li",[t._v("值自增(number 现在是 "),s("code",[t._v("2")]),t._v(")")]),t._v(" "),s("li",[t._v("返回值(返回 "),s("code",[t._v("2")]),t._v(")")])]),t._v(" "),s("p",[t._v("结果是 "),s("code",[t._v("0 2 2")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_17-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_17-输出是什么"}},[t._v("#")]),t._v(" 17. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getPersonInfo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" three")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("three"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\ngetPersonInfo"),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" is ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" years old")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Lydia"')]),t._v(" "),s("code",[t._v("21")]),t._v(" "),s("code",[t._v('["", " is ", " years old"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["", " is ", " years old"]')]),t._v(" "),s("code",[t._v('"Lydia"')]),t._v(" "),s("code",[t._v("21")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"Lydia"')]),t._v(" "),s("code",[t._v('["", " is ", " years old"]')]),t._v(" "),s("code",[t._v("21")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-3"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-3"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("如果使用标记模板字面量,第一个参数的值总是包含字符串的数组。其余的参数获取的是传递的表达式的值!")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_18-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_18-输出是什么"}},[t._v("#")]),t._v(" 18. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("checkAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("data")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"You are an adult!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"You are still an adult."')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Hmm.. You don't have an age I guess")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("checkAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("You are an adult!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("You are still an adult.")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Hmm.. You don't have an age I guess")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-5"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-5"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("在测试相等性时,基本类型通过它们的值(value)进行比较,而对象通过它们的引用(reference)进行比较。JavaScript 检查对象是否具有对内存中相同位置的引用。")]),t._v(" "),s("p",[t._v("题目中我们正在比较的两个对象不是同一个引用:作为参数传递的对象引用的内存位置,与用于判断相等的对象所引用的内存位置并不同。")]),t._v(" "),s("p",[t._v("这也是 "),s("code",[t._v("{ age: 18 } === { age: 18 }")]),t._v(" 和 "),s("code",[t._v("{ age: 18 } == { age: 18 }")]),t._v(" 都返回 "),s("code",[t._v("false")]),t._v(" 的原因。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_19-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_19-输出是什么"}},[t._v("#")]),t._v(" 19. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("args")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" args"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"number"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"array"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"object"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"NaN"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-6"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-6"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("扩展运算符("),s("code",[t._v("...args")]),t._v(")会返回实参组成的数组。而数组是对象,因此 "),s("code",[t._v("typeof args")]),t._v(" 返回 "),s("code",[t._v('"object"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_20-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_20-输出是什么"}},[t._v("#")]),t._v(" 20. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"use strict"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("21")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-7"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-7"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用 "),s("code",[t._v('"use strict"')]),t._v(",你可以确保不会意外地声明全局变量。我们从来没有声明变量 "),s("code",[t._v("age")]),t._v(",因为我们使用 "),s("code",[t._v('"use strict"')]),t._v(",它将抛出一个引用错误。如果我们不使用 "),s("code",[t._v('"use strict"')]),t._v(",它就会工作,因为属性 "),s("code",[t._v("age")]),t._v(" 会被添加到全局对象中了。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_21-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_21-输出是什么"}},[t._v("#")]),t._v(" 21. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("eval")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"10*10+5"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("105")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"105"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"10*10+5"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-8"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-8"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("代码以字符串形式传递进来,"),s("code",[t._v("eval")]),t._v(" 对其求值。如果它是一个表达式,就像本例中那样,它对表达式求值。表达式是 "),s("code",[t._v("10 * 10 + 5")]),t._v("。这将返回数字 "),s("code",[t._v("105")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_22-cool-secret-可访问多长时间"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_22-cool-secret-可访问多长时间"}},[t._v("#")]),t._v(" 22. cool_secret 可访问多长时间?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("sessionStorage"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setItem")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"cool_secret"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("123")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 永远,数据不会丢失。")]),t._v(" "),s("li",[t._v("B: 当用户关掉标签页时。")]),t._v(" "),s("li",[t._v("C: 当用户关掉整个浏览器,而不只是关掉标签页。")]),t._v(" "),s("li",[t._v("D: 当用户关闭电脑时。")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-4"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-4"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("关闭 "),s("strong",[t._v("tab 标签页")]),t._v(" 后,"),s("code",[t._v("sessionStorage")]),t._v(" 存储的数据才会删除。")]),t._v(" "),s("p",[t._v("如果使用 "),s("code",[t._v("localStorage")]),t._v(",那么数据将永远在那里,除非调用了 "),s("code",[t._v("localStorage.clear()")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_23-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_23-输出是什么"}},[t._v("#")]),t._v(" 23. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("8")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("8")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("10")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-5"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-5"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("使用 "),s("code",[t._v("var")]),t._v(" 关键字,你可以用相同的名称声明多个变量。然后变量将保存最新的值。")]),t._v(" "),s("p",[t._v("你不能使用 "),s("code",[t._v("let")]),t._v(" 或 "),s("code",[t._v("const")]),t._v(" 来实现这一点,因为它们是块作用域的。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_24-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_24-输出是什么"}},[t._v("#")]),t._v(" 24. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" obj "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" set "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Set")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nobj"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("hasOwnProperty")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nobj"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("hasOwnProperty")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nset"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("has")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nset"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("has")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-8"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-8"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("所有对象的键(不包括 Symbol)在底层都是字符串,即使你自己没有将其作为字符串输入。这就是为什么 "),s("code",[t._v("obj.hasOwnProperty('1')")]),t._v(" 也返回 "),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[t._v("对于集合,它不是这样工作的。在我们的集合中没有 "),s("code",[t._v("'1'")]),t._v(":"),s("code",[t._v("set.has('1')")]),t._v(" 返回 "),s("code",[t._v("false")]),t._v("。它有数字类型为 "),s("code",[t._v("1")]),t._v(","),s("code",[t._v("set.has(1)")]),t._v(" 返回 "),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_25-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_25-输出是什么"}},[t._v("#")]),t._v(" 25. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" obj "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("a")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"one"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("b")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"two"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("a")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"three"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("obj"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ a: "one", b: "two" }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ b: "two", a: "three" }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ a: "three", b: "two" }')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-9"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-9"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("如果你有两个名称相同的键,则键会被替换掉。它仍然位于第一个键出现的位置,但是值是最后出现那个键的值。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_26-javascript-全局执行上下文为你做了两件事-全局对象和-this-关键字。"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_26-javascript-全局执行上下文为你做了两件事-全局对象和-this-关键字。"}},[t._v("#")]),t._v(" 26. JavaScript 全局执行上下文为你做了两件事:全局对象和 this 关键字。")]),t._v(" "),s("ul",[s("li",[t._v("A: 对")]),t._v(" "),s("li",[t._v("B: 错")]),t._v(" "),s("li",[t._v("C: 看情况")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-9"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-9"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("基本执行上下文是全局执行上下文:它是代码中随处可访问的内容。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_27-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_27-输出是什么"}},[t._v("#")]),t._v(" 27. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("continue")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("4")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("4")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-10"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-10"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("如果某个条件返回 "),s("code",[t._v("true")]),t._v(",则 "),s("code",[t._v("continue")]),t._v(" 语句跳过本次迭代。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_28-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_28-输出是什么"}},[t._v("#")]),t._v(" 28. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("String")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("giveLydiaPizza")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Just give Lydia pizza already!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nname"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("giveLydiaPizza")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Just give Lydia pizza already!"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("TypeError: not a function")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-10"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-10"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("String")]),t._v(" 是内置的构造函数,我们可以向它添加属性。我只是在它的原型中添加了一个方法。基本类型字符串被自动转换为字符串对象,由字符串原型函数生成。因此,所有 string(string 对象) 都可以访问该方法!")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_29-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_29-输出是什么"}},[t._v("#")]),t._v(" 29. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" b "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("key")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" c "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("key")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\na"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("123")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\na"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("c"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("456")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("123")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("456")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-6"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-6"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("对象的键被自动转换为字符串。我们试图将一个对象 "),s("code",[t._v("b")]),t._v(" 设置为对象 "),s("code",[t._v("a")]),t._v(" 的键,且相应的值为 "),s("code",[t._v("123")]),t._v("。")]),t._v(" "),s("p",[t._v("然而,当字符串化一个对象时,它会变成 "),s("code",[t._v('"[object Object]"')]),t._v("。因此这里说的是,"),s("code",[t._v('a["[object Object]"] = 123')]),t._v("。然后,我们再一次做了同样的事情,"),s("code",[t._v("c")]),t._v(" 是另外一个对象,这里也有隐式字符串化,于是,"),s("code",[t._v('a["[object Object]"] = 456')]),t._v("。")]),t._v(" "),s("p",[t._v("然后,我们打印 "),s("code",[t._v("a[b]")]),t._v(",也就是 "),s("code",[t._v('a["[object Object]"]')]),t._v("。之前刚设置为 "),s("code",[t._v("456")]),t._v(",因此返回的是 "),s("code",[t._v("456")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_30-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_30-输出是什么"}},[t._v("#")]),t._v(" 30. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("foo")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"First"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("bar")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Second"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("baz")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Third"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("bar")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("foo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("baz")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("First")]),t._v(" "),s("code",[t._v("Second")]),t._v(" "),s("code",[t._v("Third")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("First")]),t._v(" "),s("code",[t._v("Third")]),t._v(" "),s("code",[t._v("Second")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Second")]),t._v(" "),s("code",[t._v("First")]),t._v(" "),s("code",[t._v("Third")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Second")]),t._v(" "),s("code",[t._v("Third")]),t._v(" "),s("code",[t._v("First")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-7"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-7"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("我们有一个 "),s("code",[t._v("setTimeout")]),t._v(" 函数,并首先调用它。然而,它是最后打印日志的。")]),t._v(" "),s("p",[t._v("这是因为在浏览器中,我们不仅有运行时引擎,还有一个叫做 "),s("code",[t._v("WebAPI")]),t._v(" 的东西。"),s("code",[t._v("WebAPI")]),t._v(" 提供了 "),s("code",[t._v("setTimeout")]),t._v(" 函数,也包含其他的,例如 DOM。")]),t._v(" "),s("p",[t._v("将 "),s("em",[t._v("callback")]),t._v(" 推送到 WebAPI 后,"),s("code",[t._v("setTimeout")]),t._v(" 函数本身 (但不是回调!) 将从栈中弹出。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/X5wsHOg.png",width:"200"}}),t._v(" "),s("p",[t._v("现在,"),s("code",[t._v("foo")]),t._v(" 被调用,打印 "),s("code",[t._v('"First"')]),t._v("。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/Pvc0dGq.png",width:"200"}}),t._v(" "),s("p",[s("code",[t._v("foo")]),t._v(" 从栈中弹出,"),s("code",[t._v("baz")]),t._v(" 被调用。打印 "),s("code",[t._v('"Third"')]),t._v("。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/WhA2bCP.png",width:"200"}}),t._v(" "),s("p",[t._v("WebAPI 不能随时向栈内添加内容。相反,它将回调函数推到名为 "),s("em",[t._v("queue")]),t._v(" 的地方。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/NSnDZmU.png",width:"200"}}),t._v(" "),s("p",[t._v("这就是事件循环开始工作的地方。一个"),s("strong",[t._v("事件循环")]),t._v("查看栈和任务队列。如果栈是空的,它接受队列上的第一个元素并将其推入栈。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/uyiScAI.png",width:"200"}}),t._v(" "),s("p",[s("code",[t._v("bar")]),t._v(" 被调用,打印 "),s("code",[t._v('"Second"')]),t._v(",然后它被栈弹出。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_31-当点击按钮时-event-target-是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_31-当点击按钮时-event-target-是什么"}},[t._v("#")]),t._v(" 31. 当点击按钮时,event.target 是什么?")]),t._v(" "),s("div",{staticClass:"language-html extra-class"},[s("pre",{pre:!0,attrs:{class:"language-html"}},[s("code",[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("<")]),t._v("div")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token special-attr"}},[s("span",{pre:!0,attrs:{class:"token attr-name"}},[t._v("onclick")]),s("span",{pre:!0,attrs:{class:"token attr-value"}},[s("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')]),s("span",{pre:!0,attrs:{class:"token value javascript language-javascript"}},[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'first div'")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')])])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(">")])]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("<")]),t._v("div")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token special-attr"}},[s("span",{pre:!0,attrs:{class:"token attr-name"}},[t._v("onclick")]),s("span",{pre:!0,attrs:{class:"token attr-value"}},[s("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')]),s("span",{pre:!0,attrs:{class:"token value javascript language-javascript"}},[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'second div'")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')])])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(">")])]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("<")]),t._v("button")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token special-attr"}},[s("span",{pre:!0,attrs:{class:"token attr-name"}},[t._v("onclick")]),s("span",{pre:!0,attrs:{class:"token attr-value"}},[s("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')]),s("span",{pre:!0,attrs:{class:"token value javascript language-javascript"}},[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'button'")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')])])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(">")])]),t._v("Click!"),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("")])]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("")])]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: Outer "),s("code",[t._v("div")])]),t._v(" "),s("li",[t._v("B: Inner "),s("code",[t._v("div")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("button")])]),t._v(" "),s("li",[t._v("D: 一个包含所有嵌套元素的数组。")])]),t._v(" "),s("h4",{attrs:{id:"答案-c-11"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-11"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("导致事件的最深嵌套的元素是事件的 target。你可以通过 "),s("code",[t._v("event.stopPropagation")]),t._v(" 来停止冒泡。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_32-当您单击该段落时-日志输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_32-当您单击该段落时-日志输出是什么"}},[t._v("#")]),t._v(" 32. 当您单击该段落时,日志输出是什么?")]),t._v(" "),s("div",{staticClass:"language-html extra-class"},[s("pre",{pre:!0,attrs:{class:"language-html"}},[s("code",[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("<")]),t._v("div")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token special-attr"}},[s("span",{pre:!0,attrs:{class:"token attr-name"}},[t._v("onclick")]),s("span",{pre:!0,attrs:{class:"token attr-value"}},[s("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')]),s("span",{pre:!0,attrs:{class:"token value javascript language-javascript"}},[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'div'")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')])])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(">")])]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("<")]),t._v("p")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token special-attr"}},[s("span",{pre:!0,attrs:{class:"token attr-name"}},[t._v("onclick")]),s("span",{pre:!0,attrs:{class:"token attr-value"}},[s("span",{pre:!0,attrs:{class:"token punctuation attr-equals"}},[t._v("=")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')]),s("span",{pre:!0,attrs:{class:"token value javascript language-javascript"}},[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("'p'")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v('"')])])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(">")])]),t._v("Click here!"),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("")])]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token tag"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("")])]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("p")]),t._v(" "),s("code",[t._v("div")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("div")]),t._v(" "),s("code",[t._v("p")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("p")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("div")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-11"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-11"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("如果我们点击 "),s("code",[t._v("p")]),t._v(",我们会看到两个日志:"),s("code",[t._v("p")]),t._v(" 和 "),s("code",[t._v("div")]),t._v("。在事件传播期间,有三个阶段:捕获、目标和冒泡。默认情况下,事件处理程序在冒泡阶段执行(除非将 "),s("code",[t._v("useCapture")]),t._v(" 设置为 "),s("code",[t._v("true")]),t._v(")。它从嵌套最深的元素向外传播。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_33-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_33-输出是什么"}},[t._v("#")]),t._v(" 33. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" is ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("call")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("bind")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("undefined is 21")]),t._v(" "),s("code",[t._v("Lydia is 21")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("function")]),t._v(" "),s("code",[t._v("function")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Lydia is 21")]),t._v(" "),s("code",[t._v("Lydia is 21")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Lydia is 21")]),t._v(" "),s("code",[t._v("function")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-4"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-4"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("使用这两种方法,我们都可以传递我们希望 "),s("code",[t._v("this")]),t._v(" 关键字引用的对象。但是,"),s("code",[t._v(".call")]),t._v(" 是"),s("strong",[t._v("立即执行")]),t._v("的。")]),t._v(" "),s("p",[s("code",[t._v(".bind")]),t._v(" 返回函数的"),s("strong",[t._v("副本")]),t._v(",但带有绑定上下文!它不是立即执行的。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_34-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_34-输出是什么"}},[t._v("#")]),t._v(" 34. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"object"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"number"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"function"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"undefined"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-8"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-8"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("sayHi")]),t._v(" 方法返回的是立即执行函数 (IIFE) 的返回值。此立即执行函数的返回值是 "),s("code",[t._v("0")]),t._v(",类型是 "),s("code",[t._v("number")])]),t._v(" "),s("p",[t._v("参考:只有 7 种内置类型:"),s("code",[t._v("null")]),t._v(","),s("code",[t._v("undefined")]),t._v(","),s("code",[t._v("boolean")]),t._v(","),s("code",[t._v("number")]),t._v(","),s("code",[t._v("string")]),t._v(","),s("code",[t._v("object")]),t._v(", "),s("code",[t._v("symbol")]),t._v(" 和 "),s("code",[t._v("bigint")]),t._v("。"),s("code",[t._v("function")]),t._v(" 不是一种类型,函数是对象,它的类型是"),s("code",[t._v("object")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_35-下面哪些值是-falsy"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_35-下面哪些值是-falsy"}},[t._v("#")]),t._v(" 35. 下面哪些值是 falsy?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Number")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('" "')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Boolean")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("undefined")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("0")]),t._v(", "),s("code",[t._v("''")]),t._v(", "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("0")]),t._v(", "),s("code",[t._v("new Number(0)")]),t._v(", "),s("code",[t._v("''")]),t._v(", "),s("code",[t._v("new Boolean(false)")]),t._v(", "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("0")]),t._v(", "),s("code",[t._v("''")]),t._v(", "),s("code",[t._v("new Boolean(false)")]),t._v(", "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: All of them are falsy")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-12"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-12"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("只有 8 种 "),s("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy",target:"_blank",rel:"noopener noreferrer"}},[t._v("falsy"),s("OutboundLink")],1),t._v(" 值:")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("undefined")])]),t._v(" "),s("li",[s("code",[t._v("null")])]),t._v(" "),s("li",[s("code",[t._v("NaN")])]),t._v(" "),s("li",[s("code",[t._v("false")])]),t._v(" "),s("li",[s("code",[t._v("''")]),t._v(" (empty string)")]),t._v(" "),s("li",[s("code",[t._v("0")])]),t._v(" "),s("li",[s("code",[t._v("-0")])]),t._v(" "),s("li",[s("code",[t._v("0n")]),t._v(" (BigInt(0))")])]),t._v(" "),s("p",[s("code",[t._v("Function")]),t._v(" 构造函数,比如 "),s("code",[t._v("new Number")]),t._v(" 和 "),s("code",[t._v("new Boolean")]),t._v(",是 "),s("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy",target:"_blank",rel:"noopener noreferrer"}},[t._v("truthy"),s("OutboundLink")],1),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_36-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_36-输出是什么"}},[t._v("#")]),t._v(" 36. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"number"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"string"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"object"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"undefined"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-9"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-9"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("typeof 1")]),t._v(" 返回 "),s("code",[t._v('"number"')]),t._v("。\n"),s("code",[t._v('typeof "number"')]),t._v(" 返回 "),s("code",[t._v('"string"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_37-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_37-输出是什么"}},[t._v("#")]),t._v(" 37. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" numbers "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nnumbers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("numbers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[1, 2, 3, 7 x null, 11]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[1, 2, 3, 11]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[1, 2, 3, 7 x empty, 11]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-12"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-12"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v('当你为数组设置超过数组长度的值的时候,JavaScript 会创建名为 "empty slots" 的东西。它们的值实际上是 '),s("code",[t._v("undefined")]),t._v("。你会看到以下场景:")]),t._v(" "),s("p",[s("code",[t._v("[1, 2, 3, 7 x empty, 11]")])]),t._v(" "),s("p",[t._v("这取决于你的运行环境(每个浏览器,以及 node 环境,都有可能不同)")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_38-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_38-输出是什么"}},[t._v("#")]),t._v(" 38. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("try")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("throw")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("catch")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-13"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-13"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("catch")]),t._v(" 代码块接收参数 "),s("code",[t._v("x")]),t._v("。当我们传递参数时,这与之前定义的变量 "),s("code",[t._v("x")]),t._v(" 不同。这个 "),s("code",[t._v("x")]),t._v(" 是属于 "),s("code",[t._v("catch")]),t._v(" 块级作用域的。")]),t._v(" "),s("p",[t._v("然后,我们将块级作用域中的变量赋值为 "),s("code",[t._v("1")]),t._v(",同时也设置了变量 "),s("code",[t._v("y")]),t._v(" 的值。现在,我们打印块级作用域中的变量 "),s("code",[t._v("x")]),t._v(",值为 "),s("code",[t._v("1")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("catch")]),t._v(" 块之外的变量 "),s("code",[t._v("x")]),t._v(" 的值仍为 "),s("code",[t._v("undefined")]),t._v(","),s("code",[t._v("y")]),t._v(" 的值为 "),s("code",[t._v("2")]),t._v("。当我们在 "),s("code",[t._v("catch")]),t._v(" 块之外执行 "),s("code",[t._v("console.log(x)")]),t._v(" 时,返回 "),s("code",[t._v("undefined")]),t._v(","),s("code",[t._v("y")]),t._v(" 返回 "),s("code",[t._v("2")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_39-javascript-中的一切都是"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_39-javascript-中的一切都是"}},[t._v("#")]),t._v(" 39. JavaScript 中的一切都是?")]),t._v(" "),s("ul",[s("li",[t._v("A: 基本类型与对象")]),t._v(" "),s("li",[t._v("B: 函数与对象")]),t._v(" "),s("li",[t._v("C: 只有对象")]),t._v(" "),s("li",[t._v("D: 数字与对象\n")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-14"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-14"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("JavaScript 只有基本类型和对象。")]),t._v(" "),s("p",[t._v("基本类型包括 "),s("code",[t._v("boolean")]),t._v(", "),s("code",[t._v("null")]),t._v(", "),s("code",[t._v("undefined")]),t._v(", "),s("code",[t._v("bigint")]),t._v(", "),s("code",[t._v("number")]),t._v(", "),s("code",[t._v("string")]),t._v(", "),s("code",[t._v("symbol")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_40-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_40-输出是什么"}},[t._v("#")]),t._v(" 40. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reduce")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("acc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" cur")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" acc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("concat")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("cur"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[0, 1, 2, 3, 1, 2]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[6, 1, 2]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[1, 2, 0, 1, 2, 3]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("[1, 2, 6]")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-13"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-13"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("[1, 2]")]),t._v("是初始值。初始值将会作为首次调用时第一个参数 "),s("code",[t._v("acc")]),t._v(" 的值。在第一次执行时,"),s("code",[t._v("acc")]),t._v(" 的值是 "),s("code",[t._v("[1, 2]")]),t._v(","),s("code",[t._v("cur")]),t._v(" 的值是 "),s("code",[t._v("[0, 1]")]),t._v("。合并它们,结果为 "),s("code",[t._v("[1, 2, 0, 1]")]),t._v("。\n第二次执行,"),s("code",[t._v("acc")]),t._v(" 的值是 "),s("code",[t._v("[1, 2, 0, 1]")]),t._v(","),s("code",[t._v("cur")]),t._v(" 的值是 "),s("code",[t._v("[2, 3]")]),t._v("。合并它们,最终结果为 "),s("code",[t._v("[1, 2, 0, 1, 2, 3]")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_41-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_41-输出是什么"}},[t._v("#")]),t._v(" 41. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-10"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-10"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("null")]),t._v(" 是 "),s("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy",target:"_blank",rel:"noopener noreferrer"}},[t._v("falsy"),s("OutboundLink")],1),t._v("。"),s("code",[t._v("!null")]),t._v(" 的值是 "),s("code",[t._v("true")]),t._v("。"),s("code",[t._v("!true")]),t._v(" 的值是 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v('""')]),t._v(" 是 "),s("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Falsy",target:"_blank",rel:"noopener noreferrer"}},[t._v("falsy"),s("OutboundLink")],1),t._v("。"),s("code",[t._v('!""')]),t._v(" 的值是 "),s("code",[t._v("true")]),t._v("。"),s("code",[t._v("!true")]),t._v(" 的值是 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("1")]),t._v(" 是 "),s("a",{attrs:{href:"https://developer.mozilla.org/zh-CN/docs/Glossary/Truthy",target:"_blank",rel:"noopener noreferrer"}},[t._v("truthy"),s("OutboundLink")],1),t._v("。"),s("code",[t._v("!1")]),t._v(" 的值是 "),s("code",[t._v("false")]),t._v("。"),s("code",[t._v("!false")]),t._v(" 的值是 "),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_42-setinterval-方法的返回值是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_42-setinterval-方法的返回值是什么"}},[t._v("#")]),t._v(" 42. "),s("code",[t._v("setInterval")]),t._v(" 方法的返回值是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setInterval")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hi"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 一个唯一的 id")]),t._v(" "),s("li",[t._v("B: 该方法指定的毫秒数")]),t._v(" "),s("li",[t._v("C: 传递的函数")]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-15"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-15"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("setInterval")]),t._v(" 返回一个唯一的 id。此 id 可被用于 "),s("code",[t._v("clearInterval")]),t._v(" 函数来取消定时。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_43-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_43-输出是什么"}},[t._v("#")]),t._v(" 43. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('["L", "y", "d", "i", "a"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["Lydia"]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('[[], "Lydia"]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('[["L", "y", "d", "i", "a"]]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-16"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-16"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("string 类型是可迭代的。扩展运算符将迭代的每个字符映射成一个元素。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_44-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_44-输出是什么"}},[t._v("#")]),t._v(" 44. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generator")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("i")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" gen "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generator")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gen"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("gen"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[0, 10], [10, 20]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("20, 20")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("10, 20")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("0, 10 and 10, 20")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-14"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-14"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("一般的函数在执行之后是不能中途停下的。但是,生成器函数却可以中途“停下”,之后可以再从停下的地方继续。当生成器遇到"),s("code",[t._v("yield")]),t._v("关键字的时候,会生成"),s("code",[t._v("yield")]),t._v("后面的值。注意,生成器在这种情况下不 "),s("em",[t._v("返回")]),t._v(" ("),s("em",[t._v("return")]),t._v(" ) 值,而是 "),s("em",[t._v("生成")]),t._v(" ("),s("em",[t._v("yield")]),t._v(") 值。")]),t._v(" "),s("p",[t._v("首先,我们用"),s("code",[t._v("10")]),t._v("作为参数"),s("code",[t._v("i")]),t._v("来初始化生成器函数。然后使用"),s("code",[t._v("next()")]),t._v("方法一步步执行生成器。第一次执行生成器的时候,"),s("code",[t._v("i")]),t._v("的值为"),s("code",[t._v("10")]),t._v(",遇到第一个"),s("code",[t._v("yield")]),t._v("关键字,它要生成"),s("code",[t._v("i")]),t._v("的值。此时,生成器“暂停”,生成了"),s("code",[t._v("10")]),t._v("。")]),t._v(" "),s("p",[t._v("然后,我们再执行"),s("code",[t._v("next()")]),t._v("方法。生成器会从刚才暂停的地方继续,这个时候"),s("code",[t._v("i")]),t._v("还是"),s("code",[t._v("10")]),t._v("。于是我们走到了第二个"),s("code",[t._v("yield")]),t._v("关键字处,这时候需要生成的值是"),s("code",[t._v("i*2")]),t._v(","),s("code",[t._v("i")]),t._v("为"),s("code",[t._v("10")]),t._v(",那么此时生成的值便是"),s("code",[t._v("20")]),t._v("。所以这道题的最终结果是"),s("code",[t._v("10,20")]),t._v("。")]),t._v(" "),s("h6",{attrs:{id:"_45-返回值是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_45-返回值是什么"}},[t._v("#")]),t._v(" 45. 返回值是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" firstPromise "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Promise")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" rej")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("500")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"one"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" secondPromise "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Promise")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" rej")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"two"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("race")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("firstPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" secondPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"one"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"two"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"two" "one"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"one" "two"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-11"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-11"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("当我们向"),s("code",[t._v("Promise.race")]),t._v("方法中传入多个"),s("code",[t._v("Promise")]),t._v("时,会进行 "),s("em",[t._v("优先")]),t._v(" 解析。在这个例子中,我们用"),s("code",[t._v("setTimeout")]),t._v("给"),s("code",[t._v("firstPromise")]),t._v("和"),s("code",[t._v("secondPromise")]),t._v("分别设定了 500ms 和 100ms 的定时器。这意味着"),s("code",[t._v("secondPromise")]),t._v("会首先解析出字符串"),s("code",[t._v("two")]),t._v("。那么此时"),s("code",[t._v("res")]),t._v("参数即为"),s("code",[t._v("two")]),t._v(",是为输出结果。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_46-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_46-输出是什么"}},[t._v("#")]),t._v(" 46. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" members "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nperson "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("members"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("null")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[null]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[{}]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('[{ name: "Lydia" }]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-5"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-5"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("首先我们声明了一个拥有"),s("code",[t._v("name")]),t._v("属性的对象 "),s("code",[t._v("person")]),t._v("。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/TML1MbS.png",width:"200"}}),t._v(" "),s("p",[t._v("然后我们又声明了一个变量"),s("code",[t._v("members")]),t._v(". 将首个元素赋值为变量"),s("code",[t._v("person")]),t._v("。当设置两个对象彼此相等时,它们会通过 "),s("em",[t._v("引用")]),t._v(" 进行交互。但是当你将引用从一个变量分配至另一个变量时,其实只是执行了一个 "),s("em",[t._v("复制")]),t._v(" 操作。(注意一点,他们的引用 "),s("em",[t._v("并不相同")]),t._v("!)")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/FSG5K3F.png",width:"300"}}),t._v(" "),s("p",[t._v("接下来我们让"),s("code",[t._v("person")]),t._v("等于"),s("code",[t._v("null")]),t._v("。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/sYjcsMT.png",width:"300"}}),t._v(" "),s("p",[t._v("我们没有修改数组第一个元素的值,而只是修改了变量"),s("code",[t._v("person")]),t._v("的值,因为元素(复制而来)的引用与"),s("code",[t._v("person")]),t._v("不同。"),s("code",[t._v("members")]),t._v("的第一个元素仍然保持着对原始对象的引用。当我们输出"),s("code",[t._v("members")]),t._v("数组时,第一个元素会将引用的对象打印出来。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_47-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_47-输出是什么"}},[t._v("#")]),t._v(" 47. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" item "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ name: "Lydia" }, { age: 21 }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"name", "age"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"Lydia", 21')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('["name", "Lydia"], ["age", 21]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-12"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-12"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("在"),s("code",[t._v("for-in")]),t._v("循环中,我们可以通过对象的 key 来进行迭代,也就是这里的"),s("code",[t._v("name")]),t._v("和"),s("code",[t._v("age")]),t._v("。在底层,对象的 key 都是字符串(如果他们不是 Symbol 的话)。在每次循环中,我们将"),s("code",[t._v("item")]),t._v("设定为当前遍历到的 key.所以一开始,"),s("code",[t._v("item")]),t._v("是"),s("code",[t._v("name")]),t._v(",之后 "),s("code",[t._v("item")]),t._v("输出的则是"),s("code",[t._v("age")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_48-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_48-输出是什么"}},[t._v("#")]),t._v(" 48. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"5"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"345"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"75"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("12")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"12"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-13"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-13"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("当所有运算符的 "),s("em",[t._v("优先级")]),t._v(" 相同时,计算表达式需要确定运算符的结合顺序,即从右到左还是从左往右。在这个例子中,我们只有一类运算符"),s("code",[t._v("+")]),t._v(",对于加法来说,结合顺序就是从左到右。")]),t._v(" "),s("p",[s("code",[t._v("3 + 4")]),t._v("首先计算,得到数字"),s("code",[t._v("7")]),t._v(".")]),t._v(" "),s("p",[t._v("由于类型的强制转换,"),s("code",[t._v("7 + '5'")]),t._v("的结果是"),s("code",[t._v('"75"')]),t._v(". JavaScript 将"),s("code",[t._v("7")]),t._v("转换成了字符串,可以参考问题 15.我们可以用"),s("code",[t._v("+")]),t._v("号把两个字符串连接起来。"),s("code",[t._v('"7" + "5"')]),t._v(" 就得到了"),s("code",[t._v('"75"')]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_49-num的值是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_49-num的值是什么"}},[t._v("#")]),t._v(" 49. "),s("code",[t._v("num")]),t._v("的值是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parseInt")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"7*6"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("42")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"42"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("7")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("NaN")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-15"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-15"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("只返回了字符串中第一个字母。设定了 "),s("em",[t._v("进制")]),t._v(" 后 (也就是第二个参数,指定需要解析的数字是什么进制:十进制、十六机制、八进制、二进制等等……),"),s("code",[t._v("parseInt")]),t._v(" 检查字符串中的字符是否合法。一旦遇到一个在指定进制中不合法的字符后,立即停止解析并且忽略后面所有的字符。")]),t._v(" "),s("p",[s("code",[t._v("*")]),t._v("就是不合法的数字字符。所以只解析到"),s("code",[t._v('"7"')]),t._v(",并将其解析为十进制的"),s("code",[t._v("7")]),t._v(". "),s("code",[t._v("num")]),t._v("的值即为"),s("code",[t._v("7")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_50-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_50-输出是什么"}},[t._v("#")]),t._v(" 50. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("map")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("num")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"number"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[null, null, null]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[undefined, undefined, undefined]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("[ 3 x empty ]")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-16"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-16"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("对数组进行映射的时候,"),s("code",[t._v("num")]),t._v("就是当前循环到的元素。在这个例子中,所有的映射都是 number 类型,所以 if 中的判断"),s("code",[t._v('typeof num === "number"')]),t._v("结果都是"),s("code",[t._v("true")]),t._v(".map 函数创建了新数组并且将函数的返回值插入数组。")]),t._v(" "),s("p",[t._v("但是,没有任何值返回。当函数没有返回任何值时,即默认返回"),s("code",[t._v("undefined")]),t._v(".对数组中的每一个元素来说,函数块都得到了这个返回值,所以结果中每一个元素都是"),s("code",[t._v("undefined")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_51-输出的是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_51-输出的是什么"}},[t._v("#")]),t._v(" 51. 输出的是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getInfo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" year")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n year "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1998"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sarah"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" birthYear "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1997"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getInfo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" birthYear"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" birthYear"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ name: "Lydia" }, "1997"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ name: "Sarah" }, "1998"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ name: "Lydia" }, "1998"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('{ name: "Sarah" }, "1997"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-17"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-17"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("普通参数都是 "),s("em",[t._v("值")]),t._v(" 传递的,而对象则不同,是 "),s("em",[t._v("引用")]),t._v(" 传递。所以说,"),s("code",[t._v("birthYear")]),t._v("是值传递,因为他是个字符串而不是对象。当我们对参数进行值传递时,会创建一份该值的 "),s("em",[t._v("复制")]),t._v("。(可以参考问题 46)")]),t._v(" "),s("p",[t._v("变量"),s("code",[t._v("birthYear")]),t._v("有一个对"),s("code",[t._v('"1997"')]),t._v("的引用,而传入的参数也有一个对"),s("code",[t._v('"1997"')]),t._v("的引用,但二者的引用并不相同。当我们通过给 "),s("code",[t._v("year")]),t._v("赋值"),s("code",[t._v('"1998"')]),t._v("来更新"),s("code",[t._v("year")]),t._v("的值的时候我们只是更新了"),s("code",[t._v("year")]),t._v("(的引用)。此时"),s("code",[t._v("birthYear")]),t._v("仍然是"),s("code",[t._v('"1997"')]),t._v(".")]),t._v(" "),s("p",[t._v("而"),s("code",[t._v("person")]),t._v("是个对象。参数"),s("code",[t._v("member")]),t._v("引用与之 "),s("em",[t._v("相同的")]),t._v(" 对象。当我们修改"),s("code",[t._v("member")]),t._v("所引用对象的属性时,"),s("code",[t._v("person")]),t._v("的相应属性也被修改了,因为他们引用了相同的对象。"),s("code",[t._v("person")]),t._v("的 "),s("code",[t._v("name")]),t._v("属性也变成了 "),s("code",[t._v('"Lydia"')]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_52-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_52-输出是什么"}},[t._v("#")]),t._v(" 52. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("greeting")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("throw")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hello world!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("try")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("greeting")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"It worked!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("catch")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Oh no an error:"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" e"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"It worked! Hello world!"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Oh no an error: undefined')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("SyntaxError: can only throw Error objects")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"Oh no an error: Hello world!')])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-6"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-6"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("通过"),s("code",[t._v("throw")]),t._v("语句,我么可以创建自定义错误。而通过它,我们可以抛出异常。异常可以是一个"),s("b",[t._v("字符串")]),t._v(",一个 "),s("b",[t._v("数字")]),t._v(",一个 "),s("b",[t._v("布尔类型")]),t._v(" 或者是一个 "),s("b",[t._v("对象")]),t._v("。在本例中,我们的异常是字符串"),s("code",[t._v("'Hello world'")]),t._v(".")]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("catch")]),t._v("语句,我们可以设定当"),s("code",[t._v("try")]),t._v("语句块中抛出异常后应该做什么处理。在本例中抛出的异常是字符串"),s("code",[t._v("'Hello world'")]),t._v(". "),s("code",[t._v("e")]),t._v("就是这个字符串,因此被输出。最终结果就是"),s("code",[t._v("'Oh an error: Hello world'")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_53-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_53-输出是什么"}},[t._v("#")]),t._v(" 53. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Car")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("make "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lamborghini"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("make")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Maserati"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myCar "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Car")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("myCar"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("make"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Lamborghini"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Maserati"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-14"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-14"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("返回属性的时候,属性的值等于 "),s("em",[t._v("返回的")]),t._v(" 值,而不是构造函数中设定的值。我们返回了字符串 "),s("code",[t._v('"Maserati"')]),t._v(",所以 "),s("code",[t._v("myCar.make")]),t._v("等于"),s("code",[t._v('"Maserati"')]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_54-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_54-输出是什么"}},[t._v("#")]),t._v(" 54. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"undefined", "number"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"number", "number"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"object", "number"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"number", "undefined"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-18"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-18"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("let x = y = 10;")]),t._v(" 是下面这个表达式的缩写:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("我们设定"),s("code",[t._v("y")]),t._v("等于"),s("code",[t._v("10")]),t._v("时,我们实际上增加了一个属性"),s("code",[t._v("y")]),t._v("给全局对象 (浏览器里的"),s("code",[t._v("window")]),t._v(", Nodejs 里的"),s("code",[t._v("global")]),t._v(")。在浏览器中,"),s("code",[t._v("window.y")]),t._v("等于"),s("code",[t._v("10")]),t._v(".")]),t._v(" "),s("p",[t._v("然后我们声明了变量"),s("code",[t._v("x")]),t._v("等于"),s("code",[t._v("y")]),t._v(",也是"),s("code",[t._v("10")]),t._v(".但变量是使用 "),s("code",[t._v("let")]),t._v("声明的,它只作用于 "),s("em",[t._v("块级作用域")]),t._v(",仅在声明它的块中有效;就是案例中的立即调用表达式 (IIFE)。使用"),s("code",[t._v("typeof")]),t._v("操作符时,操作值 "),s("code",[t._v("x")]),t._v("没有被定义:因为我们在"),s("code",[t._v("x")]),t._v("声明块的外部,无法调用它。这就意味着"),s("code",[t._v("x")]),t._v("未定义。未分配或是未声明的变量类型为"),s("code",[t._v('"undefined"')]),t._v(". "),s("code",[t._v("console.log(typeof x)")]),t._v("返回"),s("code",[t._v('"undefined"')]),t._v(".")]),t._v(" "),s("p",[t._v("而我们创建了全局变量"),s("code",[t._v("y")]),t._v(",并且设定"),s("code",[t._v("y")]),t._v("等于"),s("code",[t._v("10")]),t._v(".这个值在我们的代码各处都访问的到。"),s("code",[t._v("y")]),t._v("已经被定义了,而且有一个"),s("code",[t._v('"number"')]),t._v("类型的值。"),s("code",[t._v("console.log(typeof y)")]),t._v("返回"),s("code",[t._v('"number"')]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_55-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_55-输出是什么"}},[t._v("#")]),t._v(" "),s("a",{attrs:{name:"20190629"}}),t._v("55. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("bark")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Woof I am ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pet "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Mara"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\npet"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("bark")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("delete")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("bark"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\npet"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("bark")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Woof I am Mara"')]),t._v(", "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Woof I am Mara"')]),t._v(","),s("code",[t._v('"Woof I am Mara"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"Woof I am Mara"')]),t._v(", "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")]),t._v(", "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-19"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-19"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("我们可以用"),s("code",[t._v("delete")]),t._v("关键字删除对象的属性,对原型也是适用的。删除了原型的属性后,该属性在原型链上就不可用了。在本例中,函数"),s("code",[t._v("bark")]),t._v("在执行了"),s("code",[t._v("delete Dog.prototype.bark")]),t._v("后不可用,然而后面的代码还在调用它。")]),t._v(" "),s("p",[t._v("当我们尝试调用一个不存在的函数时"),s("code",[t._v("TypeError")]),t._v("异常会被抛出。在本例中就是 "),s("code",[t._v("TypeError: pet.bark is not a function")]),t._v(",因为"),s("code",[t._v("pet.bark")]),t._v("是"),s("code",[t._v("undefined")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_56-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_56-输出是什么"}},[t._v("#")]),t._v(" 56. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" set "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Set")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("set"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[1, 1, 2, 3, 4]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[1, 2, 3, 4]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("{1, 1, 2, 3, 4}")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("{1, 2, 3, 4}")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-7"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-7"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("Set")]),t._v("对象是独一无二的值的集合:也就是说同一个值在其中仅出现一次。")]),t._v(" "),s("p",[t._v("我们传入了数组"),s("code",[t._v("[1, 1, 2, 3, 4]")]),t._v(",他有一个重复值"),s("code",[t._v("1")]),t._v(".以为一个集合里不能有两个重复的值,其中一个就被移除了。所以结果是 "),s("code",[t._v("{1, 2, 3, 4}")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_57-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_57-输出是什么"}},[t._v("#")]),t._v(" 57. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// counter.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" counter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("default")]),t._v(" counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// index.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" myCounter "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./counter"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nmyCounter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("myCounter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("10")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("11")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Error")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("NaN")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-17"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-17"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("引入的模块是 "),s("em",[t._v("只读")]),t._v(" 的:你不能修改引入的模块。只有导出他们的模块才能修改其值。")]),t._v(" "),s("p",[t._v("当我们给"),s("code",[t._v("myCounter")]),t._v("增加一个值的时候会抛出一个异常:"),s("code",[t._v("myCounter")]),t._v("是只读的,不能被修改。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_58-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_58-输出是什么"}},[t._v("#")]),t._v(" 58. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nage "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("delete")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("delete")]),t._v(" age"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")]),t._v(", "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Lydia"')]),t._v(", "),s("code",[t._v("21")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(", "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-20"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-20"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("delete")]),t._v("操作符返回一个布尔值:"),s("code",[t._v("true")]),t._v("指删除成功,否则返回"),s("code",[t._v("false")]),t._v(". 但是通过 "),s("code",[t._v("var")]),t._v(", "),s("code",[t._v("const")]),t._v(" 或 "),s("code",[t._v("let")]),t._v(" 关键字声明的变量无法用 "),s("code",[t._v("delete")]),t._v(" 操作符来删除。")]),t._v(" "),s("p",[s("code",[t._v("name")]),t._v("变量由"),s("code",[t._v("const")]),t._v("关键字声明,所以删除不成功:返回 "),s("code",[t._v("false")]),t._v(". 而我们设定"),s("code",[t._v("age")]),t._v("等于"),s("code",[t._v("21")]),t._v("时,我们实际上添加了一个名为"),s("code",[t._v("age")]),t._v("的属性给全局对象。对象中的属性是可以删除的,全局对象也是如此,所以"),s("code",[t._v("delete age")]),t._v("返回"),s("code",[t._v("true")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_59-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_59-输出是什么"}},[t._v("#")]),t._v(" 59. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" numbers "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" numbers"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[[1, 2, 3, 4, 5]]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[1, 2, 3, 4, 5]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("1")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("[1]")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-18"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-18"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("我们可以通过解构赋值来解析来自对象的数组或属性的值,比如说:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("img",{attrs:{src:"https://i.imgur.com/ADFpVop.png",width:"200"}}),t._v(" "),s("p",[s("code",[t._v("a")]),t._v("的值现在是"),s("code",[t._v("1")]),t._v(","),s("code",[t._v("b")]),t._v("的值现在是"),s("code",[t._v("2")]),t._v(".而在题目中,我们是这么做的:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("img",{attrs:{src:"https://i.imgur.com/NzGkMNk.png",width:"200"}}),t._v(" "),s("p",[t._v("也就是说,"),s("code",[t._v("y")]),t._v("等于数组的第一个值就是数字"),s("code",[t._v("1")]),t._v(".我们输出"),s("code",[t._v("y")]),t._v(",返回"),s("code",[t._v("1")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_60-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_60-输出是什么"}},[t._v("#")]),t._v(" 60. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" user "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" admin "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("admin")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("user "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("admin"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ admin: true, user: { name: "Lydia", age: 21 } }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ admin: true, name: "Lydia", age: 21 }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ admin: true, user: ["Lydia", 21] }')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("{ admin: true }")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-15"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-15"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("扩展运算符"),s("code",[t._v("...")]),t._v("为对象的组合提供了可能。你可以复制对象中的键值对,然后把它们加到另一个对象里去。在本例中,我们复制了"),s("code",[t._v("user")]),t._v("对象键值对,然后把它们加入到"),s("code",[t._v("admin")]),t._v("对象中。"),s("code",[t._v("admin")]),t._v("对象就拥有了这些键值对,所以结果为"),s("code",[t._v('{ admin: true, name: "Lydia", age: 21 }')]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_61-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_61-输出是什么"}},[t._v("#")]),t._v(" 61. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nObject"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("defineProperty")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"age"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("value")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Object"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("keys")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ name: "Lydia", age: 21 }')]),t._v(", "),s("code",[t._v('["name", "age"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ name: "Lydia", age: 21 }')]),t._v(", "),s("code",[t._v('["name"]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ name: "Lydia"}')]),t._v(", "),s("code",[t._v('["name", "age"]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('{ name: "Lydia"}')]),t._v(", "),s("code",[t._v('["age"]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-16"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-16"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("通过"),s("code",[t._v("defineProperty")]),t._v("方法,我们可以给对象添加一个新属性,或者修改已经存在的属性。而我们使用"),s("code",[t._v("defineProperty")]),t._v("方法给对象添加了一个属性之后,属性默认为 "),s("em",[t._v("不可枚举 (not enumerable)")]),t._v(". "),s("code",[t._v("Object.keys")]),t._v("方法仅返回对象中 "),s("em",[t._v("可枚举 (enumerable)")]),t._v(" 的属性,因此只剩下了"),s("code",[t._v('"name"')]),t._v(".")]),t._v(" "),s("p",[t._v("用"),s("code",[t._v("defineProperty")]),t._v("方法添加的属性默认不可变。你可以通过"),s("code",[t._v("writable")]),t._v(", "),s("code",[t._v("configurable")]),t._v(" 和 "),s("code",[t._v("enumerable")]),t._v("属性来改变这一行为。这样,"),s("code",[t._v("defineProperty")]),t._v("方法可以让您更好地控制要添加到对象的属性。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_62-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_62-输出是什么"}},[t._v("#")]),t._v(" 62. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" settings "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("username")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"lydiahallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("level")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("19")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("health")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("90")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("stringify")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("settings"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"level"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"health"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"{"level":19, "health":90}"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"{"username": "lydiahallie"}"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"["level", "health"]"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"{"username": "lydiahallie", "level":19, "health":90}"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-21"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-21"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("JSON.stringify")]),t._v("的第二个参数是 "),s("em",[t._v("替代者 (replacer)")]),t._v(". 替代者 (replacer) 可以是个函数或数组,用以控制哪些值如何被转换为字符串。")]),t._v(" "),s("p",[t._v("如果替代者 (replacer) 是个 "),s("em",[t._v("数组")]),t._v(",那么就只有包含在数组中的属性将会被转化为字符串。在本例中,只有名为"),s("code",[t._v('"level"')]),t._v(" 和 "),s("code",[t._v('"health"')]),t._v(" 的属性被包括进来,"),s("code",[t._v('"username"')]),t._v("则被排除在外。"),s("code",[t._v("data")]),t._v(" 就等于 "),s("code",[t._v('"{"level":19, "health":90}"')]),t._v(".")]),t._v(" "),s("p",[t._v("而如果替代者 (replacer) 是个 "),s("em",[t._v("函数")]),t._v(",这个函数将被对象的每个属性都调用一遍。\n函数返回的值会成为这个属性的值,最终体现在转化后的 JSON 字符串中(译者注:Chrome 下,经过实验,如果所有属性均返回同一个值的时候有异常,会直接将返回值作为结果输出而不会输出 JSON 字符串),而如果返回值为"),s("code",[t._v("undefined")]),t._v(",则该属性会被排除在外。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_63-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_63-输出是什么"}},[t._v("#")]),t._v(" 63. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("increaseNumber")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" num"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("increasePassedNumber")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("number")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" number"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" num1 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increaseNumber")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" num2 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increasePassedNumber")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num2"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("10")]),t._v(", "),s("code",[t._v("10")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("10")]),t._v(", "),s("code",[t._v("11")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("11")]),t._v(", "),s("code",[t._v("11")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("11")]),t._v(", "),s("code",[t._v("12")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-22"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-22"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("一元操作符 "),s("code",[t._v("++")]),t._v(" "),s("em",[t._v("先返回")]),t._v(" 操作值,"),s("em",[t._v("再累加")]),t._v(" 操作值。"),s("code",[t._v("num1")]),t._v("的值是"),s("code",[t._v("10")]),t._v(",因为"),s("code",[t._v("increaseNumber")]),t._v("函数首先返回"),s("code",[t._v("num")]),t._v("的值,也就是"),s("code",[t._v("10")]),t._v(",随后再进行 "),s("code",[t._v("num")]),t._v("的累加。")]),t._v(" "),s("p",[s("code",[t._v("num2")]),t._v("是"),s("code",[t._v("10")]),t._v("因为我们将 "),s("code",[t._v("num1")]),t._v("传入"),s("code",[t._v("increasePassedNumber")]),t._v(". "),s("code",[t._v("number")]),t._v("等于"),s("code",[t._v("10")]),t._v("("),s("code",[t._v("num1")]),t._v("的值。同样道理,"),s("code",[t._v("++")]),t._v(" "),s("em",[t._v("先返回")]),t._v(" 操作值,"),s("em",[t._v("再累加")]),t._v(" 操作值。)"),s("code",[t._v("number")]),t._v("是"),s("code",[t._v("10")]),t._v(",所以"),s("code",[t._v("num2")]),t._v("也是"),s("code",[t._v("10")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_64-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_64-输出什么"}},[t._v("#")]),t._v(" 64. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" value "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("number")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("multiply")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("value "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("number "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("multiply")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("multiply")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("multiply")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("multiply")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("40")]),t._v(", "),s("code",[t._v("80")]),t._v(", "),s("code",[t._v("160")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("40")]),t._v(", "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("40")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("40")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("NaN")]),t._v(", "),s("code",[t._v("NaN")]),t._v(", "),s("code",[t._v("20")]),t._v(", "),s("code",[t._v("40")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-19"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-19"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("在 ES6 中,我们可以使用默认值初始化参数。如果没有给函数传参,或者传的参值为 "),s("code",[t._v('"undefined"')]),t._v(",那么参数的值将是默认值。上述例子中,我们将 "),s("code",[t._v("value")]),t._v(" 对象进行了解构并传到一个新对象中,因此 "),s("code",[t._v("x")]),t._v(" 的默认值为 "),s("code",[t._v("{number:10}")]),t._v("。")]),t._v(" "),s("p",[t._v("默认参数在调用时才会进行计算,每次调用函数时,都会创建一个新的对象。我们前两次调用 "),s("code",[t._v("multiply")]),t._v(" 函数且不传递值,那么每一次 "),s("code",[t._v("x")]),t._v(" 的默认值都为 "),s("code",[t._v("{number:10}")]),t._v(",因此打印出该数字的乘积值为"),s("code",[t._v("20")]),t._v("。")]),t._v(" "),s("p",[t._v("第三次调用 "),s("code",[t._v("multiply")]),t._v(" 时,我们传递了一个参数,即对象"),s("code",[t._v("value")]),t._v("。"),s("code",[t._v("*=")]),t._v("运算符实际上是"),s("code",[t._v("x.number = x.number * 2")]),t._v("的简写,我们修改了"),s("code",[t._v("x.number")]),t._v("的值,并打印出值"),s("code",[t._v("20")]),t._v("。")]),t._v(" "),s("p",[t._v("第四次,我们再次传递"),s("code",[t._v("value")]),t._v("对象。"),s("code",[t._v("x.number")]),t._v("之前被修改为"),s("code",[t._v("20")]),t._v(",所以"),s("code",[t._v("x.number * = 2")]),t._v("打印为"),s("code",[t._v("40")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_65-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_65-输出什么"}},[t._v("#")]),t._v(" 65. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reduce")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("3")]),t._v(" and "),s("code",[t._v("6")]),t._v(" "),s("code",[t._v("4")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" and "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("4")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" and "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" and "),s("code",[t._v("4")]),t._v(" "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" and "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("3")]),t._v(" and "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("4")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-8"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-8"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("reducer")]),t._v(" 函数接收 4 个参数:")]),t._v(" "),s("ol",[s("li",[t._v("Accumulator (acc) (累计器)")]),t._v(" "),s("li",[t._v("Current Value (cur) (当前值)")]),t._v(" "),s("li",[t._v("Current Index (idx) (当前索引)")]),t._v(" "),s("li",[t._v("Source Array (src) (源数组)")])]),t._v(" "),s("p",[s("code",[t._v("reducer")]),t._v(" 函数的返回值将会分配给累计器,该返回值在数组的每个迭代中被记住,并最后成为最终的单个结果值。")]),t._v(" "),s("p",[s("code",[t._v("reducer")]),t._v(" 函数还有一个可选参数"),s("code",[t._v("initialValue")]),t._v(",该参数将作为第一次调用回调函数时的第一个参数的值。如果没有提供"),s("code",[t._v("initialValue")]),t._v(",则将使用数组中的第一个元素。")]),t._v(" "),s("p",[t._v("在上述例子,"),s("code",[t._v("reduce")]),t._v("方法接收的第一个参数 (Accumulator) 是"),s("code",[t._v("x")]),t._v(",第二个参数 (Current Value) 是"),s("code",[t._v("y")]),t._v("。")]),t._v(" "),s("p",[t._v("在第一次调用时,累加器"),s("code",[t._v("x")]),t._v("为"),s("code",[t._v("1")]),t._v(",当前值"),s("code",[t._v("“y”")]),t._v("为"),s("code",[t._v("2")]),t._v(",打印出累加器和当前值:"),s("code",[t._v("1")]),t._v("和"),s("code",[t._v("2")]),t._v("。")]),t._v(" "),s("p",[t._v("例子中我们的回调函数没有返回任何值,只是打印累加器的值和当前值。如果函数没有返回值,则默认返回"),s("code",[t._v("undefined")]),t._v("。在下一次调用时,累加器为"),s("code",[t._v("undefined")]),t._v(",当前值为“3”,因此"),s("code",[t._v("undefined")]),t._v("和"),s("code",[t._v("3")]),t._v("被打印出。")]),t._v(" "),s("p",[t._v("在第四次调用时,回调函数依然没有返回值。累加器再次为 "),s("code",[t._v("undefined")]),t._v(",当前值为“4”。"),s("code",[t._v("undefined")]),t._v("和"),s("code",[t._v("4")]),t._v("被打印出。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_66-使用哪个构造函数可以成功继承dog类"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_66-使用哪个构造函数可以成功继承dog类"}},[t._v("#")]),t._v(" 66. 使用哪个构造函数可以成功继承"),s("code",[t._v("Dog")]),t._v("类?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Labrador")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("extends")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Dog")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 1")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("size "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" size"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 2")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("size "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" size"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 3")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("size "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" size"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 4")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("size "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" size"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 1")]),t._v(" "),s("li",[t._v("B: 2")]),t._v(" "),s("li",[t._v("C: 3")]),t._v(" "),s("li",[t._v("D: 4")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-17"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-17"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("在子类中,在调用"),s("code",[t._v("super")]),t._v("之前不能访问到"),s("code",[t._v("this")]),t._v("关键字。如果这样做,它将抛出一个"),s("code",[t._v("ReferenceError")]),t._v(":1 和 4 将引发一个引用错误。")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("super")]),t._v("关键字,需要用给定的参数来调用父类的构造函数。父类的构造函数接收"),s("code",[t._v("name")]),t._v("参数,因此我们需要将"),s("code",[t._v("name")]),t._v("传递给"),s("code",[t._v("super")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("Labrador")]),t._v("类接收两个参数,"),s("code",[t._v("name")]),t._v("参数是由于它继承了"),s("code",[t._v("Dog")]),t._v(","),s("code",[t._v("size")]),t._v("作为"),s("code",[t._v("Labrador")]),t._v("类的额外属性,它们都需要传递给"),s("code",[t._v("Labrador")]),t._v("的构造函数,因此使用构造函数 2 正确完成。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_67-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_67-输出什么"}},[t._v("#")]),t._v(" 67. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// index.js")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"running index.js"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./sum.js"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// sum.js")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"running sum.js"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("sum")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" b")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("running index.js")]),t._v(", "),s("code",[t._v("running sum.js")]),t._v(", "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("running sum.js")]),t._v(", "),s("code",[t._v("running index.js")]),t._v(", "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("running sum.js")]),t._v(", "),s("code",[t._v("3")]),t._v(", "),s("code",[t._v("running index.js")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("running index.js")]),t._v(", "),s("code",[t._v("undefined")]),t._v(", "),s("code",[t._v("running sum.js")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-18"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-18"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("import")]),t._v("命令是编译阶段执行的,在代码运行之前。因此这意味着被导入的模块会先运行,而导入模块的文件会后执行。")]),t._v(" "),s("p",[t._v("这是 CommonJS 中"),s("code",[t._v("require()")]),t._v("和"),s("code",[t._v("import")]),t._v("之间的区别。使用"),s("code",[t._v("require()")]),t._v(",您可以在运行代码时根据需要加载依赖项。如果我们使用"),s("code",[t._v("require")]),t._v("而不是"),s("code",[t._v("import")]),t._v(","),s("code",[t._v("running index.js")]),t._v(","),s("code",[t._v("running sum.js")]),t._v(","),s("code",[t._v("3")]),t._v("会被依次打印。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_68-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_68-输出什么"}},[t._v("#")]),t._v(" 68. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Number")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Number")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Boolean")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Boolean")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Symbol")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"foo"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Symbol")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"foo"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")]),t._v(", "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("false")]),t._v(", "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("true")]),t._v(", "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-23"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-23"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("每个"),s("code",[t._v("Symbol")]),t._v("都是完全唯一的。传递给"),s("code",[t._v("Symbol")]),t._v("的参数只是给"),s("code",[t._v("Symbol")]),t._v("的一个描述。"),s("code",[t._v("Symbol")]),t._v("的值不依赖于传递的参数。当我们测试相等时,我们创建了两个全新的符号:第一个"),s("code",[t._v("Symbol('foo')")]),t._v(",第二个"),s("code",[t._v("Symbol('foo')")]),t._v(",这两个值是唯一的,彼此不相等,因此返回"),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_69-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_69-输出什么"}},[t._v("#")]),t._v(" 69. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("padStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("13")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("padStart")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Lydia Hallie"')]),t._v(", "),s("code",[t._v('"Lydia Hallie"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('" Lydia Hallie"')]),t._v(", "),s("code",[t._v('" Lydia Hallie"')]),t._v(" ("),s("code",[t._v('"[13x whitespace]Lydia Hallie"')]),t._v(", "),s("code",[t._v('"[2x whitespace]Lydia Hallie"')]),t._v(")")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('" Lydia Hallie"')]),t._v(", "),s("code",[t._v('"Lydia Hallie"')]),t._v(" ("),s("code",[t._v('"[1x whitespace]Lydia Hallie"')]),t._v(", "),s("code",[t._v('"Lydia Hallie"')]),t._v(")")]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"Lydia Hallie"')]),t._v(", "),s("code",[t._v('"Lyd"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-20"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-20"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("padStart")]),t._v("方法,我们可以在字符串的开头添加填充。传递给此方法的参数是字符串的总长度(包含填充)。字符串"),s("code",[t._v("Lydia Hallie")]),t._v("的长度为"),s("code",[t._v("12")]),t._v(",因此"),s("code",[t._v("name.padStart(13)")]),t._v("在字符串的开头只会插入 1("),s("code",[t._v("13 - 12 = 1")]),t._v(")个空格。")]),t._v(" "),s("p",[t._v("如果传递给"),s("code",[t._v("padStart")]),t._v("方法的参数小于字符串的长度,则不会添加填充。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_70-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_70-输出什么"}},[t._v("#")]),t._v(" 70. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"💻"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"🥑💻"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("257548")])]),t._v(" "),s("li",[t._v("C: A string containing their code points")]),t._v(" "),s("li",[t._v("D: Error")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-24"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-24"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("+")]),t._v("运算符,您可以连接字符串。上述情况,我们将字符串"),s("code",[t._v("“🥑”")]),t._v("与字符串"),s("code",[t._v("”💻“")]),t._v("连接起来,产生"),s("code",[t._v("”🥑💻“")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_71-如何能打印出console-log语句后注释掉的值"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_71-如何能打印出console-log语句后注释掉的值"}},[t._v("#")]),t._v(" 71. 如何能打印出"),s("code",[t._v("console.log")]),t._v("语句后注释掉的值?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("startGame")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" 答案 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Do you love JavaScript?"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("答案 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Yes"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Oh wow... Guess we\'re gone here"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"JavaScript loves you back ❤️"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" game "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("startGame")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 1 */")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Do you love JavaScript?")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 2 */")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// JavaScript loves you back ❤️")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('game.next("Yes").value')]),t._v(" and "),s("code",[t._v("game.next().value")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('game.next.value("Yes")')]),t._v(" and "),s("code",[t._v("game.next.value()")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("game.next().value")]),t._v(" and "),s("code",[t._v('game.next("Yes").value')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("game.next.value()")]),t._v(" and "),s("code",[t._v('game.next.value("Yes")')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-21"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-21"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("generator")]),t._v("函数在遇到"),s("code",[t._v("yield")]),t._v("关键字时会“暂停”其执行。首先,我们需要让函数产生字符串"),s("code",[t._v("Do you love JavaScript?")]),t._v(",这可以通过调用"),s("code",[t._v("game.next().value")]),t._v("来完成。上述函数的第一行就有一个"),s("code",[t._v("yield")]),t._v("关键字,那么运行立即停止了,"),s("code",[t._v("yield")]),t._v("表达式本身没有返回值,或者说总是返回"),s("code",[t._v("undefined")]),t._v(",这意味着此时变量 "),s("code",[t._v("答案")]),t._v(" 为"),s("code",[t._v("undefined")])]),t._v(" "),s("p",[s("code",[t._v("next")]),t._v("方法可以带一个参数,该参数会被当作上一个 "),s("code",[t._v("yield")]),t._v(" 表达式的返回值。当我们调用"),s("code",[t._v('game.next("Yes").value')]),t._v("时,先前的 "),s("code",[t._v("yield")]),t._v(" 的返回值将被替换为传递给"),s("code",[t._v("next()")]),t._v("函数的参数"),s("code",[t._v('"Yes"')]),t._v("。此时变量 "),s("code",[t._v("答案")]),t._v(" 被赋值为 "),s("code",[t._v('"Yes"')]),t._v(","),s("code",[t._v("if")]),t._v("语句返回"),s("code",[t._v("false")]),t._v(",所以"),s("code",[t._v("JavaScript loves you back ❤️")]),t._v("被打印。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_72-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_72-输出什么"}},[t._v("#")]),t._v(" 72. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("String"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("raw"),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Hello\\nworld")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Hello world!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Hello")]),t._v(" "),s("br"),t._v(" "),s("code",[t._v("world")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Hello\\nworld")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Hello\\n")]),t._v(" "),s("br"),t._v(" "),s("code",[t._v("world")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-22"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-22"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("String.raw")]),t._v("函数是用来获取一个模板字符串的原始字符串的,它返回一个字符串,其中忽略了转义符("),s("code",[t._v("\\n")]),t._v(","),s("code",[t._v("\\v")]),t._v(","),s("code",[t._v("\\t")]),t._v("等)。但反斜杠可能造成问题,因为你可能会遇到下面这种类似情况:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" path "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("C:\\Documents\\Projects\\table.html")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nString"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("raw"),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("path"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("这将导致:")]),t._v(" "),s("p",[s("code",[t._v('"C:DocumentsProjects able.html"')])]),t._v(" "),s("p",[t._v("直接使用"),s("code",[t._v("String.raw")])]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("String"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("raw"),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("C:\\Documents\\Projects\\table.html")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("它会忽略转义字符并打印:"),s("code",[t._v("C:\\Documents\\Projects\\table.html")])]),t._v(" "),s("p",[t._v("上述情况,字符串是"),s("code",[t._v("Hello\\nworld")]),t._v("被打印出。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_73-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_73-输出什么"}},[t._v("#")]),t._v(" 73. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getData")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I made it!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getData")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"I made it!"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('Promise {: "I made it!"}')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Promise {}")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-23"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-23"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("异步函数始终返回一个 promise。"),s("code",[t._v("await")]),t._v("仍然需要等待 promise 的解决:当我们调用"),s("code",[t._v("getData()")]),t._v("并将其赋值给"),s("code",[t._v("data")]),t._v(",此时"),s("code",[t._v("data")]),t._v("为"),s("code",[t._v("getData")]),t._v("方法返回的一个挂起的 promise,该 promise 并没有解决。")]),t._v(" "),s("p",[t._v("如果我们想要访问已解决的值"),s("code",[t._v('"I made it!"')]),t._v(",可以在"),s("code",[t._v("data")]),t._v("上使用"),s("code",[t._v(".then()")]),t._v("方法:")]),t._v(" "),s("p",[s("code",[t._v("data.then(res => console.log(res))")])]),t._v(" "),s("p",[t._v("这样将打印 "),s("code",[t._v('"I made it!"')])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_74-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_74-输出什么"}},[t._v("#")]),t._v(" 74. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addToList")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" list")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" result "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addToList")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"apple"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"banana"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("result"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("['apple', 'banana']")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-19"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-19"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("push()")]),t._v("方法返回新数组的长度。一开始,数组包含一个元素(字符串"),s("code",[t._v('"banana"')]),t._v("),长度为 1。在数组中添加字符串"),s("code",[t._v('"apple"')]),t._v("后,长度变为 2,并将从"),s("code",[t._v("addToList")]),t._v("函数返回。")]),t._v(" "),s("p",[s("code",[t._v("push")]),t._v("方法修改原始数组,如果你想从函数返回数组而不是数组长度,那么应该在 push "),s("code",[t._v("item")]),t._v("之后返回"),s("code",[t._v("list")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_75-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_75-输出什么"}},[t._v("#")]),t._v(" 75. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" box "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("y")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nObject"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("freeze")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("box"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" shape "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" box"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nshape"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("100")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("shape"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("{ x: 100, y: 20 }")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("{ x: 10, y: 20 }")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("{ x: 100 }")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-20"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-20"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("Object.freeze")]),t._v("使得无法添加、删除或修改对象的属性(除非属性的值是另一个对象)。")]),t._v(" "),s("p",[t._v("当我们创建变量"),s("code",[t._v("shape")]),t._v("并将其设置为等于冻结对象"),s("code",[t._v("box")]),t._v("时,"),s("code",[t._v("shape")]),t._v("指向的也是冻结对象。你可以使用"),s("code",[t._v("Object.isFrozen")]),t._v("检查一个对象是否被冻结,上述情况,"),s("code",[t._v("Object.isFrozen(shape)")]),t._v("将返回"),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[t._v("由于"),s("code",[t._v("shape")]),t._v("被冻结,并且"),s("code",[t._v("x")]),t._v("的值不是对象,所以我们不能修改属性"),s("code",[t._v("x")]),t._v("。"),s("code",[t._v("x")]),t._v("仍然等于"),s("code",[t._v("10")]),t._v(","),s("code",[t._v("{x:10,y:20}")]),t._v("被打印。")]),t._v(" "),s("p",[t._v("注意,上述例子我们对属性"),s("code",[t._v("x")]),t._v("进行修改,可能会导致抛出 TypeError 异常(最常见但不仅限于严格模式下时)。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_76-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_76-输出什么"}},[t._v("#")]),t._v(" 76. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" myName "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Lydia"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"myName"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-9"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-9"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("当我们从右侧的对象解构属性"),s("code",[t._v("name")]),t._v("时,我们将其值"),s("code",[t._v("Lydia")]),t._v("分配给名为"),s("code",[t._v("myName")]),t._v("的变量。")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("{name:myName}")]),t._v(",我们是在告诉 JavaScript 我们要创建一个名为"),s("code",[t._v("myName")]),t._v("的新变量,并且其值是右侧对象的"),s("code",[t._v("name")]),t._v("属性的值。")]),t._v(" "),s("p",[t._v("当我们尝试打印"),s("code",[t._v("name")]),t._v(",一个未定义的变量时,就会引发"),s("code",[t._v("ReferenceError")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_77-以下是个纯函数么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_77-以下是个纯函数么"}},[t._v("#")]),t._v(" 77. 以下是个纯函数么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" b")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: Yes")]),t._v(" "),s("li",[t._v("B: No")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-25"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-25"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("纯函数在相同的输入值时,需产生相同的输出,其输出的结果,与输入值以外的其他隐藏信息或状态无关,也和由 I/O 设备产生的外部输出无关。\n纯函数不会产生副作用。")]),t._v(" "),s("p",[t._v("纯函数与副作用的定义可参考:\nhttps://zh.wikipedia.org/wiki/%E5%89%AF%E4%BD%9C%E7%94%A8_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_78-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_78-输出什么"}},[t._v("#")]),t._v(" 78. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("add")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" cache "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("num")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("From cache! ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" result "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n cache"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" result"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Calculated! ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("result"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" addFunction "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Calculated! 20")]),t._v(" "),s("code",[t._v("Calculated! 20")]),t._v(" "),s("code",[t._v("Calculated! 20")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Calculated! 20")]),t._v(" "),s("code",[t._v("From cache! 20")]),t._v(" "),s("code",[t._v("Calculated! 20")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Calculated! 20")]),t._v(" "),s("code",[t._v("From cache! 20")]),t._v(" "),s("code",[t._v("From cache! 20")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Calculated! 20")]),t._v(" "),s("code",[t._v("From cache! 20")]),t._v(" "),s("code",[t._v("Error")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-24"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-24"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("add")]),t._v("函数是一个记忆函数。通过记忆化,我们可以缓存函数的结果,以加快其执行速度。上述情况,我们创建一个"),s("code",[t._v("cache")]),t._v("对象,用于存储先前返回过的值。")]),t._v(" "),s("p",[t._v("如果我们使用相同的参数多次调用"),s("code",[t._v("addFunction")]),t._v("函数,它首先检查缓存中是否已有该值,如果有,则返回缓存值,这将节省执行时间。如果没有,那么它将计算该值,并存储在缓存中。")]),t._v(" "),s("p",[t._v("我们用相同的值三次调用了"),s("code",[t._v("addFunction")]),t._v("函数:")]),t._v(" "),s("p",[t._v("在第一次调用,"),s("code",[t._v("num")]),t._v("等于"),s("code",[t._v("10")]),t._v("时函数的值尚未缓存,if 语句"),s("code",[t._v("num in cache")]),t._v("返回"),s("code",[t._v("false")]),t._v(",else 块的代码被执行:"),s("code",[t._v("Calculated! 20")]),t._v(",并且其结果被添加到缓存对象,"),s("code",[t._v("cache")]),t._v("现在看起来像"),s("code",[t._v("{10:20}")]),t._v("。")]),t._v(" "),s("p",[t._v("第二次,"),s("code",[t._v("cache")]),t._v("对象包含"),s("code",[t._v("10")]),t._v("的返回值。if 语句 "),s("code",[t._v("num in cache")]),t._v(" 返回"),s("code",[t._v("true")]),t._v(","),s("code",[t._v("From cache! 20")]),t._v("被打印。")]),t._v(" "),s("p",[t._v("第三次,我们将"),s("code",[t._v("5 * 2")]),t._v("(值为 10) 传递给函数。"),s("code",[t._v("cache")]),t._v("对象包含"),s("code",[t._v("10")]),t._v("的返回值。if 语句 "),s("code",[t._v("num in cache")]),t._v(" 返回"),s("code",[t._v("true")]),t._v(","),s("code",[t._v("From cache! 20")]),t._v("被打印。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_79-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_79-输出什么"}},[t._v("#")]),t._v(" "),s("a",{attrs:{name:"20190726"}}),t._v("79. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myLifeSummedUp "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"☕"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"💻"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍷"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍫"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" item "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("in")]),t._v(" myLifeSummedUp"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" item "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("of")]),t._v(" myLifeSummedUp"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("0")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")]),t._v(" and "),s("code",[t._v('"☕"')]),t._v(" "),s("code",[t._v('"💻"')]),t._v(" "),s("code",[t._v('"🍷"')]),t._v(" "),s("code",[t._v('"🍫"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"☕"')]),t._v(" "),s("code",[t._v('"💻"')]),t._v(" "),s("code",[t._v('"🍷"')]),t._v(" "),s("code",[t._v('"🍫"')]),t._v(" and "),s("code",[t._v('"☕"')]),t._v(" "),s("code",[t._v('"💻"')]),t._v(" "),s("code",[t._v('"🍷"')]),t._v(" "),s("code",[t._v('"🍫"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"☕"')]),t._v(" "),s("code",[t._v('"💻"')]),t._v(" "),s("code",[t._v('"🍷"')]),t._v(" "),s("code",[t._v('"🍫"')]),t._v(" and "),s("code",[t._v("0")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("0")]),t._v(" "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")]),t._v(" and "),s("code",[t._v('{0: "☕", 1: "💻", 2: "🍷", 3: "🍫"}')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-26"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-26"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("通过"),s("code",[t._v("for-in")]),t._v("循环,我们可以遍历一个对象"),s("strong",[t._v("自有的")]),t._v("、"),s("strong",[t._v("继承的")]),t._v("、"),s("strong",[t._v("可枚举的")]),t._v("、"),s("strong",[t._v("非 Symbol 的")]),t._v("属性。在数组中,可枚举属性是数组元素的“键”,即它们的索引。类似于下面这个对象:")]),t._v(" "),s("p",[s("code",[t._v('{0: "☕", 1: "💻", 2: "🍷", 3: "🍫"}')])]),t._v(" "),s("p",[t._v("其中键则是可枚举属性,因此 "),s("code",[t._v("0")]),t._v(","),s("code",[t._v("1")]),t._v(","),s("code",[t._v("2")]),t._v(","),s("code",[t._v("3")]),t._v("被记录。")]),t._v(" "),s("p",[t._v("通过"),s("code",[t._v("for-of")]),t._v("循环,我们可以迭代"),s("strong",[t._v("可迭代对象")]),t._v("(包括 "),s("code",[t._v("Array")]),t._v(","),s("code",[t._v("Map")]),t._v(","),s("code",[t._v("Set")]),t._v(","),s("code",[t._v("String")]),t._v(","),s("code",[t._v("arguments")]),t._v("等)。当我们迭代数组时,在每次迭代中,不同属性的值将被分配给变量"),s("code",[t._v("item")]),t._v(",因此"),s("code",[t._v("“☕”")]),t._v(","),s("code",[t._v("“💻”")]),t._v(","),s("code",[t._v("“🍷”")]),t._v(","),s("code",[t._v("“🍫”")]),t._v("被打印。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_80-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_80-输出什么"}},[t._v("#")]),t._v(" 80. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" list "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('["1 + 2", "1 * 2", "1 / 2"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["12", 2, 0.5]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[3, 2, 0.5]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("[1, 1, 1]")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-25"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-25"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("数组元素可以包含任何值。数字,字符串,布尔值,对象,数组,"),s("code",[t._v("null")]),t._v(","),s("code",[t._v("undefined")]),t._v(",以及其他表达式,如日期,函数和计算。")]),t._v(" "),s("p",[t._v("元素将等于返回的值。"),s("code",[t._v("1 + 2")]),t._v("返回"),s("code",[t._v("3")]),t._v(","),s("code",[t._v("1 * 2")]),t._v("返回'2"),s("code",[t._v(",'1 / 2")]),t._v("返回"),s("code",[t._v("0.5")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_81-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_81-输出什么"}},[t._v("#")]),t._v(" 81. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Hi there, ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sayHi")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Hi there,")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Hi there, undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Hi there, null")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-21"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-21"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("默认情况下,如果不给函数传参,参数的值将为"),s("code",[t._v("undefined")]),t._v("。上述情况,我们没有给参数"),s("code",[t._v("name")]),t._v("传值。"),s("code",[t._v("name")]),t._v("等于"),s("code",[t._v("undefined")]),t._v(",并被打印。")]),t._v(" "),s("p",[t._v("在 ES6 中,我们可以使用默认参数覆盖此默认的"),s("code",[t._v("undefined")]),t._v("值。例如:")]),t._v(" "),s("p",[s("code",[t._v("function sayHi (name =“Lydia”){...}")])]),t._v(" "),s("p",[t._v("在这种情况下,如果我们没有传递值或者如果我们传递"),s("code",[t._v("undefined")]),t._v(","),s("code",[t._v("name")]),t._v("总是等于字符串"),s("code",[t._v("Lydia")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_82-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_82-输出什么"}},[t._v("#")]),t._v(" 82. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" status "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"😎"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" status "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"😍"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("status")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getStatus")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("status"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getStatus")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getStatus")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("call")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"🥑"')]),t._v(" and "),s("code",[t._v('"😍"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"🥑"')]),t._v(" and "),s("code",[t._v('"😎"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"😍"')]),t._v(" and "),s("code",[t._v('"😎"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"😎"')]),t._v(" and "),s("code",[t._v('"😎"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-22"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-22"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("this")]),t._v("关键字的指向取决于使用它的位置。在"),s("strong",[t._v("函数")]),t._v("中,比如"),s("code",[t._v("getStatus")]),t._v(","),s("code",[t._v("this")]),t._v("指向的是调用它的对象,上述例子中"),s("code",[t._v("data")]),t._v("对象调用了"),s("code",[t._v("getStatus")]),t._v(",因此"),s("code",[t._v("this")]),t._v("指向的就是"),s("code",[t._v("data")]),t._v("对象。当我们打印"),s("code",[t._v("this.status")]),t._v("时,"),s("code",[t._v("data")]),t._v("对象的"),s("code",[t._v("status")]),t._v("属性被打印,即"),s("code",[t._v('"🥑"')]),t._v("。")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("call")]),t._v("方法,可以更改"),s("code",[t._v("this")]),t._v("指向的对象。"),s("code",[t._v("data.getStatus.call(this)")]),t._v("是将"),s("code",[t._v("this")]),t._v("的指向由"),s("code",[t._v("data")]),t._v("对象更改为全局对象。在全局对象上,有一个名为"),s("code",[t._v("status")]),t._v("的变量,其值为"),s("code",[t._v("”😎“")]),t._v("。因此打印"),s("code",[t._v("this.status")]),t._v("时,会打印"),s("code",[t._v("“😎”")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_83-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_83-输出什么"}},[t._v("#")]),t._v(" 83. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" city "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("city"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ncity "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Amsterdam"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ name: "Lydia", age: 21 }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ name: "Lydia", age: 21, city: "Amsterdam" }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ name: "Lydia", age: 21, city: undefined }')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"Amsterdam"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-27"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-27"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("我们将变量"),s("code",[t._v("city")]),t._v("设置为等于"),s("code",[t._v("person")]),t._v("对象上名为"),s("code",[t._v("city")]),t._v("的属性的值。这个对象上没有名为"),s("code",[t._v("city")]),t._v("的属性,因此变量"),s("code",[t._v("city")]),t._v("的值为"),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("请注意,我们没有引用"),s("code",[t._v("person")]),t._v("对象本身,只是将变量"),s("code",[t._v("city")]),t._v("设置为等于"),s("code",[t._v("person")]),t._v("对象上"),s("code",[t._v("city")]),t._v("属性的当前值。")]),t._v(" "),s("p",[t._v("然后,我们将"),s("code",[t._v("city")]),t._v("设置为等于字符串"),s("code",[t._v("“Amsterdam”")]),t._v("。这不会更改 person 对象:没有对该对象的引用。")]),t._v(" "),s("p",[t._v("因此打印"),s("code",[t._v("person")]),t._v("对象时,会返回未修改的对象。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_84-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_84-输出什么"}},[t._v("#")]),t._v(" 84. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("checkAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("18")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" message "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sorry, you\'re too young."')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" message "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Yay! You\'re old enough!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" message"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("checkAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Sorry, you\'re too young."')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Yay! You\'re old enough!"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-26"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-26"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("const")]),t._v("和"),s("code",[t._v("let")]),t._v("声明的变量是具有"),s("strong",[t._v("块级作用域")]),t._v("的,块是大括号("),s("code",[t._v("{}")]),t._v(")之间的任何东西,即上述情况"),s("code",[t._v("if / else")]),t._v("语句的花括号。由于块级作用域,我们无法在声明的块之外引用变量,因此抛出"),s("code",[t._v("ReferenceError")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_85-什么样的信息将被打印"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_85-什么样的信息将被打印"}},[t._v("#")]),t._v(" 85. 什么样的信息将被打印?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("fetch")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https://www.website.com/api/user/1"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("json")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("fetch")]),t._v("方法的结果")]),t._v(" "),s("li",[t._v("B: 第二次调用"),s("code",[t._v("fetch")]),t._v("方法的结果")]),t._v(" "),s("li",[t._v("C: 前一个"),s("code",[t._v(".then()")]),t._v("中回调方法返回的结果")]),t._v(" "),s("li",[t._v("D: 总是"),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-27"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-27"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("第二个"),s("code",[t._v(".then")]),t._v("中"),s("code",[t._v("res")]),t._v("的值等于前一个"),s("code",[t._v(".then")]),t._v("中的回调函数返回的值。你可以像这样继续链接"),s("code",[t._v(".then")]),t._v(",将值传递给下一个处理程序。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_86-哪个选项是将hasname设置为true的方法-前提是不能将true作为参数传递"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_86-哪个选项是将hasname设置为true的方法-前提是不能将true作为参数传递"}},[t._v("#")]),t._v(" 86. 哪个选项是将"),s("code",[t._v("hasName")]),t._v("设置为"),s("code",[t._v("true")]),t._v("的方法,前提是不能将"),s("code",[t._v("true")]),t._v("作为参数传递?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" hasName "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("!!name")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("name")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("new Boolean(name)")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("name.length")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-28"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-28"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("使用逻辑非运算符"),s("code",[t._v("!")]),t._v(",将返回一个布尔值,使用"),s("code",[t._v("!! name")]),t._v(",我们可以确定"),s("code",[t._v("name")]),t._v("的值是真的还是假的。如果"),s("code",[t._v("name")]),t._v("是真实的,那么"),s("code",[t._v("!name")]),t._v("返回"),s("code",[t._v("false")]),t._v("。"),s("code",[t._v("!false")]),t._v("返回"),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[t._v("通过将"),s("code",[t._v("hasName")]),t._v("设置为"),s("code",[t._v("name")]),t._v(",可以将"),s("code",[t._v("hasName")]),t._v("设置为等于传递给"),s("code",[t._v("getName")]),t._v("函数的值,而不是布尔值"),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("new Boolean(true)")]),t._v("返回一个对象包装器,而不是布尔值本身。")]),t._v(" "),s("p",[s("code",[t._v("name.length")]),t._v("返回传递的参数的长度,而不是布尔值"),s("code",[t._v("true")]),t._v("。")]),t._v(" "),s("h6",{attrs:{id:"_87-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_87-输出什么"}},[t._v("#")]),t._v(" 87. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I want pizza"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"""')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"I"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-23"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-23"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("可以使用方括号表示法获取字符串中特定索引的字符,字符串中的第一个字符具有索引 0,依此类推。在这种情况下,我们想要得到索引为 0 的元素,字符"),s("code",[t._v("'I'")]),t._v("被记录。")]),t._v(" "),s("p",[t._v("请注意,IE7 及更低版本不支持此方法。在这种情况下,应该使用"),s("code",[t._v(".charAt()")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_88-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_88-输出什么"}},[t._v("#")]),t._v(" 88. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("num1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" num2 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" num1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num1 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" num2"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("20")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-24"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-24"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("您可以将默认参数的值设置为函数的另一个参数,只要另一个参数定义在其之前即可。我们将值"),s("code",[t._v("10")]),t._v("传递给"),s("code",[t._v("sum")]),t._v("函数。如果"),s("code",[t._v("sum")]),t._v("函数只接收 1 个参数,则意味着没有传递"),s("code",[t._v("num2")]),t._v("的值,这种情况下,"),s("code",[t._v("num1")]),t._v("的值等于传递的值"),s("code",[t._v("10")]),t._v("。"),s("code",[t._v("num2")]),t._v("的默认值是"),s("code",[t._v("num1")]),t._v("的值,即"),s("code",[t._v("10")]),t._v("。"),s("code",[t._v("num1 + num2")]),t._v("返回"),s("code",[t._v("20")]),t._v("。")]),t._v(" "),s("p",[t._v("如果您尝试将默认参数的值设置为后面定义的参数,则可能导致参数的值尚未初始化,从而引发错误。比如:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("m "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("m"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Uncaught ReferenceError: Cannot access 'n' before initialization")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 3 2")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 3 4")]),t._v("\n")])])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_89-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_89-输出什么"}},[t._v("#")]),t._v(" 89. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// module.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("default")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hello world"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// index.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("as")]),t._v(" data "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./module"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ default: function default(), name: "Lydia" }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("{ default: function default() }")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ default: "Hello world", name: "Lydia" }')])]),t._v(" "),s("li",[t._v("D: Global object of "),s("code",[t._v("module.js")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-29"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-29"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("import * as name")]),t._v("语法,我们将"),s("code",[t._v("module.js")]),t._v("文件中所有"),s("code",[t._v("export")]),t._v("导入到"),s("code",[t._v("index.js")]),t._v("文件中,并且创建了一个名为"),s("code",[t._v("data")]),t._v("的新对象。在"),s("code",[t._v("module.js")]),t._v("文件中,有两个导出:默认导出和命名导出。默认导出是一个返回字符串“Hello World”的函数,命名导出是一个名为"),s("code",[t._v("name")]),t._v("的变量,其值为字符串"),s("code",[t._v("“Lydia”")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("data")]),t._v("对象具有默认导出的"),s("code",[t._v("default")]),t._v("属性,其他属性具有指定 exports 的名称及其对应的值。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_90-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_90-输出什么"}},[t._v("#")]),t._v(" 90. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" member "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"John"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"class"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"function"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('"object"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"string"')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-28"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-28"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("类是构造函数的语法糖,如果用构造函数的方式来重写"),s("code",[t._v("Person")]),t._v("类则将是:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("通过"),s("code",[t._v("new")]),t._v("来调用构造函数,将会生成构造函数"),s("code",[t._v("Person")]),t._v("的实例,对实例执行"),s("code",[t._v("typeof")]),t._v("关键字将返回"),s("code",[t._v('"object"')]),t._v(",上述情况打印出"),s("code",[t._v('"object"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_91-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_91-输出什么"}},[t._v("#")]),t._v(" 91. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" newList "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("newList"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[1, 2, 3, 4, 5]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[1, 2, 3, 5]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[1, 2, 3, 4]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Error")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-10"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-10"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v(".push")]),t._v("方法返回数组的长度,而不是数组本身!通过将"),s("code",[t._v("newList")]),t._v("设置为"),s("code",[t._v("[1,2,3].push(4)")]),t._v(",实际上"),s("code",[t._v("newList")]),t._v("等于数组的新长度:"),s("code",[t._v("4")]),t._v("。")]),t._v(" "),s("p",[t._v("然后,尝试在"),s("code",[t._v("newList")]),t._v("上使用"),s("code",[t._v(".push")]),t._v("方法。由于"),s("code",[t._v("newList")]),t._v("是数值"),s("code",[t._v("4")]),t._v(",抛出 TypeError。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_92-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_92-输出什么"}},[t._v("#")]),t._v(" 92. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("giveLydiaPizza")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Here is pizza!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("giveLydiaChocolate")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Here\'s chocolate... now go hit the gym already."')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("giveLydiaPizza"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("giveLydiaChocolate"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("prototype"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("{ constructor: ...}")]),t._v(" "),s("code",[t._v("{ constructor: ...}")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("{}")]),t._v(" "),s("code",[t._v("{ constructor: ...}")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("{ constructor: ...}")]),t._v(" "),s("code",[t._v("{}")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("{ constructor: ...}")]),t._v(" "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-11"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-11"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("常规函数,例如"),s("code",[t._v("giveLydiaPizza")]),t._v("函数,有一个"),s("code",[t._v("prototype")]),t._v("属性,它是一个带有"),s("code",[t._v("constructor")]),t._v("属性的对象(原型对象)。然而,箭头函数,例如"),s("code",[t._v("giveLydiaChocolate")]),t._v("函数,没有这个"),s("code",[t._v("prototype")]),t._v("属性。尝试使用"),s("code",[t._v("giveLydiaChocolate.prototype")]),t._v("访问"),s("code",[t._v("prototype")]),t._v("属性时会返回"),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_93-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_93-输出什么"}},[t._v("#")]),t._v(" 93. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("of")]),t._v(" Object"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("entries")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("name")]),t._v(" "),s("code",[t._v("Lydia")]),t._v(" and "),s("code",[t._v("age")]),t._v(" "),s("code",[t._v("21")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["name", "Lydia"]')]),t._v(" and "),s("code",[t._v('["age", 21]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('["name", "age"]')]),t._v(" and "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Error")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-30"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-30"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("Object.entries()")]),t._v("方法返回一个给定对象自身可枚举属性的键值对数组,上述情况返回一个二维数组,数组每个元素是一个包含键和值的数组:")]),t._v(" "),s("p",[s("code",[t._v("[['name','Lydia'],['age', 21]]")])]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("for-of")]),t._v("循环,我们可以迭代数组中的每个元素,上述情况是子数组。我们可以使用"),s("code",[t._v("const [x,y]")]),t._v("在"),s("code",[t._v("for-of")]),t._v("循环中解构子数组。"),s("code",[t._v("x")]),t._v("等于子数组中的第一个元素,"),s("code",[t._v("y")]),t._v("等于子数组中的第二个元素。")]),t._v(" "),s("p",[t._v("第一个子阵列是"),s("code",[t._v("[“name”,“Lydia”]")]),t._v(",其中"),s("code",[t._v("x")]),t._v("等于"),s("code",[t._v("name")]),t._v(",而"),s("code",[t._v("y")]),t._v("等于"),s("code",[t._v("Lydia")]),t._v("。\n第二个子阵列是"),s("code",[t._v("[“age”,21]")]),t._v(",其中"),s("code",[t._v("x")]),t._v("等于"),s("code",[t._v("age")]),t._v(",而"),s("code",[t._v("y")]),t._v("等于"),s("code",[t._v("21")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_94-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_94-输出什么"}},[t._v("#")]),t._v(" 94. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getItems")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("fruitList"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("args"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" favoriteFruit")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("fruitList"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("args"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" favoriteFruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getItems")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"banana"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"apple"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"pear"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"orange"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('["banana", "apple", "pear", "orange"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('[["banana", "apple"], "pear", "orange"]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('["banana", "apple", ["pear"], "orange"]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-12"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-12"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("... args")]),t._v("是剩余参数,剩余参数的值是一个包含所有剩余参数的数组,"),s("strong",[t._v("并且只能作为最后一个参数")]),t._v("。上述示例中,剩余参数是第二个参数,这是不可能的,并会抛出语法错误。")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getItems")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("fruitList"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" favoriteFruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("args")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("fruitList"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("args"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" favoriteFruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getItems")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"banana"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"apple"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"pear"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"orange"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("上述例子是有效的,将会返回数组:"),s("code",[t._v("[ 'banana', 'apple', 'orange', 'pear' ]")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_95-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_95-输出什么"}},[t._v("#")]),t._v(" "),s("a",{attrs:{name:"20190817"}}),t._v("95. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("nums")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("a"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" b")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a is bigger"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b is bigger"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n a "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("nums")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("nums")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("a is bigger")]),t._v(", "),s("code",[t._v("6")]),t._v(" and "),s("code",[t._v("b is bigger")]),t._v(", "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("a is bigger")]),t._v(", "),s("code",[t._v("undefined")]),t._v(" and "),s("code",[t._v("b is bigger")]),t._v(", "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")]),t._v(" and "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-25"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-25"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("在 JavaScript 中,我们不必显式地编写分号 ("),s("code",[t._v(";")]),t._v("),但是 JavaScript 引擎仍然在语句之后自动添加分号。这称为"),s("strong",[t._v("自动分号插入")]),t._v("。例如,一个语句可以是变量,或者像"),s("code",[t._v("throw")]),t._v("、"),s("code",[t._v("return")]),t._v("、"),s("code",[t._v("break")]),t._v("这样的关键字。")]),t._v(" "),s("p",[t._v("在这里,我们在新的一行上写了一个"),s("code",[t._v("return")]),t._v("语句和另一个值"),s("code",[t._v("a + b")]),t._v("。然而,由于它是一个新行,引擎并不知道它实际上是我们想要返回的值。相反,它会在"),s("code",[t._v("return")]),t._v("后面自动添加分号。你可以这样看:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\na "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" b"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("这意味着永远不会到达"),s("code",[t._v("a + b")]),t._v(",因为函数在"),s("code",[t._v("return")]),t._v("关键字之后停止运行。如果没有返回值,就像这里,函数返回"),s("code",[t._v("undefined")]),t._v("。注意,在"),s("code",[t._v("if/else")]),t._v("语句之后没有自动插入!")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_96-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_96-输出什么"}},[t._v("#")]),t._v(" 96. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nPerson "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("AnotherPerson")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sarah"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" member "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"Lydia"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"Sarah"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Error: cannot redeclare Person")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-26"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-26"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("我们可以将类设置为等于其他类/函数构造函数。在这种情况下,我们将"),s("code",[t._v("Person")]),t._v("设置为"),s("code",[t._v("AnotherPerson")]),t._v("。这个构造函数的名字是"),s("code",[t._v("Sarah")]),t._v(",所以新的"),s("code",[t._v("Person")]),t._v("实例"),s("code",[t._v("member")]),t._v("上的 name 属性是"),s("code",[t._v("Sarah")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_97-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_97-输出什么"}},[t._v("#")]),t._v(" 97. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" info "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("Symbol")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("info"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Object"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("keys")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("info"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("{Symbol('a'): 'b'}")]),t._v(" and "),s("code",[t._v("[\"{Symbol('a')\"]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("{}")]),t._v(" and "),s("code",[t._v("[]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ a: "b" }')]),t._v(" and "),s("code",[t._v('["a"]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("{Symbol('a'): 'b'}")]),t._v(" and "),s("code",[t._v("[]")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-13"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-13"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("Symbol")]),t._v("类型是不可枚举的。"),s("code",[t._v("Object.keys")]),t._v("方法返回对象上的所有可枚举的键属性。"),s("code",[t._v("Symbol")]),t._v("类型是不可见的,并返回一个空数组。记录整个对象时,所有属性都是可见的,甚至是不可枚举的属性。")]),t._v(" "),s("p",[t._v("这是"),s("code",[t._v("Symbol")]),t._v("的众多特性之一:除了表示完全唯一的值(防止对象意外名称冲突,例如当使用 2 个想要向同一对象添加属性的库时),您还可以"),s("code",[t._v("隐藏")]),t._v("这种方式对象的属性(尽管不完全。你仍然可以使用"),s("code",[t._v("Object.getOwnPropertySymbols()")]),t._v("方法访问 "),s("code",[t._v("Symbol")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_98-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_98-输出什么"}},[t._v("#")]),t._v(" 98. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("getList")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("getUser")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("user")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("age "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" list "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" user "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getList")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[1, [2, 3, 4]]")]),t._v(" and "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[1, [2, 3, 4]]")]),t._v(" and "),s("code",[t._v('{ name: "Lydia", age: 21 }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[1, 2, 3, 4]")]),t._v(" and "),s("code",[t._v('{ name: "Lydia", age: 21 }')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Error")]),t._v(" and "),s("code",[t._v('{ name: "Lydia", age: 21 }')])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-31"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-31"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("getList")]),t._v("函数接收一个数组作为其参数。在"),s("code",[t._v("getList")]),t._v("函数的括号之间,我们立即解构这个数组。您可以将其视为:")]),t._v(" "),s("p",[s("code",[t._v("[x, ...y] = [1, 2, 3, 4]")])]),t._v(" "),s("p",[t._v("使用剩余的参数"),s("code",[t._v("... y")]),t._v(",我们将所有剩余参数放在一个数组中。在这种情况下,其余的参数是"),s("code",[t._v("2")]),t._v(","),s("code",[t._v("3")]),t._v("和"),s("code",[t._v("4")]),t._v("。 "),s("code",[t._v("y")]),t._v("的值是一个数组,包含所有其余参数。在这种情况下,"),s("code",[t._v("x")]),t._v("的值等于"),s("code",[t._v("1")]),t._v(",所以当我们打印"),s("code",[t._v("[x,y]")]),t._v("时,会打印"),s("code",[t._v("[1,[2,3,4]]")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("getUser")]),t._v("函数接收一个对象。对于箭头函数,如果只返回一个值,我们不必编写花括号。但是,如果您想从一个箭头函数返回一个对象,您必须将它写在圆括号之间,否则两个花括号之间的所有内容都将被解释为一个块语句!在这种情况下,花括号之间的代码不是有效的 JavaScript 代码,因此会抛出 SyntaxError。")]),t._v(" "),s("p",[t._v("以下函数将返回一个对象:")]),t._v(" "),s("p",[s("code",[t._v("const getUser = user => ({ name: user.name, age: user.age })")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_99-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_99-输出什么"}},[t._v("#")]),t._v(" 99. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-29"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-29"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("变量"),s("code",[t._v("name")]),t._v("保存字符串的值,该字符串不是函数,因此无法调用。")]),t._v(" "),s("p",[t._v("当值不是预期类型时,会抛出"),s("code",[t._v("TypeErrors")]),t._v("。JavaScript 期望"),s("code",[t._v("name")]),t._v("是一个函数,因为我们试图调用它。但它是一个字符串,因此抛出"),s("code",[t._v("TypeError")]),t._v(":"),s("code",[t._v("name is not a function")])]),t._v(" "),s("p",[t._v("当你编写了一些非有效的 JavaScript 时,会抛出语法错误,例如当你把"),s("code",[t._v("return")]),t._v("这个词写成"),s("code",[t._v("retrun")]),t._v("时。\n当 JavaScript 无法找到您尝试访问的值的引用时,抛出"),s("code",[t._v("ReferenceErrors")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_100-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_100-输出什么"}},[t._v("#")]),t._v(" 100. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 🎉✨ This is my 100th question! ✨🎉")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" output "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Im"')]),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("possible!\nYou should")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("n't")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" see a therapist after so much JavaScript lol")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("possible! You should see a therapist after so much JavaScript lol")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Impossible! You should see a therapist after so much JavaScript lol")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("possible! You shouldn't see a therapist after so much JavaScript lol")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Impossible! You shouldn't see a therapist after so much JavaScript lol")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-27"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-27"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("[]")]),t._v("是一个真值。使用"),s("code",[t._v("&&")]),t._v("运算符,如果左侧值是真值,则返回右侧值。在这种情况下,左侧值"),s("code",[t._v("[]")]),t._v("是一个真值,所以返回"),s("code",[t._v("Im")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v('""')]),t._v("是一个假值。如果左侧值是假的,则不返回任何内容。"),s("code",[t._v("n't")]),t._v("不会被退回。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_101-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_101-输出什么"}},[t._v("#")]),t._v(" 101.输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" one "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" two "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" three "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" three"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("[]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v('""')]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("{}")]),t._v(" "),s("code",[t._v('""')]),t._v(" "),s("code",[t._v("[]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-30"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-30"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("||")]),t._v("运算符,我们可以返回第一个真值。如果所有值都是假值,则返回最后一个值。")]),t._v(" "),s("p",[s("code",[t._v("(false || {} || null)")]),t._v(":空对象"),s("code",[t._v("{}")]),t._v("是一个真值。这是第一个(也是唯一的)真值,它将被返回。"),s("code",[t._v("one")]),t._v("等于"),s("code",[t._v("{}")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("(null || false ||“”)")]),t._v(":所有值都是假值。这意味着返回传递的值"),s("code",[t._v('""')]),t._v("。"),s("code",[t._v("two")]),t._v("等于"),s("code",[t._v('""')]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("([] || 0 ||“”)")]),t._v(":空数组"),s("code",[t._v("[]")]),t._v("是一个真值。这是第一个返回的真值。"),s("code",[t._v("three")]),t._v("等于"),s("code",[t._v("[]")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_102-依次输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_102-依次输出什么"}},[t._v("#")]),t._v(" 102. 依次输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("myPromise")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I have resolved!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("firstFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myPromise")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"second"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("secondFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myPromise")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"second"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("firstFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("secondFunction")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("I have resolved!")]),t._v(", "),s("code",[t._v("second")]),t._v(" and "),s("code",[t._v("I have resolved!")]),t._v(", "),s("code",[t._v("second")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("second")]),t._v(", "),s("code",[t._v("I have resolved!")]),t._v(" and "),s("code",[t._v("second")]),t._v(", "),s("code",[t._v("I have resolved!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("I have resolved!")]),t._v(", "),s("code",[t._v("second")]),t._v(" and "),s("code",[t._v("second")]),t._v(", "),s("code",[t._v("I have resolved!")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("second")]),t._v(", "),s("code",[t._v("I have resolved!")]),t._v(" and "),s("code",[t._v("I have resolved!")]),t._v(", "),s("code",[t._v("second")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-14"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-14"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("有了 promise,我们通常会说:当我想要调用某个方法,但是由于它可能需要一段时间,因此暂时将它放在一边。只有当某个值被 resolved/rejected,并且执行栈为空时才使用这个值。")]),t._v(" "),s("p",[t._v("我们可以在"),s("code",[t._v("async")]),t._v("函数中通过"),s("code",[t._v(".then")]),t._v("和"),s("code",[t._v("await")]),t._v("关键字获得该值。尽管我们可以通过"),s("code",[t._v(".then")]),t._v("和"),s("code",[t._v("await")]),t._v("获得 promise 的价值,但是它们的工作方式有所不同。")]),t._v(" "),s("p",[t._v("在 "),s("code",[t._v("firstFunction")]),t._v("中,当运行到"),s("code",[t._v("myPromise")]),t._v("方法时我们将其放在一边,即 promise 进入微任务队列,其他后面的代码("),s("code",[t._v("console.log('second')")]),t._v(")照常运行,因此"),s("code",[t._v("second")]),t._v("被打印出,"),s("code",[t._v("firstFunction")]),t._v("方法到此执行完毕,执行栈中宏任务队列被清空,此时开始执行微任务队列中的任务,"),s("code",[t._v("I have resolved")]),t._v("被打印出。")]),t._v(" "),s("p",[t._v("在"),s("code",[t._v("secondFunction")]),t._v("方法中,我们通过"),s("code",[t._v("await")]),t._v("关键字,暂停了后面代码的执行,直到异步函数的值被解析才开始后面代码的执行。这意味着,它会等着直到 "),s("code",[t._v("myPromise")]),t._v(" 以值"),s("code",[t._v("I have resolved")]),t._v("被解决之后,下一行"),s("code",[t._v("second")]),t._v("才开始执行。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_103-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_103-输出什么"}},[t._v("#")]),t._v(" 103. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" set "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Set")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nset"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nset"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nset"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" item "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("of")]),t._v(" set"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("3")]),t._v(", "),s("code",[t._v("NaN")]),t._v(", "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("3")]),t._v(", "),s("code",[t._v("7")]),t._v(", "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("3")]),t._v(", "),s("code",[t._v("Lydia2")]),t._v(", "),s("code",[t._v("[Object object]2")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('"12"')]),t._v(", "),s("code",[t._v("Lydia2")]),t._v(", "),s("code",[t._v("[Object object]2")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-31"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-31"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("“+”运算符不仅用于添加数值,还可以使用它来连接字符串。每当 JavaScript 引擎发现一个或多个值不是数字时,就会将数字强制为字符串。")]),t._v(" "),s("p",[t._v("第一个是数字 1。1 + 2 返回数字 3。")]),t._v(" "),s("p",[t._v("但是,第二个是字符串“Lydia”。 “Lydia”是一个字符串,2 是一个数字:2 被强制转换为字符串。 “Lydia”和“2”被连接起来,产生字符串“Lydia2”。")]),t._v(" "),s("p",[s("code",[t._v("{name:“Lydia”}")]),t._v("是一个对象。数字和对象都不是字符串,因此将二者都字符串化。每当我们对常规对象进行字符串化时,它就会变成"),s("code",[t._v("[Object object]")]),t._v("。与“2”串联的“ [Object object]”成为“[Object object]2”。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_104-结果是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_104-结果是什么"}},[t._v("#")]),t._v(" 104. 结果是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("5")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Promise {: 5}")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Promise {: 5}")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Error")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-32"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-32"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("我们可以将我们想要的任何类型的值传递"),s("code",[t._v("Promise.resolve")]),t._v(",无论是否"),s("code",[t._v("promise")]),t._v("。该方法本身返回带有已解析值的"),s("code",[t._v("Promise")]),t._v(" ("),s("code",[t._v("")]),t._v(")。如果您传递常规函数,它将是具有常规值的已解决"),s("code",[t._v("promise")]),t._v("。如果你通过了 promise,它将是一个已经 resolved 的且带有传的值的 promise。")]),t._v(" "),s("p",[t._v("上述情况,我们传了数字 5,因此返回一个 resolved 状态的 promise,resolve 值为"),s("code",[t._v("5")])]),t._v(" "),s("h6",{attrs:{id:"_105-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_105-输出什么"}},[t._v("#")]),t._v(" 105. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("compareMembers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("person1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" person2 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" person")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person1 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!==")]),t._v(" person2"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Not the same!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"They are the same!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("compareMembers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Not the same!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("They are the same!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-28"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-28"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("对象通过引用传递。当我们检查对象的严格相等性(===)时,我们正在比较它们的引用。")]),t._v(" "),s("p",[t._v("我们将“person2”的默认值设置为“person”对象,并将“person”对象作为“person1”的值传递。")]),t._v(" "),s("p",[t._v("这意味着两个值都引用内存中的同一位置,因此它们是相等的。")]),t._v(" "),s("p",[t._v("运行“else”语句中的代码块,并记录"),s("code",[t._v("They are the same!")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_106-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_106-输出什么"}},[t._v("#")]),t._v(" 106. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" colorConfig "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("red")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("blue")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("green")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("black")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("yellow")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" colors "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"pink"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"red"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"blue"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("colorConfig"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("colors"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-15"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-15"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("在 JavaScript 中,我们有两种访问对象属性的方法:括号表示法或点表示法。在此示例中,我们使用点表示法("),s("code",[t._v("colorConfig.colors")]),t._v(")代替括号表示法("),s("code",[t._v("colorConfig [“colors”]")]),t._v(")。")]),t._v(" "),s("p",[t._v("使用点表示法,JavaScript 会尝试使用该确切名称在对象上查找属性。在此示例中,JavaScript 尝试在 colorConfig 对象上找到名为 colors 的属性。没有名为“colors”的属性,因此返回“undefined”。\n然后,我们尝试使用"),s("code",[t._v("[1]")]),t._v("访问第一个元素的值。我们无法对未定义的值执行此操作,因此会抛出"),s("code",[t._v("Cannot read property '1' of undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("JavaScript 解释(或取消装箱)语句。当我们使用方括号表示法时,它会看到第一个左方括号"),s("code",[t._v("[")]),t._v("并一直进行下去,直到找到右方括号"),s("code",[t._v("]")]),t._v("。只有这样,它才会评估该语句。如果我们使用了 colorConfig [colors [1]],它将返回 colorConfig 对象上 red 属性的值。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_107-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_107-输出什么"}},[t._v("#")]),t._v(" 107. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"❤️"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"❤️"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("false")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-32"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-32"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("在内部,表情符号是 unicode。heat 表情符号的 unicode 是"),s("code",[t._v("“U + 2764 U + FE0F”")]),t._v("。对于相同的表情符号,它们总是相同的,因此我们将两个相等的字符串相互比较,这将返回 true。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_108-哪些方法修改了原数组"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_108-哪些方法修改了原数组"}},[t._v("#")]),t._v(" 108. 哪些方法修改了原数组?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" emojis "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"😍"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("map")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("filter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("find")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reduce")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("acc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" cur")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" acc "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("slice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nemojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("splice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("All of them")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("map")]),t._v(" "),s("code",[t._v("reduce")]),t._v(" "),s("code",[t._v("slice")]),t._v(" "),s("code",[t._v("splice")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("map")]),t._v(" "),s("code",[t._v("slice")]),t._v(" "),s("code",[t._v("splice")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("splice")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-16"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-16"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("splice")]),t._v("方法,我们通过删除,替换或添加元素来修改原始数组。在这种情况下,我们从索引 1 中删除了 2 个元素(我们删除了"),s("code",[t._v("'🥑'")]),t._v("和"),s("code",[t._v("'😍'")]),t._v("),同时添加了 ✨emoji 表情。")]),t._v(" "),s("p",[s("code",[t._v("map")]),t._v(","),s("code",[t._v("filter")]),t._v("和"),s("code",[t._v("slice")]),t._v("返回一个新数组,"),s("code",[t._v("find")]),t._v("返回一个元素,而"),s("code",[t._v("reduce")]),t._v("返回一个减小的值。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_109-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_109-输出什么"}},[t._v("#")]),t._v(" "),s("a",{attrs:{name:"20191009"}}),t._v("109. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" food "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍕"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍫"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍔"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" info "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("favoriteFood")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" food"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\ninfo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("favoriteFood "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍝"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("food"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("['🍕', '🍫', '🥑', '🍔']")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("['🍝', '🍫', '🥑', '🍔']")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("['🍝', '🍕', '🍫', '🥑', '🍔']")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-33"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-33"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("我们将"),s("code",[t._v("info")]),t._v("对象上的"),s("code",[t._v("favoriteFood")]),t._v("属性的值设置为披萨表情符号“🍕”的字符串。字符串是原始数据类型。在 JavaScript 中,原始数据类型通过值起作用")]),t._v(" "),s("p",[t._v("在这种情况下,我们将"),s("code",[t._v("info")]),t._v("对象上的"),s("code",[t._v("favoriteFood")]),t._v("属性的值设置为等于"),s("code",[t._v("food")]),t._v("数组中的第一个元素的值,字符串为披萨表情符号("),s("code",[t._v("'🍕'")]),t._v(")。字符串是原始数据类型,并且通过值进行交互,我们更改"),s("code",[t._v("info")]),t._v("对象上"),s("code",[t._v("favoriteFood")]),t._v("属性的值。food 数组没有改变,因为 favoriteFood 的值只是该数组中第一个元素的值的复制,并且与该元素上的元素没有相同的内存引用食物"),s("code",[t._v("[0]")]),t._v("。当我们记录食物时,它仍然是原始数组"),s("code",[t._v("['🍕','🍫','🥑','🍔']")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_110-这个函数干了什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_110-这个函数干了什么"}},[t._v("#")]),t._v(" 110. 这个函数干了什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: Parses JSON to a JavaScript value")]),t._v(" "),s("li",[t._v("B: Parses a JavaScript object to JSON")]),t._v(" "),s("li",[t._v("C: Parses any JavaScript value to JSON")]),t._v(" "),s("li",[t._v("D: Parses JSON to a JavaScript object only")])]),t._v(" "),s("h4",{attrs:{id:"答案-a-34"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-34"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("使用"),s("code",[t._v("JSON.parse()")]),t._v("方法,我们可以将 JSON 字符串解析为 JavaScript 值。")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 将数字字符串化为有效的 JSON,然后将 JSON 字符串解析为 JavaScript 值:")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" jsonNumber "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("stringify")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// '4'")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("jsonNumber"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 4")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 将数组值字符串化为有效的 JSON,然后将 JSON 字符串解析为 JavaScript 值:")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" jsonArray "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("stringify")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// '[1, 2, 3]'")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("jsonArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// [1, 2, 3]")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 将对象字符串化为有效的 JSON,然后将 JSON 字符串解析为 JavaScript 值:")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" jsonArray "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("stringify")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// \'{"name":"Lydia"}\'')]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token constant"}},[t._v("JSON")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("parse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("jsonArray"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// { name: 'Lydia' }")]),t._v("\n")])])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_111-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_111-输出什么"}},[t._v("#")]),t._v(" 111. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sarah"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: Lydia")]),t._v(" "),s("li",[t._v("B: Sarah")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-17"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-17"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("每个函数都有其自己的执行上下文。"),s("code",[t._v("getName")]),t._v("函数首先在其自身的上下文(范围)内查找,以查看其是否包含我们尝试访问的变量"),s("code",[t._v("name")]),t._v("。上述情况,"),s("code",[t._v("getName")]),t._v("函数包含其自己的"),s("code",[t._v("name")]),t._v("变量:我们用"),s("code",[t._v("let")]),t._v("关键字和"),s("code",[t._v("Sarah")]),t._v("的值声明变量"),s("code",[t._v("name")]),t._v("。")]),t._v(" "),s("p",[t._v("带有"),s("code",[t._v("let")]),t._v("关键字(和"),s("code",[t._v("const")]),t._v(")的变量被提升,但是与"),s("code",[t._v("var")]),t._v("不同,它不会被**_ 初始化_**。在我们声明(初始化)它们之前,无法访问它们。这称为“暂时性死区”。当我们尝试在声明变量之前访问变量时,JavaScript 会抛出"),s("code",[t._v("ReferenceError: Cannot access 'name' before initialization")]),t._v("。")]),t._v(" "),s("p",[t._v("如果我们不在"),s("code",[t._v("getName")]),t._v("函数中声明"),s("code",[t._v("name")]),t._v("变量,则 javascript 引擎会查看原型链。会找到其外部作用域有一个名为"),s("code",[t._v("name")]),t._v("的变量,其值为"),s("code",[t._v("Lydia")]),t._v("。在这种情况下,它将打印"),s("code",[t._v("Lydia")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Lydia")]),t._v("\n")])])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_112-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_112-输出什么"}},[t._v("#")]),t._v(" 112. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generatorOne")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generatorTwo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"c"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" one "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generatorOne")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" two "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generatorTwo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("a")]),t._v(" and "),s("code",[t._v("a")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("a")]),t._v(" and "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("['a', 'b', 'c']")]),t._v(" and "),s("code",[t._v("a")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("a")]),t._v(" and "),s("code",[t._v("['a', 'b', 'c']")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-33"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-33"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("yield")]),t._v(" 关键字,我们在 "),s("code",[t._v("Generator")]),t._v(" 函数里执行"),s("code",[t._v("yield")]),t._v("表达式。通过 "),s("code",[t._v("yield*")]),t._v(" 关键字,我们可以在一个"),s("code",[t._v("Generator")]),t._v(" 函数里面执行("),s("code",[t._v("yield")]),t._v("表达式)另一个 "),s("code",[t._v("Generator")]),t._v(" 函数,或可遍历的对象 (如数组).")]),t._v(" "),s("p",[t._v("在函数 "),s("code",[t._v("generatorOne")]),t._v(" 中,我们通过 "),s("code",[t._v("yield")]),t._v(" 关键字 yield 了一个完整的数组 "),s("code",[t._v("['a', 'b', 'c']")]),t._v("。函数"),s("code",[t._v("one")]),t._v("通过"),s("code",[t._v("next")]),t._v("方法返回的对象的"),s("code",[t._v("value")]),t._v(" 属性的值 ("),s("code",[t._v("one.next().value")]),t._v(") 等价于数组 "),s("code",[t._v("['a', 'b', 'c']")]),t._v(".")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ['a', 'b', 'c']")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("one"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// undefined")]),t._v("\n")])])]),s("p",[t._v("在函数 "),s("code",[t._v("generatorTwo")]),t._v(" 中,我们使用 "),s("code",[t._v("yield*")]),t._v(" 关键字。就相当于函数"),s("code",[t._v("two")]),t._v("第一个"),s("code",[t._v("yield")]),t._v("的值,等价于在迭代器中第一个 "),s("code",[t._v("yield")]),t._v(" 的值。数组"),s("code",[t._v("['a', 'b', 'c']")]),t._v("就是这个迭代器。第一个 "),s("code",[t._v("yield")]),t._v(" 的值就是 "),s("code",[t._v("a")]),t._v(",所以我们第一次调用 "),s("code",[t._v("two.next().value")]),t._v("时,就返回"),s("code",[t._v("a")]),t._v("。")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 'a'")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 'b'")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 'c'")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("two"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// undefined")]),t._v("\n")])])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_113-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_113-输出什么"}},[t._v("#")]),t._v(" 113. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[t._v("console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I love"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" to program")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("I love to program")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("undefined to program")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("${(x => x)('I love') to program")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("TypeError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-35"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-35"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("带有模板字面量的表达式首先被执行。相当于字符串会包含表达式,这个立即执行函数 "),s("code",[t._v("(x => x)('I love')")]),t._v(" 返回的值。我们向箭头函数 "),s("code",[t._v("x => x")]),t._v(" 传递 "),s("code",[t._v("'I love'")]),t._v(" 作为参数。"),s("code",[t._v("x")]),t._v(" 等价于返回的 "),s("code",[t._v("'I love'")]),t._v("。这就是结果 "),s("code",[t._v("I love to program")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_114-将会发生什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_114-将会发生什么"}},[t._v("#")]),t._v(" 114. 将会发生什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" config "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("alert")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setInterval")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Alert!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconfig "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("setInterval")]),t._v(" 的回调不会被调用")]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("setInterval")]),t._v(" 的回调被调用一次")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("setInterval")]),t._v(" 的回调仍然会被每秒钟调用")]),t._v(" "),s("li",[t._v("D: 我们从没调用过 "),s("code",[t._v("config.alert()")]),t._v(", config 为 "),s("code",[t._v("null")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-34"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-34"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("一般情况下当我们将对象赋值为 "),s("code",[t._v("null")]),t._v(",那些对象会被进行 "),s("em",[t._v("垃圾回收(garbage collected)")]),t._v(" 因为已经没有对这些对象的引用了。然而,"),s("code",[t._v("setInterval")]),t._v("的参数是一个箭头函数(所以上下文绑定到对象 "),s("code",[t._v("config")]),t._v(" 了),回调函数仍然保留着对 "),s("code",[t._v("config")]),t._v("的引用。只要存在引用,对象就不会被垃圾回收。因为没有被垃圾回收,"),s("code",[t._v("setInterval")]),t._v(" 的回调每 1000ms (1s) 会被调用一次。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_115-哪一个方法会返回-hello-world"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_115-哪一个方法会返回-hello-world"}},[t._v("#")]),t._v(" 115. 哪一个方法会返回 "),s("code",[t._v("'Hello world!'")]),t._v(" ?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myMap "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Map")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("myFunc")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"greeting"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nmyMap"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("set")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("myFunc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hello world!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//1")]),t._v("\nmyMap"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"greeting"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//2")]),t._v("\nmyMap"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("myFunc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//3")]),t._v("\nmyMap"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("get")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"greeting"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 1")]),t._v(" "),s("li",[t._v("B: 2")]),t._v(" "),s("li",[t._v("C: 2 and 3")]),t._v(" "),s("li",[t._v("D: All of them")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-29"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-29"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("当通过 "),s("code",[t._v("set")]),t._v(" 方法添加一个键值对,一个传递给 "),s("code",[t._v("set")]),t._v("方法的参数将会是键名,第二个参数将会是值。在这个 case 里,键名为 "),s("em",[t._v("函数")]),t._v(" "),s("code",[t._v("() => 'greeting'")]),t._v(",值为"),s("code",[t._v("'Hello world'")]),t._v("。 "),s("code",[t._v("myMap")]),t._v(" 现在就是 "),s("code",[t._v("{ () => 'greeting' => 'Hello world!' }")]),t._v("。")]),t._v(" "),s("p",[t._v("1 是错的,因为键名不是 "),s("code",[t._v("'greeting'")]),t._v(" 而是 "),s("code",[t._v("() => 'greeting'")]),t._v("。\n3 是错的,因为我们给"),s("code",[t._v("get")]),t._v(" 方法传递了一个新的函数。对象受 "),s("em",[t._v("引用")]),t._v(" 影响。函数也是对象,因此两个函数严格上并不等价,尽管他们相同:他们有两个不同的内存引用地址。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_116-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_116-输出什么"}},[t._v("#")]),t._v(" 116. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("changeAge")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("person "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("changeAgeAndName")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("person "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sarah"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("changeAge")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("changeAgeAndName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{name: "Sarah", age: 22}')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{name: "Sarah", age: 23}')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{name: "Lydia", age: 22}')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('{name: "Lydia", age: 23}')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-35"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-35"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("函数 "),s("code",[t._v("changeAge")]),t._v(" 和函数 "),s("code",[t._v("changeAgeAndName")]),t._v(" 有着不同的参数,定义一个 "),s("em",[t._v("新")]),t._v(" 生成的对象 "),s("code",[t._v("{ ...person }")]),t._v("。这个对象有着所有 "),s("code",[t._v("person")]),t._v(" 对象 中 k/v 值的副本。")]),t._v(" "),s("p",[t._v("首项,我们调用 "),s("code",[t._v("changeAge")]),t._v(" 函数并传递 "),s("code",[t._v("person")]),t._v(" 对象作为它的参数。这个函数对 "),s("code",[t._v("age")]),t._v(" 属性进行加一操作。"),s("code",[t._v("person")]),t._v(" 现在是 "),s("code",[t._v('{ name: "Lydia", age: 22 }')]),t._v("。")]),t._v(" "),s("p",[t._v("然后,我们调用函数 "),s("code",[t._v("changeAgeAndName")]),t._v(",然而我们没有传递参数。取而代之,"),s("code",[t._v("x")]),t._v(" 的值等价 "),s("em",[t._v("new")]),t._v(" 生成的对象:"),s("code",[t._v("{ ...person }")]),t._v("。因为它是一个新生成的对象,它并不会对对象 "),s("code",[t._v("person")]),t._v(" 造成任何副作用。"),s("code",[t._v("person")]),t._v(" 仍然等价于 "),s("code",[t._v('{ name: "Lydia", age: 22 }')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_117-下面那个选项将会返回-6"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_117-下面那个选项将会返回-6"}},[t._v("#")]),t._v(" 117. 下面那个选项将会返回 "),s("code",[t._v("6")]),t._v("?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sumValues")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" z")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" z"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("sumValues([...1, 2, 3])")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("sumValues([...[1, 2, 3]])")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("sumValues(...[1, 2, 3])")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("sumValues([1, 2, 3])")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-36"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-36"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("通过展开操作符 "),s("code",[t._v("...")]),t._v(",我们可以 "),s("em",[t._v("暂开")]),t._v(" 单个可迭代的元素。函数 "),s("code",[t._v("sumValues")]),t._v(" function 接收三个参数:"),s("code",[t._v("x")]),t._v(", "),s("code",[t._v("y")]),t._v(" 和 "),s("code",[t._v("z")]),t._v("。"),s("code",[t._v("...[1, 2, 3]")]),t._v(" 的执行结果为 "),s("code",[t._v("1, 2, 3")]),t._v(",将会传递给函数 "),s("code",[t._v("sumValues")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_118-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_118-输出什么"}},[t._v("#")]),t._v(" 118. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" list "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥳"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🤠"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥰"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🤪"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("list"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("🤠")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("🥰")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("SyntaxError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-30"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-30"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("+=")]),t._v(" 操作符,我们对值 "),s("code",[t._v("num")]),t._v(" 进行加 "),s("code",[t._v("1")]),t._v(" 操作。"),s("code",[t._v("num")]),t._v(" 有初始值 "),s("code",[t._v("1")]),t._v(",因此 "),s("code",[t._v("1 + 1")]),t._v(" 的执行结果为 "),s("code",[t._v("2")]),t._v("。数组 "),s("code",[t._v("list")]),t._v(" 的第二项为 🥰,"),s("code",[t._v("console.log(list[2])")]),t._v(" 输出 🥰.")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_119-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_119-输出什么"}},[t._v("#")]),t._v(" 119. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("firstName")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("lastName")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("pet")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Mara"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("breed")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Dutch Tulip Hound"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFullName")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("firstName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("lastName"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("pet"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("pet"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),t._v("family"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("getFullName"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("getLastName"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Mara")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("Lydia Hallie")]),t._v(" "),s("code",[t._v("ReferenceError")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Mara")]),t._v(" "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("Lydia Hallie")]),t._v(" "),s("code",[t._v("null")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("ReferenceError")]),t._v(" "),s("code",[t._v("null")]),t._v(" "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-31"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-31"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("通过 ES10 或 TS3.7+"),s("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"}},[t._v("可选链操作符 "),s("code",[t._v("?.")]),s("OutboundLink")],1),t._v(",我们不再需要显式检测更深层的嵌套值是否有效。如果我们尝试获取 "),s("code",[t._v("undefined")]),t._v(" 或 "),s("code",[t._v("null")]),t._v(" 的值 ("),s("em",[t._v("nullish")]),t._v("),表达将会短路并返回 "),s("code",[t._v("undefined")]),t._v(".")]),t._v(" "),s("p",[s("code",[t._v("person.pet?.name")]),t._v(":"),s("code",[t._v("person")]),t._v(" 有一个名为 "),s("code",[t._v("pet")]),t._v(" 的属性:"),s("code",[t._v("person.pet")]),t._v(" 不是 nullish。它有个名为 "),s("code",[t._v("name")]),t._v(" 的属性,并返回字符串 "),s("code",[t._v("Mara")]),t._v("。\n"),s("code",[t._v("person.pet?.family?.name")]),t._v(":"),s("code",[t._v("person")]),t._v(" 有一个名为 "),s("code",[t._v("pet")]),t._v(" 的属性:"),s("code",[t._v("person.pet")]),t._v(" 不是 nullish. "),s("code",[t._v("pet")]),t._v(" "),s("em",[t._v("并没有")]),t._v(" 一个名为 "),s("code",[t._v("family")]),t._v(" 的属性,"),s("code",[t._v("person.pet.family")]),t._v(" 是 nullish。表达式返回 "),s("code",[t._v("undefined")]),t._v("。\n"),s("code",[t._v("person.getFullName?.()")]),t._v(":"),s("code",[t._v("person")]),t._v(" 有一个名为 "),s("code",[t._v("getFullName")]),t._v(" 的属性:"),s("code",[t._v("person.getFullName()")]),t._v(" 不是 nullish 并可以被调用,返回字符串 "),s("code",[t._v("Lydia Hallie")]),t._v("。\n"),s("code",[t._v("member.getLastName?.()")]),t._v(": 变量"),s("code",[t._v("member")]),t._v(" 不存在,因此会抛出错误"),s("code",[t._v("ReferenceError")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_120-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_120-输出什么"}},[t._v("#")]),t._v(" 120. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" groceries "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"banana"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"apple"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"peanuts"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("groceries"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("indexOf")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"banana"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"We have to buy bananas!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("We don't have to buy bananas!")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: We have to buy bananas!")]),t._v(" "),s("li",[t._v("B: We don't have to buy bananas")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("1")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-32"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-32"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("我们传递了一个状态 "),s("code",[t._v('groceries.indexOf("banana")')]),t._v(" 给 if 条件语句。"),s("code",[t._v('groceries.indexOf("banana")')]),t._v(" 返回 "),s("code",[t._v("0")]),t._v(",一个 falsy 的值。因为 if 条件语句的状态为 falsy,"),s("code",[t._v("else")]),t._v(" 块区内的代码执行,并且 "),s("code",[t._v("We don't have to buy bananas!")]),t._v(" 被输出。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_121-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_121-输出什么"}},[t._v("#")]),t._v(" 121. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" config "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("languages")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("set")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("language")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("lang")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("languages"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("lang"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("config"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("language"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("function language(lang) { this.languages.push(lang }")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("0")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-18"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-18"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("方法 "),s("code",[t._v("language")]),t._v(" 是一个 "),s("code",[t._v("setter")]),t._v("。Setters 并不保存一个实际值,它们的使命在于 "),s("em",[t._v("修改")]),t._v(" 属性。当调用方法 "),s("code",[t._v("setter")]),t._v(",返回 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_122-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_122-输出什么"}},[t._v("#")]),t._v(" 122. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"object"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"string"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-37"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-37"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("typeof name")]),t._v(" 返回 "),s("code",[t._v('"string"')]),t._v("。字符串 "),s("code",[t._v('"string"')]),t._v(" 是一个 truthy 的值,因此 "),s("code",[t._v("!typeof name")]),t._v(" 返回一个布尔值 "),s("code",[t._v("false")]),t._v("。"),s("code",[t._v('false === "object"')]),t._v(" 和 "),s("code",[t._v('false === "string"')]),t._v(" 都返回 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("p",[t._v("(如果我们想检测一个值的类型,我们应该用 "),s("code",[t._v("!==")]),t._v(" 而不是 "),s("code",[t._v("!typeof")]),t._v(")")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_123-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_123-输出什么"}},[t._v("#")]),t._v(" 123. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("add")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("y")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("z")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" z"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" z"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("6")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("4")]),t._v(" "),s("code",[t._v("5")]),t._v(" "),s("code",[t._v("6")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("6")]),t._v(" "),s("code",[t._v("5")]),t._v(" "),s("code",[t._v("4")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("4")]),t._v(" "),s("code",[t._v("function")]),t._v(" "),s("code",[t._v("function")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("6")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-36"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-36"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("函数 "),s("code",[t._v("add")]),t._v(" 是一个返回 返回箭头函数的箭头函数 的箭头函数(still with me?)。第一个函数接收一个值为 "),s("code",[t._v("4")]),t._v(" 的参数 "),s("code",[t._v("x")]),t._v("。我们调用第二个函数,它接收一个值为 "),s("code",[t._v("5")]),t._v(" 的参数 "),s("code",[t._v("y")]),t._v("。然后我们调用第三个函数,它接收一个值为 "),s("code",[t._v("6")]),t._v(" 的参数 "),s("code",[t._v("z")]),t._v("。当我们尝试在最后一个箭头函数中获取 "),s("code",[t._v("x")]),t._v(", "),s("code",[t._v("y")]),t._v(" 和 "),s("code",[t._v("z")]),t._v(" 的值,JS 引擎根据作用域链去找 "),s("code",[t._v("x")]),t._v(" 和 "),s("code",[t._v("y")]),t._v(" 的值。得到 "),s("code",[t._v("4")]),t._v(" "),s("code",[t._v("5")]),t._v(" "),s("code",[t._v("6")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_124-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_124-输出什么"}},[t._v("#")]),t._v(" 124. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("range")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("start"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" end")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" start"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" end"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" gen "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("range")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" item "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("of")]),t._v(" gen"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("item"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Promise {1}")]),t._v(" "),s("code",[t._v("Promise {2}")]),t._v(" "),s("code",[t._v("Promise {3}")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Promise {}")]),t._v(" "),s("code",[t._v("Promise {}")]),t._v(" "),s("code",[t._v("Promise {}")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-38"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-38"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("我们给 函数 range 传递:"),s("code",[t._v("Promise{1}")]),t._v(", "),s("code",[t._v("Promise{2}")]),t._v(", "),s("code",[t._v("Promise{3}")]),t._v(",Generator 函数 "),s("code",[t._v("range")]),t._v(" 返回一个全是 async object promise 数组。我们将 async object 赋值给变量 "),s("code",[t._v("gen")]),t._v(",之后我们使用"),s("code",[t._v("for await ... of")]),t._v(" 进行循环遍历。我们将返回的 Promise 实例赋值给 "),s("code",[t._v("item")]),t._v(":第一个返回 "),s("code",[t._v("Promise{1}")]),t._v(",第二个返回 "),s("code",[t._v("Promise{2}")]),t._v(",之后是 "),s("code",[t._v("Promise{3}")]),t._v("。因为我们正 "),s("em",[t._v("awaiting")]),t._v(" "),s("code",[t._v("item")]),t._v(" 的值,resolved 状态的 promise,promise 数组的 resolved "),s("em",[t._v("值")]),t._v(" 以此为:"),s("code",[t._v("1")]),t._v(","),s("code",[t._v("2")]),t._v(","),s("code",[t._v("3")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_125-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_125-输出什么"}},[t._v("#")]),t._v(" 125. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("myFunc")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" z "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" z"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("1")]),t._v(" "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("3")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("{1: 1}")]),t._v(" "),s("code",[t._v("{2: 2}")]),t._v(" "),s("code",[t._v("{3: 3}")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("{ 1: undefined }")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")]),t._v(" "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-19"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-19"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("myFunc")]),t._v(" 期望接收一个包含 "),s("code",[t._v("x")]),t._v(", "),s("code",[t._v("y")]),t._v(" 和 "),s("code",[t._v("z")]),t._v(" 属性的对象作为它的参数。因为我们仅仅传递三个单独的数字值 (1, 2, 3) 而不是一个含有 "),s("code",[t._v("x")]),t._v(", "),s("code",[t._v("y")]),t._v(" 和 "),s("code",[t._v("z")]),t._v(" 属性的对象 ({x: 1, y: 2, z: 3}),"),s("code",[t._v("x")]),t._v(", "),s("code",[t._v("y")]),t._v(" 和 "),s("code",[t._v("z")]),t._v(" 有着各自的默认值 "),s("code",[t._v("undefined")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_126-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_126-输出什么"}},[t._v("#")]),t._v(" 126. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFine")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("speed"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" amount")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" formattedSpeed "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Intl"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("NumberFormat")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"en-US"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("style")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"unit"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("unit")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"mile-per-hour"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("format")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("speed"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" formattedAmount "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Intl"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("NumberFormat")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"en-US"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("style")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"currency"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("currency")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"USD"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("format")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("amount"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("The driver drove ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("formattedSpeed"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v(" and has to pay ")]),s("span",{pre:!0,attrs:{class:"token interpolation"}},[s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("${")]),t._v("formattedAmount"),s("span",{pre:!0,attrs:{class:"token interpolation-punctuation punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFine")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("130")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("300")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: The driver drove 130 and has to pay 300")]),t._v(" "),s("li",[t._v("B: The driver drove 130 mph and has to pay $300.00")]),t._v(" "),s("li",[t._v("C: The driver drove undefined and has to pay undefined")]),t._v(" "),s("li",[t._v("D: The driver drove 130.00 and has to pay 300.00")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-33"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-33"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("通过方法 "),s("code",[t._v("Intl.NumberFormat")]),t._v(",我们可以格式化任意区域的数字值。我们对数字值 "),s("code",[t._v("130")]),t._v(" 进行 "),s("code",[t._v("mile-per-hour")]),t._v(" 作为 "),s("code",[t._v("unit")]),t._v(" 的 "),s("code",[t._v("en-US")]),t._v(" 区域 格式化,结果为 "),s("code",[t._v("130 mph")]),t._v("。对数字值 "),s("code",[t._v("300")]),t._v(" 进行 "),s("code",[t._v("USD")]),t._v(" 作为 "),s("code",[t._v("currency")]),t._v(" 的 "),s("code",[t._v("en-US")]),t._v(" 区域格式化,结果为 "),s("code",[t._v("$300.00")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_127-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_127-输出什么"}},[t._v("#")]),t._v(" 127. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" spookyItems "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"👻"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🎃"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🕸"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("item")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" spookyItems"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("item")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"💀"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("spookyItems"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('["👻", "🎃", "🕸"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["👻", "🎃", "🕸", "💀"]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('["👻", "🎃", "🕸", { item: "💀" }]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('["👻", "🎃", "🕸", "[object Object]"]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-34"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-34"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v('通过解构对象们,我们可以从右手边的对象中拆出值,并且将拆出的值分配给左手边对象同名的属性。在这种情况下,我们将值 "💀" 分配给 '),s("code",[t._v("spookyItems[3]")]),t._v("。相当于我们正在篡改数组 "),s("code",[t._v("spookyItems")]),t._v(',我们给它添加了值 "💀"。当输出 '),s("code",[t._v("spookyItems")]),t._v(" 时,结果为 "),s("code",[t._v('["👻", "🎃", "🕸", "💀"]')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_128-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_128-输出什么"}},[t._v("#")]),t._v(" 128. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("isNaN")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("isNaN")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("isNaN")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("isNaN")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("age"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")]),t._v(" "),s("code",[t._v("false")]),t._v(" "),s("code",[t._v("true")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-39"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-39"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("通过方法 "),s("code",[t._v("Number.isNaN")]),t._v(",你可以检测你传递的值是否为 "),s("em",[t._v("数字值")]),t._v(" 并且是否等价于 "),s("code",[t._v("NaN")]),t._v("。"),s("code",[t._v("name")]),t._v(" 不是一个数字值,因此 "),s("code",[t._v("Number.isNaN(name)")]),t._v(" 返回 "),s("code",[t._v("false")]),t._v("。"),s("code",[t._v("age")]),t._v(" 是一个数字值,但它不等价于 "),s("code",[t._v("NaN")]),t._v(",因此 "),s("code",[t._v("Number.isNaN(age)")]),t._v(" 返回 "),s("code",[t._v("false")]),t._v(".")]),t._v(" "),s("p",[t._v("通过方法 "),s("code",[t._v("isNaN")]),t._v(",你可以检测你传递的值是否一个 number。"),s("code",[t._v("name")]),t._v(" 不是一个 "),s("code",[t._v("number")]),t._v(",因此 "),s("code",[t._v("isNaN(name)")]),t._v(" 返回 "),s("code",[t._v("true")]),t._v(". "),s("code",[t._v("age")]),t._v(" 是一个 "),s("code",[t._v("number")]),t._v(" 因此 "),s("code",[t._v("isNaN(age)")]),t._v(" 返回 "),s("code",[t._v("false")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_129-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_129-输出什么"}},[t._v("#")]),t._v(" 129. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" randomValue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getInfo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" randomValue"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" randomValue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getInfo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('"number"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('"string"')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-20"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-20"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("const")]),t._v(" 关键字声明的变量在被初始化之前不可被引用:这被称之为 "),s("em",[t._v("暂时性死区")]),t._v("。在函数 "),s("code",[t._v("getInfo")]),t._v(" 中,变量 "),s("code",[t._v("randomValue")]),t._v(" 声明在"),s("code",[t._v("getInfo")]),t._v(" 的作用域的此法环境中。在想要对 "),s("code",[t._v("typeof randomValue")]),t._v(" 进行 log 之前,变量 "),s("code",[t._v("randomValue")]),t._v(" 仍未被初始化:错误"),s("code",[t._v("ReferenceError")]),t._v(" 被抛出!JS 引擎并不会根据作用域链网上寻找该变量,因为我们已经在 "),s("code",[t._v("getInfo")]),t._v(" 函数中声明了 "),s("code",[t._v("randomValue")]),t._v(" 变量。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_130-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_130-输出什么"}},[t._v("#")]),t._v(" 130. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myPromise "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Woah some cool data"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("try")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" myPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("catch")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("throw")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token template-string"}},[s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v("Oops didn't work")]),s("span",{pre:!0,attrs:{class:"token template-punctuation string"}},[t._v("`")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("finally")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Oh finally!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Woah some cool data")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Oh finally!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Woah some cool data")]),t._v(" "),s("code",[t._v("Oh finally!")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Oops didn't work")]),t._v(" "),s("code",[t._v("Oh finally!")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-40"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-40"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("在 "),s("code",[t._v("try")]),t._v(" 块区,我们打印 "),s("code",[t._v("myPromise")]),t._v(" 变量的 awaited 值:"),s("code",[t._v('"Woah some cool data"')]),t._v("。因为"),s("code",[t._v("try")]),t._v(" 块区没有错误抛出,"),s("code",[t._v("catch")]),t._v(" 块区的代码并不执行。"),s("code",[t._v("finally")]),t._v(" 块区的代码 "),s("em",[t._v("总是")]),t._v(" 执行,"),s("code",[t._v('"Oh finally!"')]),t._v(" 被输出。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_131-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_131-输出什么"}},[t._v("#")]),t._v(" 131. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" emojis "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥑"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"✨"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍕"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍕"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("emojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("flat")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("['🥑', ['✨', '✨', ['🍕', '🍕']]]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("['🥑', '✨', '✨', ['🍕', '🍕']]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("['🥑', ['✨', '✨', '🍕', '🍕']]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("['🥑', '✨', '✨', '🍕', '🍕']")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-35"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-35"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("通过方法 "),s("code",[t._v("flat")]),t._v(",我们可以创建一个新的,已被扁平化的数组。被扁平化的深度取决于我们传递的值。在这个 case 里,我们传递了值 "),s("code",[t._v("1")]),t._v(" (并不必要,这是默认值),相当于只有第一层的数组才会被连接。即这个 case 里的 "),s("code",[t._v("['🥑']")]),t._v(" and "),s("code",[t._v("['✨', '✨', ['🍕', '🍕']]")]),t._v("。连接这两个数组得到结果 "),s("code",[t._v("['🥑', '✨', '✨', ['🍕', '🍕']]")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_132-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_132-输出什么"}},[t._v("#")]),t._v(" "),s("a",{attrs:{name:"20191224"}}),t._v("132. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" counterOne "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ncounterOne"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ncounterOne"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" counterTwo "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" counterOne"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ncounterTwo"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("counterOne"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("0")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("1")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("2")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("3")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-21"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-21"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("counterOne")]),t._v(" 是类 "),s("code",[t._v("Counter")]),t._v(" 的一个实例。类 Counter 包含一个"),s("code",[t._v("count")]),t._v(" 属性在它的构造函数里,和一个 "),s("code",[t._v("increment")]),t._v(" 方法。首先,我们通过 "),s("code",[t._v("counterOne.increment()")]),t._v(" 调用方法 "),s("code",[t._v("increment")]),t._v(" 两次。现在,"),s("code",[t._v("counterOne.count")]),t._v(" 为 "),s("code",[t._v("2")]),t._v(".")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/KxLlTm9.png",width:"400"}}),t._v(" "),s("p",[t._v("然后,我们创建一个新的变量 "),s("code",[t._v("counterTwo")]),t._v(" 并将 "),s("code",[t._v("counterOne")]),t._v(" 的引用地址赋值给它。因为对象受引用地址的影响,我们刚刚创建了一个新的对象,其引用地址和 "),s("code",[t._v("counterOne")]),t._v(" 的等价。因此它们指向同一块内存地址,任何对其的副作用都会影响 "),s("code",[t._v("counterTwo")]),t._v("。现在 "),s("code",[t._v("counterTwo.count")]),t._v(" 为 "),s("code",[t._v("2")]),t._v("。")]),t._v(" "),s("p",[t._v("我们调用 "),s("code",[t._v("counterTwo.increment()")]),t._v(" 将 "),s("code",[t._v("count")]),t._v(" 的值设为 "),s("code",[t._v("3")]),t._v("。然后,我们打印 "),s("code",[t._v("counterOne")]),t._v(" 里的 count,结果为 "),s("code",[t._v("3")]),t._v("。")]),t._v(" "),s("img",{attrs:{src:"https://i.imgur.com/BNBHXmc.png",width:"400"}}),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_133-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_133-输出什么"}},[t._v("#")]),t._v(" 133. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myPromise "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Promise!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("funcOne")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n myPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Timeout!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Last line!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("funcTwo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" res "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" myPromise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setTimeout")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Timeout!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Last line!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("funcOne")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("funcTwo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Promise! Last line! Promise! Last line! Last line! Promise!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Last line! Timeout! Promise! Last line! Timeout! Promise!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Promise! Last line! Last line! Promise! Timeout! Timeout!")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Last line! Promise! Promise! Last line! Timeout! Timeout!")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-22"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-22"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("首先,我们调用 "),s("code",[t._v("funcOne")]),t._v("。在函数 "),s("code",[t._v("funcOne")]),t._v(" 的第一行,我们调用"),s("code",[t._v("myPromise")]),t._v(" promise "),s("em",[t._v("异步操作")]),t._v("。当 JS 引擎在忙于执行 promise,它继续执行函数 "),s("code",[t._v("funcOne")]),t._v("。下一行 "),s("em",[t._v("异步操作")]),t._v(" "),s("code",[t._v("setTimeout")]),t._v(",其回调函数被 Web API 调用。 (详情请参考我关于 event loop 的文章.)")]),t._v(" "),s("p",[t._v("promise 和 timeout 都是异步操作,函数继续执行当 JS 引擎忙于执行 promise 和 处理 "),s("code",[t._v("setTimeout")]),t._v(" 的回调。相当于 "),s("code",[t._v("Last line!")]),t._v(" 首先被输出,因为它不是异步操作。执行完 "),s("code",[t._v("funcOne")]),t._v(" 的最后一行,promise 状态转变为 resolved,"),s("code",[t._v("Promise!")]),t._v(" 被打印。然而,因为我们调用了 "),s("code",[t._v("funcTwo()")]),t._v(",调用栈不为空,"),s("code",[t._v("setTimeout")]),t._v(" 的回调仍不能入栈。")]),t._v(" "),s("p",[t._v("我们现在处于 "),s("code",[t._v("funcTwo")]),t._v(",先 "),s("em",[t._v("awaiting")]),t._v(" myPromise。通过 "),s("code",[t._v("await")]),t._v(" 关键字,我们暂停了函数的执行直到 promise 状态变为 resolved (或 rejected)。然后,我们输出 "),s("code",[t._v("res")]),t._v(" 的 awaited 值(因为 promise 本身返回一个 promise)。接着输出 "),s("code",[t._v("Promise!")]),t._v("。")]),t._v(" "),s("p",[t._v("下一行就是 "),s("em",[t._v("异步操作")]),t._v(" "),s("code",[t._v("setTimeout")]),t._v(",其回调函数被 Web API 调用。")]),t._v(" "),s("p",[t._v("我们执行到函数 "),s("code",[t._v("funcTwo")]),t._v(" 的最后一行,输出 "),s("code",[t._v("Last line!")]),t._v("。现在,因为 "),s("code",[t._v("funcTwo")]),t._v(" 出栈,调用栈为空。在事件队列中等待的回调函数("),s("code",[t._v('() => console.log("Timeout!")')]),t._v(" from "),s("code",[t._v("funcOne")]),t._v(", and "),s("code",[t._v('() => console.log("Timeout!")')]),t._v(" from "),s("code",[t._v("funcTwo")]),t._v(")以此入栈。第一个回调输出 "),s("code",[t._v("Timeout!")]),t._v(",并出栈。然后,第二个回调输出 "),s("code",[t._v("Timeout!")]),t._v(",并出栈。得到结果 "),s("code",[t._v("Last line! Promise! Promise! Last line! Timeout! Timeout!")])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_134-我们怎样才能在-index-js-中调用-sum-js-中的-sum"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_134-我们怎样才能在-index-js-中调用-sum-js-中的-sum"}},[t._v("#")]),t._v(" 134. 我们怎样才能在 "),s("code",[t._v("index.js")]),t._v(" 中调用 "),s("code",[t._v("sum.js?")]),t._v(" 中的 "),s("code",[t._v("sum")]),t._v("?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// sum.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("default")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// index.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("as")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./sum"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("sum(4)")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("sum.sum(4)")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("sum.default(4)")])]),t._v(" "),s("li",[t._v("D: 默认导出不用 "),s("code",[t._v("*")]),t._v(" 来导入,只能具名导出")])]),t._v(" "),s("h4",{attrs:{id:"答案-c-41"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-41"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用符号 "),s("code",[t._v("*")]),t._v(",我们引入文件中的所有值,包括默认和具名。如果我们有以下文件:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// info.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" age "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("export")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("default")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I love JavaScript"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// index.js")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("as")]),t._v(" info "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("from")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"./info"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("info"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("p",[t._v("将会输出以下内容:")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("default")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I love JavaScript"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("以 "),s("code",[t._v("sum")]),t._v(" 为例,相当于以下形式引入值 "),s("code",[t._v("sum")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("default")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("sum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("我们可以通过调用 "),s("code",[t._v("sum.default")]),t._v(" 来调用该函数")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_135-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_135-输出什么"}},[t._v("#")]),t._v(" 135. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" handler "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("set")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Added a new property!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("get")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Accessed a property!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Proxy")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" handler"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nperson"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nperson"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("name"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("Added a new property!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Accessed a property!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("Added a new property!")]),t._v(" "),s("code",[t._v("Accessed a property!")])]),t._v(" "),s("li",[t._v("D: 没有任何输出")])]),t._v(" "),s("h4",{attrs:{id:"答案-c-42"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-42"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用 Proxy 对象,我们可以给一个对象添加自定义行为。在这个 case,我们传递一个包含以下属性的对象 "),s("code",[t._v("handler")]),t._v(" : "),s("code",[t._v("set")]),t._v(" and "),s("code",[t._v("get")]),t._v("。每当我们 "),s("em",[t._v("设置")]),t._v(" 属性值时 "),s("code",[t._v("set")]),t._v(" 被调用,每当我们 "),s("em",[t._v("获取")]),t._v(" 时 "),s("code",[t._v("get")]),t._v(" 被调用。")]),t._v(" "),s("p",[t._v("第一个参数是一个空对象 "),s("code",[t._v("{}")]),t._v(",作为 "),s("code",[t._v("person")]),t._v(" 的值。对于这个对象,自定义行为被定义在对象 "),s("code",[t._v("handler")]),t._v("。如果我们向对象 "),s("code",[t._v("person")]),t._v(" 添加属性,"),s("code",[t._v("set")]),t._v(" 将被调用。如果我们获取 "),s("code",[t._v("person")]),t._v(" 的属性,"),s("code",[t._v("get")]),t._v(" 将被调用。")]),t._v(" "),s("p",[t._v("首先,我们向 proxy 对象 ("),s("code",[t._v('person.name = "Lydia"')]),t._v(") 添加一个属性 "),s("code",[t._v("name")]),t._v("。"),s("code",[t._v("set")]),t._v(" 被调用并输出 "),s("code",[t._v('"Added a new property!"')]),t._v("。")]),t._v(" "),s("p",[t._v("然后,我们获取 proxy 对象的一个属性,对象 handler 的属性 "),s("code",[t._v("get")]),t._v(" 被调用。输出 "),s("code",[t._v('"Accessed a property!"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_136-以下哪一项会对对象-person-有副作用"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_136-以下哪一项会对对象-person-有副作用"}},[t._v("#")]),t._v(" 136. 以下哪一项会对对象 "),s("code",[t._v("person")]),t._v(" 有副作用?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nObject"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("seal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('person.name = "Evan Bacon"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("person.age = 21")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("delete person.name")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("Object.assign(person, { age: 21 })")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-37"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-37"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("使用 "),s("code",[t._v("Object.seal")]),t._v(" 我们可以防止新属性 "),s("em",[t._v("被添加")]),t._v(",或者存在属性 "),s("em",[t._v("被移除")]),t._v(".")]),t._v(" "),s("p",[t._v("然而,你仍然可以对存在属性进行更改。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_137-以下哪一项会对对象-person-有副作用"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_137-以下哪一项会对对象-person-有副作用"}},[t._v("#")]),t._v(" 137. 以下哪一项会对对象 "),s("code",[t._v("person")]),t._v(" 有副作用?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("address")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("street")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"100 Main St"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nObject"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("freeze")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('person.name = "Evan Bacon"')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("delete person.address")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('person.address.street = "101 Main St"')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('person.pet = { name: "Mara" }')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-43"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-43"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("使用方法 "),s("code",[t._v("Object.freeze")]),t._v(" 对一个对象进行 "),s("em",[t._v("冻结")]),t._v("。不能对属性进行添加,修改,删除。")]),t._v(" "),s("p",[t._v("然而,它仅 对对象进行 "),s("em",[t._v("浅")]),t._v(" 冻结,意味着只有 对象中的 "),s("em",[t._v("直接")]),t._v(" 属性被冻结。如果属性是另一个 object,像案例中的 "),s("code",[t._v("address")]),t._v(","),s("code",[t._v("address")]),t._v(" 中的属性没有被冻结,仍然可以被修改。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_138-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_138-输出什么"}},[t._v("#")]),t._v(" 138. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("add")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("x")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("num "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" value "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("add")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" value"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("myFunc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("4")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("6")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("NaN")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("NaN")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("Error")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("6")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("2")]),t._v(" "),s("code",[t._v("4")]),t._v(" and "),s("code",[t._v("3")]),t._v(" "),s("code",[t._v("Error")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-38"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-38"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("首先我们不传递任何参数调用 "),s("code",[t._v("myFunc()")]),t._v("。因为我们没有传递参数,"),s("code",[t._v("num")]),t._v(" 和 "),s("code",[t._v("value")]),t._v(" 获取它们各自的默认值:num 为 "),s("code",[t._v("2")]),t._v(",而 "),s("code",[t._v("value")]),t._v(" 为函数 "),s("code",[t._v("add")]),t._v(" 的返回值。对于函数 "),s("code",[t._v("add")]),t._v(",我们传递值为 2 的 "),s("code",[t._v("num")]),t._v(" 作为参数。函数 "),s("code",[t._v("add")]),t._v(" 返回 "),s("code",[t._v("4")]),t._v(" 作为 "),s("code",[t._v("value")]),t._v(" 的值。")]),t._v(" "),s("p",[t._v("然后,我们调用 "),s("code",[t._v("myFunc(3)")]),t._v(" 并传递值 "),s("code",[t._v("3")]),t._v(" 参数 "),s("code",[t._v("num")]),t._v(" 的值。我们没有给 "),s("code",[t._v("value")]),t._v(" 传递值。因为我们没有给参数 "),s("code",[t._v("value")]),t._v(" 传递值,它获取默认值:函数 "),s("code",[t._v("add")]),t._v(" 的返回值。对于函数 "),s("code",[t._v("add")]),t._v(",我们传递值为 3 的 "),s("code",[t._v("num")]),t._v("给它。函数 "),s("code",[t._v("add")]),t._v(" 返回 "),s("code",[t._v("6")]),t._v(" 作为 "),s("code",[t._v("value")]),t._v(" 的值。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_139-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_139-输出什么"}},[t._v("#")]),t._v(" 139. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n #number "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("#number"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getNum")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("#number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" counter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\ncounter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("#number"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("10")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("11")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("SyntaxError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-23"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-23"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[t._v("在 ES2020 中,通过 "),s("code",[t._v("#")]),t._v(" 我们可以给 class 添加私有变量。在 class 的外部我们无法获取该值。当我们尝试输出 "),s("code",[t._v("counter.#number")]),t._v(",语法错误被抛出:我们无法在 class "),s("code",[t._v("Counter")]),t._v(" 外部获取它!")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_140-选择哪一个"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_140-选择哪一个"}},[t._v("#")]),t._v(" 140. 选择哪一个?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" teams "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Team 1"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("members")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Paul"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lisa"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Team 2"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("members")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Laura"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Tim"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getMembers")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("members")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" members"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("yield")]),t._v(" members"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getTeams")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("teams")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" teams"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// ✨ SOMETHING IS MISSING HERE ✨")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" obj "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getTeams")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("teams"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nobj"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// { value: "Paul", done: false }')]),t._v("\nobj"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("next")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// { value: "Lisa", done: false }')]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("yield getMembers(teams[i].members)")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("yield* getMembers(teams[i].members)")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("return getMembers(teams[i].members)")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("return yield getMembers(teams[i].members)")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-36"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-36"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("为了遍历 "),s("code",[t._v("teams")]),t._v(" 数组中对象的属性 "),s("code",[t._v("members")]),t._v(" 中的每一项,我们需要将 "),s("code",[t._v("teams[i].members")]),t._v(" 传递给 Generator 函数 "),s("code",[t._v("getMembers")]),t._v("。Generator 函数返回一个 generator 对象。为了遍历这个 generator 对象中的每一项,我们需要使用 "),s("code",[t._v("yield*")]),t._v(".")]),t._v(" "),s("p",[t._v("如果我们没有写 "),s("code",[t._v("yield")]),t._v(","),s("code",[t._v("return yield")]),t._v(" 或者 "),s("code",[t._v("return")]),t._v(",整个 Generator 函数不会第一时间 return 当我们调用 "),s("code",[t._v("next")]),t._v(" 方法。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_141-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_141-输出什么"}},[t._v("#")]),t._v(" 141. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("hobbies")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"coding"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addHobby")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("hobby"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" hobbies "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("hobbies")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n hobbies"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("hobby"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" hobbies"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addHobby")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"running"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addHobby")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"dancing"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("addHobby")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"baking"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("hobbies"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("hobbies"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('["coding"]')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('["coding", "dancing"]')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('["coding", "dancing", "baking"]')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('["coding", "running", "dancing", "baking"]')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-44"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-44"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("函数 "),s("code",[t._v("addHobby")]),t._v(" 接受两个参数,"),s("code",[t._v("hobby")]),t._v(" 和有着对象 "),s("code",[t._v("person")]),t._v(" 中数组 "),s("code",[t._v("hobbies")]),t._v(" 默认值的 "),s("code",[t._v("hobbies")]),t._v("。")]),t._v(" "),s("p",[t._v("首相,我们调用函数 "),s("code",[t._v("addHobby")]),t._v(",并给 "),s("code",[t._v("hobby")]),t._v(" 传递 "),s("code",[t._v('"running"')]),t._v(" 以及给 "),s("code",[t._v("hobbies")]),t._v(" 传递一个空数组。因为我们给 "),s("code",[t._v("hobbies")]),t._v(" 传递了空数组,"),s("code",[t._v('"running"')]),t._v(" 被添加到这个空数组。")]),t._v(" "),s("p",[t._v("然后,我们调用函数 "),s("code",[t._v("addHobby")]),t._v(",并给 "),s("code",[t._v("hobby")]),t._v(" 传递 "),s("code",[t._v('"dancing"')]),t._v("。我们不向 "),s("code",[t._v("hobbies")]),t._v(" 传递值,因此它获取其默认值 —— 对象 "),s("code",[t._v("person")]),t._v(" 的 属性 "),s("code",[t._v("hobbies")]),t._v("。我们向数组 "),s("code",[t._v("person.hobbies")]),t._v(" push "),s("code",[t._v("dancing")]),t._v("。")]),t._v(" "),s("p",[t._v("最后,我们调用函数 "),s("code",[t._v("addHobby")]),t._v(",并向 "),s("code",[t._v("hobby")]),t._v(" 传递 值 "),s("code",[t._v('"baking"')]),t._v(",并且向 "),s("code",[t._v("hobbies")]),t._v(" 传递 "),s("code",[t._v("person.hobbies")]),t._v("。我们向数组 "),s("code",[t._v("person.hobbies")]),t._v(" push "),s("code",[t._v("dancing")]),t._v("。")]),t._v(" "),s("p",[t._v("pushing "),s("code",[t._v("dancing")]),t._v(" 和 "),s("code",[t._v("baking")]),t._v(" 之后,"),s("code",[t._v("person.hobbies")]),t._v(" 的值为 "),s("code",[t._v('["coding", "dancing", "baking"]')])]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_142-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_142-输出什么"}},[t._v("#")]),t._v(" 142. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Bird")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I\'m a bird. 🦢"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Flamingo")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("extends")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Bird")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"I\'m pink. 🌸"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" pet "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Flamingo")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("I'm pink. 🌸")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("I'm pink. 🌸")]),t._v(" "),s("code",[t._v("I'm a bird. 🦢")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("I'm a bird. 🦢")]),t._v(" "),s("code",[t._v("I'm pink. 🌸")])]),t._v(" "),s("li",[t._v("D: Nothing, we didn't call any method")])]),t._v(" "),s("h4",{attrs:{id:"答案-b-37"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-37"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("我们创建了类 "),s("code",[t._v("Flamingo")]),t._v(" 的实例 "),s("code",[t._v("pet")]),t._v("。当我们实例化这个实例,"),s("code",[t._v("Flamingo")]),t._v(" 中的 "),s("code",[t._v("constructor")]),t._v(" 被调用。首相,输出 "),s("code",[t._v('"I\'m pink. 🌸"')]),t._v(",之后我们调用"),s("code",[t._v("super()")]),t._v("。"),s("code",[t._v("super()")]),t._v(" 调用父类的构造函数,"),s("code",[t._v("Bird")]),t._v("。"),s("code",[t._v("Bird")]),t._v(" 的构造函数被调用,并输出 "),s("code",[t._v('"I\'m a bird. 🦢"')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_143-哪一个选项会导致报错"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_143-哪一个选项会导致报错"}},[t._v("#")]),t._v(" 143. 哪一个选项会导致报错?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" emojis "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🎄"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🎅🏼"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🎁"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"⭐"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 1 */")]),t._v(" emojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("push")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🦌"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 2 */")]),t._v(" emojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("splice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 3 */")]),t._v(" emojis "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("emojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🥂"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* 4 */")]),t._v(" emojis"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 1")]),t._v(" "),s("li",[t._v("B: 1 and 2")]),t._v(" "),s("li",[t._v("C: 3 and 4")]),t._v(" "),s("li",[t._v("D: 3")])]),t._v(" "),s("h4",{attrs:{id:"答案-d-24"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-24"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("const")]),t._v(" 关键字意味着我们不能 "),s("em",[t._v("重定义")]),t._v(" 变量中的值,它 "),s("em",[t._v("仅可读")]),t._v("。然而,值本身不可修改。数组 "),s("code",[t._v("emojis")]),t._v(" 中的值可被修改,如 push 新的值,拼接,又或者将数组的长度设置为 0。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_144-我们需要向对象-person-添加什么-以致执行-person-时获得形如-lydia-hallie-21-的输出"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_144-我们需要向对象-person-添加什么-以致执行-person-时获得形如-lydia-hallie-21-的输出"}},[t._v("#")]),t._v(" 144. 我们需要向对象 "),s("code",[t._v("person")]),t._v(" 添加什么,以致执行 "),s("code",[t._v("[...person]")]),t._v(" 时获得形如 "),s("code",[t._v('["Lydia Hallie", 21]')]),t._v(" 的输出?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" person "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia Hallie"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("age")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("21")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("person"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// ["Lydia Hallie", 21]')]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 不需要,对象默认就是可迭代的")]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("*[Symbol.iterator]() { for (let x in this) yield* this[x] }")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("*[Symbol.iterator]() { yield* Object.values(this) }")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("*[Symbol.iterator]() { for (let x in this) yield this }")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-45"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-45"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("对象默认并不是可迭代的。如果迭代规则被定义,则一个对象是可迭代的(An iterable is an iterable if the iterator protocol is present)。我们可以通过添加迭代器 symbol "),s("code",[t._v("[Symbol.iterator]")]),t._v(" 来定义迭代规则,其返回一个 generator 对象,比如说构建一个 generator 函数 "),s("code",[t._v("*[Symbol.iterator]() {}")]),t._v("。如果我们想要返回数组 "),s("code",[t._v('["Lydia Hallie", 21]')]),t._v(": "),s("code",[t._v("yield* Object.values(this)")]),t._v(",这个 generator 函数一定要 yield 对象 "),s("code",[t._v("person")]),t._v(" 的"),s("code",[t._v("Object.values")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_145-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_145-输出什么"}},[t._v("#")]),t._v(" 145. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" nums "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nnums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("forEach")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("num")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("num"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: 1")]),t._v(" "),s("li",[t._v("B: 2")]),t._v(" "),s("li",[t._v("C: 3")]),t._v(" "),s("li",[t._v("D: 4\n")])]),t._v(" "),s("h4",{attrs:{id:"答案-c-46"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-46"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("在 "),s("code",[t._v("forEach")]),t._v(" 循环内部的 "),s("code",[t._v("if")]),t._v(" 会判断 "),s("code",[t._v("num")]),t._v(" 的值是 truthy 或者是 falsy。因为 "),s("code",[t._v("nums")]),t._v(" 数组的第一个数字是 "),s("code",[t._v("0")]),t._v(",一个 falsy 值,"),s("code",[t._v("if")]),t._v(" 语句代码块不会被执行。"),s("code",[t._v("count")]),t._v(" 仅仅在 "),s("code",[t._v("nums")]),t._v(" 数组的其他 3 个数字 "),s("code",[t._v("1")]),t._v(","),s("code",[t._v("2")]),t._v(","),s("code",[t._v("3")]),t._v(" 时加 1。因为 "),s("code",[t._v("count")]),t._v(" 执行了 3 次加 "),s("code",[t._v("1")]),t._v(" 运算,所以 "),s("code",[t._v("count")]),t._v(" 的值为 "),s("code",[t._v("3")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_146-输出是什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_146-输出是什么"}},[t._v("#")]),t._v(" 146. 输出是什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFruit")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("fruits")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("fruits"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?.")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFruit")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍊"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍌"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍍"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFruit")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("getFruit")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍍"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍊"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍌"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("null")]),t._v(", "),s("code",[t._v("undefined")]),t._v(", 🍌")]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[]")]),t._v(", "),s("code",[t._v("null")]),t._v(", 🍌")]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[]")]),t._v(", "),s("code",[t._v("[]")]),t._v(", 🍌")]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")]),t._v(", "),s("code",[t._v("undefined")]),t._v(", 🍌")])]),t._v(" "),s("h4",{attrs:{id:"答案-d-25"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-25"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("?")]),t._v(" 允许我们去选择性地访问对象内部更深层的嵌套属性。我们尝试打印 "),s("code",[t._v("fruits")]),t._v(" 数组索引值为 "),s("code",[t._v("1")]),t._v(" 的子数组内部的索引值为 "),s("code",[t._v("1")]),t._v(" 的元素。如果在 "),s("code",[t._v("fruits")]),t._v(" 数组索引值 为 "),s("code",[t._v("1")]),t._v(" 的位置不存在元素,会直接返回 "),s("code",[t._v("undefined")]),t._v("。如果 "),s("code",[t._v("fruits")]),t._v(" 数组在索引值为 "),s("code",[t._v("1")]),t._v(" 的位置存在元素,但是子数组在索引值为 "),s("code",[t._v("1")]),t._v(" 的位置不存在元素,也会返回 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("首先,我们尝试打印 "),s("code",[t._v("[['🍊', '🍌'], ['🍍']]")]),t._v(" 的子数组 "),s("code",[t._v("['🍍']")]),t._v(" 的第 2 个元素。这个子数组只包含一个元素,也就意味着在索引值为 "),s("code",[t._v("1")]),t._v(" 的位置不存在元素,所以返回的是 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("其次,我们在没有传入任何参数调用了 "),s("code",[t._v("getFruits")]),t._v(" 函数,也就意味着形参 "),s("code",[t._v("fruits")]),t._v(" 的默认值为"),s("code",[t._v("undefined")]),t._v("。因为我们选择性地链接了 "),s("code",[t._v("fruits")]),t._v(" 在索引值为 "),s("code",[t._v("1")]),t._v(" 的元素,因为在索引值为 "),s("code",[t._v("1")]),t._v(" 的位置不存在元素,因此返回的是 "),s("code",[t._v("undefined")]),t._v("。")]),t._v(" "),s("p",[t._v("最后,我们尝试打印 "),s("code",[t._v("['🍍'], ['🍊', '🍌']")]),t._v(" 的子数组 "),s("code",[t._v("['🍊', '🍌']")]),t._v(" 的第 2 个元素。子数组索引值为 "),s("code",[t._v("1")]),t._v("的位置为 "),s("code",[t._v("🍌")]),t._v(",因此它被打印出了。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_147-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_147-输出什么"}},[t._v("#")]),t._v(" 147. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Calc")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("constructor")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increase")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" calc "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Calc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Calc")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("increase")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("calc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("0")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("1")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-39"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-39"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[t._v("我们设置 "),s("code",[t._v("calc")]),t._v(" 变量为 "),s("code",[t._v("Calc")]),t._v(" 类的一个新实例。然后,我们初始化一个 "),s("code",[t._v("Calc")]),t._v(" 的新实例,而且调用了这个实例的 "),s("code",[t._v("increase")]),t._v(" 方法。因为 count 属性是在 "),s("code",[t._v("Calc")]),t._v(" class 的 constructor 内部的,所以 count 属性不会在 "),s("code",[t._v("Calc")]),t._v(" 的原型链上共享出去。这就意味着 calc 实例的 count 值不会被更新,count 仍然是 "),s("code",[t._v("0")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_148-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_148-输出什么"}},[t._v("#")]),t._v(" 148. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" user "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("email")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"e@mail.com"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("password")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"12345"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("updateUser")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" password "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n Object"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("assign")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" email "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("password"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("password "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" password"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" updatedUser "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("updateUser")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("email")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"new@email.com"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("updatedUser "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("false")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("true")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-38"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-38"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("updateUser")]),t._v(" 函数更新 user 的 "),s("code",[t._v("email")]),t._v(" 和 "),s("code",[t._v("password")]),t._v(" 属性的值,如果它们的值传入函数,函数返回的就是 "),s("code",[t._v("user")]),t._v(" 对象。"),s("code",[t._v("updateUser")]),t._v(" 函数的返回值是 "),s("code",[t._v("user")]),t._v(" 对象,意味着 updatedUser 的值与 "),s("code",[t._v("user")]),t._v(" 指向的是同一个 "),s("code",[t._v("user")]),t._v(" 对象。"),s("code",[t._v("updatedUser === user")]),t._v(" 为 "),s("code",[t._v("true")]),t._v(".")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_149-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_149-输出什么"}},[t._v("#")]),t._v(" 149. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" fruit "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍌"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍊"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍎"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nfruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("slice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nfruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("splice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nfruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("unshift")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🍇"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("fruit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("['🍌', '🍊', '🍎']")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("['🍊', '🍎']")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("['🍇', '🍊', '🍎']")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("['🍇', '🍌', '🍊', '🍎']")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-47"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-47"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[t._v("首先,我们在 fruit 数组上调用 "),s("code",[t._v("slice")]),t._v(" 方法。slice 方法不会修改原始数组,但是会返回从数组切片下来的值:香蕉 emoji。\n其次,我们在 fruit 数组上调用 "),s("code",[t._v("splice")]),t._v(" 方法。splice 方法会修改原始数组,也就意味着 fruit 数组此时为 "),s("code",[t._v("['🍊', '🍎']")]),t._v("。\n最后,我们在 fruit 数组上调用 "),s("code",[t._v("unshift")]),t._v(" 方法,通过添加一个值的方式改变了原始数组,添加的是'🍇',它成为了数组的第一个元素。现在 fruit 数组的组成为 "),s("code",[t._v("['🍇', '🍊', '🍎']")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_150-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_150-输出什么"}},[t._v("#")]),t._v(" 150. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" animals "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" dog "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("emoji")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🐶"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" cat "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("emoji")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"🐈"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nanimals"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("dog"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("dog"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Mara"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nanimals"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("cat"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("...")]),t._v("cat"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Sara"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("animals"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("dog"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ emoji: "🐶", name: "Mara" }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ emoji: "🐈", name: "Sara" }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-39"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-39"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[t._v("对象的键会被转换为字符串。")]),t._v(" "),s("p",[t._v("因为 "),s("code",[t._v("dog")]),t._v(" 的值是一个对象,"),s("code",[t._v("animals[dog]")]),t._v(" 实际上意味着我们创建了一个叫做 "),s("code",[t._v('"object Object"')]),t._v(" 的属性来代表新的对象。"),s("code",[t._v('animals["object Object"]')]),t._v(" 现在等于 "),s("code",[t._v('{ emoji: "🐶", name: "Mara"}')]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v("cat")]),t._v(" 也是一个对象,"),s("code",[t._v("animals[cat]")]),t._v(" 实际上意味着我们在用新的 cat 的属性覆盖 "),s("code",[t._v('animals[``"``object Object``"``]')]),t._v(" 的值。")]),t._v(" "),s("p",[t._v("打印 "),s("code",[t._v("animals[dog]")]),t._v(",实际上是"),s("code",[t._v('animals["object Object"]')]),t._v(",这是因为转化"),s("code",[t._v("dog")]),t._v("对象为一个字符串结果 "),s("code",[t._v('"object Object"')]),t._v(",所以返回 "),s("code",[t._v('{ emoji: "🐈", name: "Sara" }')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_151-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_151-输出什么"}},[t._v("#")]),t._v(" 151. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" user "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("email")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"my@email.com"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("updateEmail")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("email")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("email "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nuser"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("updateEmail")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"new@email.com"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("my@email.com")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("new@email.com")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("undefined")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("ReferenceError")])])]),t._v(" "),s("h4",{attrs:{id:"答案-a-40"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-a-40"}},[t._v("#")]),t._v(" 答案:A")]),t._v(" "),s("p",[s("code",[t._v("updateEmail")]),t._v(" 函数是一个箭头函数,它没有和 "),s("code",[t._v("user")]),t._v(" 对象绑定。这就意味着 "),s("code",[t._v("this")]),t._v(" 关键字不会引用到 "),s("code",[t._v("user")]),t._v(" 对象,但是会引用到全局对象。"),s("code",[t._v("user")]),t._v(" 对象内部的 "),s("code",[t._v("email")]),t._v(" 的值不会更新。当打印 "),s("code",[t._v("user.email")]),t._v(" 的时候,原始值 "),s("code",[t._v("my@email.com")]),t._v(" 被返回。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_152-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_152-输出什么"}},[t._v("#")]),t._v(" 152. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" promise1 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"First"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" promise2 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Second"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" promise3 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reject")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Third"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" promise4 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("resolve")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Fourth"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("runPromises")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" res1 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("all")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("promise1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" promise2"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" res2 "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" Promise"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("all")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("promise3"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" promise4"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("res1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" res2"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("runPromises")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("then")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("res")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("catch")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("err")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("[['First', 'Second'], ['Fourth']]")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("[['First', 'Second'], ['Third', 'Fourth']]")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("[['First', 'Second']]")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("'Third'")])])]),t._v(" "),s("h4",{attrs:{id:"答案-d-26"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-d-26"}},[t._v("#")]),t._v(" 答案:D")]),t._v(" "),s("p",[s("code",[t._v("Promise.all")]),t._v(" 方法可以并行式运行 promise。如果其中一个 promise 失败了,"),s("code",[t._v("Promise.all")]),t._v(" 方法会带上被 reject 的 promise 的值"),s("em",[t._v("rejects")]),t._v("。在这个例子中,"),s("code",[t._v("promise3")]),t._v(" 带着 "),s("code",[t._v('"Third"')]),t._v(" 值 reject。我们在调用 "),s("code",[t._v("runPromises")]),t._v(" 时在 "),s("code",[t._v("runPromises")]),t._v(" 函数内部的 "),s("code",[t._v("catch")]),t._v(" 方法去捕获任意 error 从而捕获到被 reject 的值。因为 "),s("code",[t._v("promise3")]),t._v(" 带着 "),s("code",[t._v('"Third"')]),t._v(" 被 reject,所以只有 "),s("code",[t._v('"Third"')]),t._v(" 打印。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_153-哪个作为method的值可以打印-name-lydia-age-22"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_153-哪个作为method的值可以打印-name-lydia-age-22"}},[t._v("#")]),t._v(" 153. 哪个作为"),s("code",[t._v("method")]),t._v("的值可以打印"),s("code",[t._v('{ name: "Lydia", age: 22 }')]),t._v("?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" keys "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"name"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"age"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" values "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("22")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" method "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* ?? */")]),t._v("\n Object"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("method"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n keys"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("map")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("_"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" i")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("keys"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" values"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// { name: "Lydia", age: 22 }')]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("entries")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("values")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("fromEntries")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("forEach")])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-48"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-48"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("fromEntries")]),t._v(" 方法可以将二维数组转换为对象。在每个子数组的第一个元素是 key,在每个子数组的第二个元素是 value。在这个例子中,我们映射了 "),s("code",[t._v("keys")]),t._v(" 数组,它返回了一个数组,数组的第一个元素为 keys 数组当前索引的值,第二个元素为 values 数组当前索引的值。")]),t._v(" "),s("p",[t._v("这样就创建了一个包含正确 keys 和 values 的子数组的数组,因此结果为"),s("code",[t._v('{ name: "Lydia", age: 22 }')]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_154-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_154-输出什么"}},[t._v("#")]),t._v(" 154. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("createMember")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" address "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" validEmail "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token regex"}},[s("span",{pre:!0,attrs:{class:"token regex-delimiter"}},[t._v("/")]),s("span",{pre:!0,attrs:{class:"token regex-source language-regex"}},[t._v(".+\\@.+\\..+")]),s("span",{pre:!0,attrs:{class:"token regex-delimiter"}},[t._v("/")])]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),t._v("validEmail"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("throw")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Error")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Valid email pls"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n email"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("address")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" address "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("?")]),t._v(" address "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("null")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" member "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("createMember")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("email")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"my@email.com"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nconsole"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("member"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v('{ email: "my@email.com", address: null }')])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v('{ email: "my@email.com" }')])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v('{ email: "my@email.com", address: {} }')])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v('{ email: "my@email.com", address: undefined }')])])]),t._v(" "),s("h4",{attrs:{id:"答案-c-49"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-c-49"}},[t._v("#")]),t._v(" 答案:C")]),t._v(" "),s("p",[s("code",[t._v("address")]),t._v(" 的默认值是一个空对象 "),s("code",[t._v("{}")]),t._v("。当我们设置 "),s("code",[t._v("member")]),t._v(" 变量为 "),s("code",[t._v("createMember")]),t._v(" 函数返回的对象,我们没有为 address 参数传值,意味着 address 的值为默认的空对象 "),s("code",[t._v("{}")]),t._v("。一个空对象是一个 truthy 值,意味着 "),s("code",[t._v("address ? address : null")]),t._v(" 条件会返回 "),s("code",[t._v("true")]),t._v("。address 的值为空对象 "),s("code",[t._v("{}")]),t._v("。")]),t._v(" "),s("hr"),t._v(" "),s("h6",{attrs:{id:"_155-输出什么"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_155-输出什么"}},[t._v("#")]),t._v(" 155. 输出什么?")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" randomValue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token literal-property property"}},[t._v("name")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Lydia"')]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\nrandomValue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("23")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("typeof")]),t._v(" randomValue "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"string"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"It\'s not a string!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("else")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n console"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("log")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Yay it\'s a string!"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("ul",[s("li",[t._v("A: "),s("code",[t._v("It's not a string!")])]),t._v(" "),s("li",[t._v("B: "),s("code",[t._v("Yay it's a string!")])]),t._v(" "),s("li",[t._v("C: "),s("code",[t._v("TypeError")])]),t._v(" "),s("li",[t._v("D: "),s("code",[t._v("undefined")])])]),t._v(" "),s("h4",{attrs:{id:"答案-b-40"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#答案-b-40"}},[t._v("#")]),t._v(" 答案:B")]),t._v(" "),s("p",[s("code",[t._v("if")]),t._v(" 语句的条件判断 "),s("code",[t._v("!typeof randomValue")]),t._v(" 的值是否等于 "),s("code",[t._v('"string"')]),t._v("。"),s("code",[t._v("!")]),t._v(" 操作符将这个值转化为一个布尔值。如果值是 truthy 的话,返回值会是 "),s("code",[t._v("false")]),t._v(",如果值是 falsy,返回值会是 "),s("code",[t._v("true")]),t._v("。在这里,"),s("code",[t._v("typeof randomValue")]),t._v(" 的返回值是一个 truthy 值 "),s("code",[t._v('"number"')]),t._v(",意味着 "),s("code",[t._v("!typeof randomValue")]),t._v(" 的值是一个布尔值 "),s("code",[t._v("false")]),t._v("。")]),t._v(" "),s("p",[s("code",[t._v('!typeof randomValue === "string"')]),t._v(" 总是返回 false,因为我们实际上是在执行 "),s("code",[t._v('false === "string"')]),t._v("。因为条件返回的是 "),s("code",[t._v("false")]),t._v(",所以 "),s("code",[t._v("else")]),t._v(" 语句中的代码块会被运行,因此打印 "),s("code",[t._v("Yay it's a string!")]),t._v("。")])])}),[],!1,null,null,null);s.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/70.3bcafc1f.js b/assets/js/70.3bcafc1f.js new file mode 100644 index 0000000000..0595bd9919 --- /dev/null +++ b/assets/js/70.3bcafc1f.js @@ -0,0 +1 @@ +(window.webpackJsonp=window.webpackJsonp||[]).push([[70],{508:function(t,a,s){"use strict";s.r(a);var n=s(30),e=Object(n.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"_48-rotate-image"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_48-rotate-image"}},[t._v("#")]),t._v(" "),a("a",{attrs:{href:"https://leetcode.com/problems/rotate-image/",target:"_blank",rel:"noopener noreferrer"}},[t._v("48. Rotate Image"),a("OutboundLink")],1)]),t._v(" "),a("h2",{attrs:{id:"题目"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#题目"}},[t._v("#")]),t._v(" 题目")]),t._v(" "),a("p",[t._v("You are given an "),a("em",[t._v("n")]),t._v(" x "),a("em",[t._v("n")]),t._v(" 2D matrix representing an image.")]),t._v(" "),a("p",[t._v("Rotate the image by 90 degrees (clockwise).")]),t._v(" "),a("p",[a("strong",[t._v("Note")]),t._v(":")]),t._v(" "),a("p",[t._v("You have to rotate the image "),a("strong",[a("a",{attrs:{href:"https://en.wikipedia.org/wiki/In-place_algorithm",target:"_blank",rel:"noopener noreferrer"}},[t._v("in-place"),a("OutboundLink")],1)]),t._v(", which means you have to modify the input 2D matrix directly. "),a("strong",[t._v("DO NOT")]),t._v(" allocate another 2D matrix and do the rotation.")]),t._v(" "),a("p",[a("strong",[t._v("Example 1")]),t._v(":")]),t._v(" "),a("p",[a("img",{attrs:{src:"https://assets.leetcode.com/uploads/2020/08/28/mat1.jpg",alt:""}})]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",[a("code",[t._v("Given input matrix = \n[\n [1,2,3],\n [4,5,6],\n [7,8,9]\n],\n\nrotate the input matrix in-place such that it becomes:\n[\n [7,4,1],\n [8,5,2],\n [9,6,3]\n]\n")])])]),a("p",[a("strong",[t._v("Example 2")]),t._v(":")]),t._v(" "),a("p",[a("img",{attrs:{src:"https://assets.leetcode.com/uploads/2020/08/28/mat2.jpg",alt:""}})]),t._v(" "),a("div",{staticClass:"language- extra-class"},[a("pre",[a("code",[t._v("Given input matrix =\n[\n [ 5, 1, 9,11],\n [ 2, 4, 8,10],\n [13, 3, 6, 7],\n [15,14,12,16]\n], \n\nrotate the input matrix in-place such that it becomes:\n[\n [15,13, 2, 5],\n [14, 3, 4, 1],\n [12, 6, 8, 9],\n [16, 7,10,11]\n]\n")])])]),a("h2",{attrs:{id:"题目大意"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#题目大意"}},[t._v("#")]),t._v(" 题目大意")]),t._v(" "),a("p",[t._v("给定一个 n × n 的二维矩阵表示一个图像。将图像顺时针旋转 90 度。说明:你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要使用另一个矩阵来旋转图像。")]),t._v(" "),a("h2",{attrs:{id:"解题思路"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#解题思路"}},[t._v("#")]),t._v(" 解题思路")]),t._v(" "),a("ul",[a("li",[t._v("给出一个二维数组,要求顺时针旋转 90 度,这一题比较简单;")]),t._v(" "),a("li",[t._v("这里给出 2 种旋转方法的实现,顺时针旋转和逆时针旋转;")]),t._v(" "),a("li",[t._v("顺时针旋转:先将二维数组上下翻转,然后将二维数组沿对角线交换;")]),t._v(" "),a("li",[t._v("逆时针旋转:先将二维数组左右翻转,然后将二维数组沿对角线交换;")])]),t._v(" "),a("div",{staticClass:"language-javascript extra-class"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/*\n * clockwise rotate 顺时针旋转\n * first reverse up to down, then swap the symmetry \n * 1 2 3 7 8 9 7 4 1\n * 4 5 6 => 4 5 6 => 8 5 2\n * 7 8 9 1 2 3 9 6 3\n*/")]),t._v("\n\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/*\n * anticlockwise rotate 逆时针旋转\n * first reverse left to right, then swap the symmetry\n * 1 2 3 3 2 1 3 6 9\n * 4 5 6 => 6 5 4 => 2 5 8\n * 7 8 9 9 8 7 1 4 7\n*/")]),t._v("\n")])])]),a("h2",{attrs:{id:"代码"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#代码"}},[t._v("#")]),t._v(" 代码")]),t._v(" "),a("div",{staticClass:"language-javascript extra-class"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/**\n * @param {number[][]} matrix\n * @return {void} Do not return anything, modify matrix in-place instead.\n */")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("rotate")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("matrix")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" len "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length\n "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 上下翻转")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 此处要注意:只能针对一半的行数翻转")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 否则翻转两遍等于没变")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" len "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" j "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" len"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" temp "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n matrix"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("len "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n matrix"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("len "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" temp\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 沿对角线翻转")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 此处要注意:只能对左下角或者右上角的一半数据做翻转")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 否则翻转两遍等于没变")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" len"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" j "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" i "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" len"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" temp "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n matrix"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n matrix"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" temp\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])])])}),[],!1,null,null,null);a.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/70.f226e9bd.js b/assets/js/70.f226e9bd.js deleted file mode 100644 index 25993f811a..0000000000 --- a/assets/js/70.f226e9bd.js +++ /dev/null @@ -1 +0,0 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[70],{508:function(t,s,a){"use strict";a.r(s);var n=a(30),r=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"_48-rotate-image"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_48-rotate-image"}},[t._v("#")]),t._v(" "),s("a",{attrs:{href:"https://leetcode.com/problems/rotate-image/",target:"_blank",rel:"noopener noreferrer"}},[t._v("48. Rotate Image"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"题目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目"}},[t._v("#")]),t._v(" 题目")]),t._v(" "),s("p",[t._v("You are given an "),s("em",[t._v("n")]),t._v(" x "),s("em",[t._v("n")]),t._v(" 2D matrix representing an image.")]),t._v(" "),s("p",[t._v("Rotate the image by 90 degrees (clockwise).")]),t._v(" "),s("p",[s("strong",[t._v("Note")]),t._v(":")]),t._v(" "),s("p",[t._v("You have to rotate the image "),s("strong",[s("a",{attrs:{href:"https://en.wikipedia.org/wiki/In-place_algorithm",target:"_blank",rel:"noopener noreferrer"}},[t._v("in-place"),s("OutboundLink")],1)]),t._v(", which means you have to modify the input 2D matrix directly. "),s("strong",[t._v("DO NOT")]),t._v(" allocate another 2D matrix and do the rotation.")]),t._v(" "),s("p",[s("strong",[t._v("Example 1")]),t._v(":")]),t._v(" "),s("p",[s("img",{attrs:{src:"https://assets.leetcode.com/uploads/2020/08/28/mat1.jpg",alt:""}})]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",[s("code",[t._v("Given input matrix = \n[\n [1,2,3],\n [4,5,6],\n [7,8,9]\n],\n\nrotate the input matrix in-place such that it becomes:\n[\n [7,4,1],\n [8,5,2],\n [9,6,3]\n]\n")])])]),s("p",[s("strong",[t._v("Example 2")]),t._v(":")]),t._v(" "),s("p",[s("img",{attrs:{src:"https://assets.leetcode.com/uploads/2020/08/28/mat2.jpg",alt:""}})]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",[s("code",[t._v("Given input matrix =\n[\n [ 5, 1, 9,11],\n [ 2, 4, 8,10],\n [13, 3, 6, 7],\n [15,14,12,16]\n], \n\nrotate the input matrix in-place such that it becomes:\n[\n [15,13, 2, 5],\n [14, 3, 4, 1],\n [12, 6, 8, 9],\n [16, 7,10,11]\n]\n")])])]),s("h2",{attrs:{id:"题目大意"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目大意"}},[t._v("#")]),t._v(" 题目大意")]),t._v(" "),s("p",[t._v("给定一个 n × n 的二维矩阵表示一个图像。将图像顺时针旋转 90 度。说明:你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要使用另一个矩阵来旋转图像。")]),t._v(" "),s("h2",{attrs:{id:"解题思路"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#解题思路"}},[t._v("#")]),t._v(" 解题思路")]),t._v(" "),s("ul",[s("li",[t._v("给出一个二维数组,要求顺时针旋转 90 度。")]),t._v(" "),s("li",[t._v("这一题比较简单,按照题意做就可以。这里给出 2 种旋转方法的实现,顺时针旋转和逆时针旋转。")])]),t._v(" "),s("div",{staticClass:"language-c extra-class"},[s("pre",{pre:!0,attrs:{class:"language-c"}},[s("code",[t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/*\n * clockwise rotate 顺时针旋转\n * first reverse up to down, then swap the symmetry \n * 1 2 3 7 8 9 7 4 1\n * 4 5 6 => 4 5 6 => 8 5 2\n * 7 8 9 1 2 3 9 6 3\n */")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("rotate")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("vector"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("vector"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reverse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("begin")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("end")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("swap")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n \n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/*\n * anticlockwise rotate 逆时针旋转\n * first reverse left to right, then swap the symmetry\n * 1 2 3 3 2 1 3 6 9\n * 4 5 6 => 6 5 4 => 2 5 8\n * 7 8 9 9 8 7 1 4 7\n */")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("anti_rotate")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("vector"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("vector"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("auto")]),t._v(" vi "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reverse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("vi"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("begin")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" vi"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("end")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("size")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("swap")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n \n")])])]),s("h2",{attrs:{id:"代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#代码"}},[t._v("#")]),t._v(" 代码")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" leetcode\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 解法一")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("rotate")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tlength "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// rotate by diagonal 对角线变换")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" length"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" length"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tmatrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// rotate by vertical centerline 竖直轴对称翻转")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" length"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" length"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tmatrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("length"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("length"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 解法二")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("rotate1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tn "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/* rotate clock-wise = 1. transpose matrix => 2. reverse(matrix[i])\n\n\t1 2 3 4 1 5 9 13 13 9 5 1\n\t5 6 7 8 => 2 6 10 14 => 14 10 6 2\n\t9 10 11 12 3 7 11 15 15 11 7 3\n\t13 14 15 16 4 8 12 16 16 12 8 4\n\n\t*/")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// transpose, i=rows, j=columns")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// j = i+1, coz diagonal elements didn't change in a square matrix")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("swap")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// reverse each row of the image")]),t._v("\n\t\tmatrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reverse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// swap changes original slice's i,j position")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("swap")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("nums "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tnums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" nums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" nums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" nums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// reverses a row of image, matrix[i]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("reverse")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("nums "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" lp"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" rp "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("nums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" lp "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" rp "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tnums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("lp"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" nums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("rp"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" nums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("rp"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" nums"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("lp"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\t\tlp"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\trp"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" nums\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/71.4be81573.js b/assets/js/71.4be81573.js deleted file mode 100644 index 2d3eee22f3..0000000000 --- a/assets/js/71.4be81573.js +++ /dev/null @@ -1 +0,0 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[71],{509:function(t,s,a){"use strict";a.r(s);var n=a(30),r=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"_54-spiral-matrix"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_54-spiral-matrix"}},[t._v("#")]),t._v(" "),s("a",{attrs:{href:"https://leetcode.com/problems/spiral-matrix/",target:"_blank",rel:"noopener noreferrer"}},[t._v("54. Spiral Matrix"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"题目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目"}},[t._v("#")]),t._v(" 题目")]),t._v(" "),s("p",[t._v("Given a matrix of "),s("em",[t._v("m")]),t._v(" x "),s("em",[t._v("n")]),t._v(" elements ("),s("em",[t._v("m")]),t._v(" rows, "),s("em",[t._v("n")]),t._v(" columns), return all elements of the matrix in spiral order.")]),t._v(" "),s("p",[s("strong",[t._v("Example 1")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",[s("code",[t._v("Input:\n[\n [ 1, 2, 3 ],\n [ 4, 5, 6 ],\n [ 7, 8, 9 ]\n]\nOutput: [1,2,3,6,9,8,7,4,5]\n")])])]),s("p",[s("strong",[t._v("Example 2")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",[s("code",[t._v("Input:\n[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9,10,11,12]\n]\nOutput: [1,2,3,4,8,12,11,10,9,5,6,7]\n")])])]),s("h2",{attrs:{id:"题目大意"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目大意"}},[t._v("#")]),t._v(" 题目大意")]),t._v(" "),s("p",[t._v("给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。")]),t._v(" "),s("h2",{attrs:{id:"解题思路"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#解题思路"}},[t._v("#")]),t._v(" 解题思路")]),t._v(" "),s("ul",[s("li",[t._v("给出一个二维数组,按照螺旋的方式输出")]),t._v(" "),s("li",[t._v("解法一:需要注意的是特殊情况,比如二维数组退化成一维或者一列或者一个元素。注意了这些情况,基本就可以一次通过了。")]),t._v(" "),s("li",[t._v("解法二:提前算出一共多少个元素,一圈一圈地遍历矩阵,停止条件就是遍历了所有元素(count == sum)")])]),t._v(" "),s("h2",{attrs:{id:"代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#代码"}},[t._v("#")]),t._v(" 代码")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" leetcode\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 解法 1")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("spiralOrder")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tres "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tres "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("append")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" res\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tres "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("append")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" res\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tvisit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" round"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" spDir "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 朝右")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 朝下")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 朝左")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 朝上")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tvisit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tvisit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("\n\tres "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("append")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" spDir"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("round"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("%")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\t\ty "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" spDir"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("round"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("%")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tround"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" res\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tvisit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("\n\t\t\tres "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("append")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("switch")]),t._v(" round "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("%")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("case")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tround"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("continue")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("case")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tround"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("continue")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("case")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tround"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("continue")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("case")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tround"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("continue")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" res\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 解法 2")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("spiralOrder2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tm "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" m "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tn "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// top、left、right、bottom 分别是剩余区域的上、左、右、下的下标")]),t._v("\n\ttop"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" left"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" bottom"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" right "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" \n\tcount"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("n\n\tres "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 外层循环每次遍历一圈")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\ti"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" top"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" left\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" right "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tres "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("append")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tcount"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\tj"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\ti"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" top "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" right\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" bottom "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tres "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("append")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tcount"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\ti"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\ti"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" bottom"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" right "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">=")]),t._v(" left "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tres "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("append")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tcount"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\tj"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\ti"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" bottom "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" left\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" top "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" sum "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tres "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("append")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tcount"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\ti"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 进入到下一层")]),t._v("\n\t\ttop"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" left"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" bottom"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" right "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" top"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" left"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" bottom"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" right"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" res\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/71.627d9732.js b/assets/js/71.627d9732.js new file mode 100644 index 0000000000..c57b69336c --- /dev/null +++ b/assets/js/71.627d9732.js @@ -0,0 +1 @@ +(window.webpackJsonp=window.webpackJsonp||[]).push([[71],{509:function(t,s,a){"use strict";a.r(s);var n=a(30),r=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"_54-spiral-matrix"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_54-spiral-matrix"}},[t._v("#")]),t._v(" "),s("a",{attrs:{href:"https://leetcode.com/problems/spiral-matrix/",target:"_blank",rel:"noopener noreferrer"}},[t._v("54. Spiral Matrix"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"题目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目"}},[t._v("#")]),t._v(" 题目")]),t._v(" "),s("p",[t._v("Given a matrix of "),s("em",[t._v("m")]),t._v(" x "),s("em",[t._v("n")]),t._v(" elements ("),s("em",[t._v("m")]),t._v(" rows, "),s("em",[t._v("n")]),t._v(" columns), return all elements of the matrix in spiral order.")]),t._v(" "),s("p",[s("strong",[t._v("Example 1")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",[s("code",[t._v("Input:\n[\n [ 1, 2, 3 ],\n [ 4, 5, 6 ],\n [ 7, 8, 9 ]\n]\nOutput: [1,2,3,6,9,8,7,4,5]\n")])])]),s("p",[s("strong",[t._v("Example 2")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",[s("code",[t._v("Input:\n[\n [1, 2, 3, 4],\n [5, 6, 7, 8],\n [9,10,11,12]\n]\nOutput: [1,2,3,4,8,12,11,10,9,5,6,7]\n")])])]),s("h2",{attrs:{id:"题目大意"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目大意"}},[t._v("#")]),t._v(" 题目大意")]),t._v(" "),s("p",[t._v("给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。")]),t._v(" "),s("h2",{attrs:{id:"解题思路"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#解题思路"}},[t._v("#")]),t._v(" 解题思路")]),t._v(" "),s("ul",[s("li",[t._v("给出一个二维数组,按照螺旋的方式输出;")]),t._v(" "),s("li",[t._v("用四个指针控制每次上、下、左、右的边,然后按照逆时针的顺序从边界上依次访问元素;")]),t._v(" "),s("li",[t._v("当访问完当前边界之后,要更新一下边界位置,缩小范围,方便下一轮进行访问;")]),t._v(" "),s("li",[t._v("注意由于输入的数组 "),s("code",[t._v("matrix")]),t._v(" 是 "),s("code",[t._v("m * n")]),t._v(" 的矩阵,m 不一定等于 n,所以在螺旋遍历时可能出现多遍历了行或者列,返回时需要删除 "),s("code",[t._v("res")]),t._v(" 中多余的数: "),s("code",[t._v("res.slice(0, m * n)")]),t._v(";")])]),t._v(" "),s("h2",{attrs:{id:"代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#代码"}},[t._v("#")]),t._v(" 代码")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/**\n * @param {number[][]} matrix\n * @return {number[]}\n */")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("spiralOrder")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("matrix")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" m "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" res "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" left "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" right "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" top "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" bottom "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" m "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("while")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" m "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" left"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" right"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("top"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n top"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" top"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" bottom"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("right"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n right"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" right"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">=")]),t._v(" left"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("bottom"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n bottom"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" bottom"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">=")]),t._v(" top"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("left"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n left"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("slice")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" m "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/72.4836d96e.js b/assets/js/72.4836d96e.js deleted file mode 100644 index 918668e37a..0000000000 --- a/assets/js/72.4836d96e.js +++ /dev/null @@ -1 +0,0 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[72],{510:function(t,s,a){"use strict";a.r(s);var n=a(30),r=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"_59-spiral-matrix-ii"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_59-spiral-matrix-ii"}},[t._v("#")]),t._v(" "),s("a",{attrs:{href:"https://leetcode.com/problems/spiral-matrix-ii/",target:"_blank",rel:"noopener noreferrer"}},[t._v("59. Spiral Matrix II"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"题目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目"}},[t._v("#")]),t._v(" 题目")]),t._v(" "),s("p",[t._v("Given a positive integer "),s("em",[t._v("n")]),t._v(", generate a square matrix filled with elements from 1 to "),s("em",[t._v("n")]),t._v("2 in spiral order.")]),t._v(" "),s("p",[s("strong",[t._v("Example")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",[s("code",[t._v("Input: 3\nOutput:\n[\n [ 1, 2, 3 ],\n [ 8, 9, 4 ],\n [ 7, 6, 5 ]\n]\n")])])]),s("h2",{attrs:{id:"题目大意"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目大意"}},[t._v("#")]),t._v(" 题目大意")]),t._v(" "),s("p",[t._v("给定一个正整数 n,生成一个包含 1 到 n^2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵。")]),t._v(" "),s("h2",{attrs:{id:"解题思路"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#解题思路"}},[t._v("#")]),t._v(" 解题思路")]),t._v(" "),s("ul",[s("li",[t._v("给出一个数组 n,要求输出一个 n * n 的二维数组,里面元素是 1 - n*n,且数组排列顺序是螺旋排列的")]),t._v(" "),s("li",[t._v("这一题是第 54 题的加强版,没有需要注意的特殊情况,直接模拟即可。")])]),t._v(" "),s("h2",{attrs:{id:"代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#代码"}},[t._v("#")]),t._v(" 代码")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" leetcode\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generateMatrix")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("n "),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tres"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" round"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" spDir "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 朝右")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 朝下")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 朝左")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 朝上")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tvisit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tres"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("make")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tvisit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("\n\tres"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" spDir"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("round"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("%")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\t\ty "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" spDir"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("round"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("%")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tround"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" x "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" y "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" res\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tvisit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("\n\t\t\tres"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("switch")]),t._v(" round "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("%")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("case")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tround"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("continue")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("case")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tround"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("continue")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("case")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" y"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tround"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("continue")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("case")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" x"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&&")]),t._v(" visit"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("x"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("y"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tround"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("\n\t\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("continue")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" res\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n")])])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/72.61ee7a07.js b/assets/js/72.61ee7a07.js new file mode 100644 index 0000000000..020179c9ac --- /dev/null +++ b/assets/js/72.61ee7a07.js @@ -0,0 +1 @@ +(window.webpackJsonp=window.webpackJsonp||[]).push([[72],{510:function(t,s,a){"use strict";a.r(s);var n=a(30),r=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"_59-spiral-matrix-ii"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_59-spiral-matrix-ii"}},[t._v("#")]),t._v(" "),s("a",{attrs:{href:"https://leetcode.com/problems/spiral-matrix-ii/",target:"_blank",rel:"noopener noreferrer"}},[t._v("59. Spiral Matrix II"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"题目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目"}},[t._v("#")]),t._v(" 题目")]),t._v(" "),s("p",[t._v("Given a positive integer "),s("em",[t._v("n")]),t._v(", generate a square matrix filled with elements from 1 to "),s("em",[t._v("n")]),t._v("2 in spiral order.")]),t._v(" "),s("p",[s("strong",[t._v("Example")]),t._v(":")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",[s("code",[t._v("Input: 3\nOutput:\n[\n [ 1, 2, 3 ],\n [ 8, 9, 4 ],\n [ 7, 6, 5 ]\n]\n")])])]),s("h2",{attrs:{id:"题目大意"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目大意"}},[t._v("#")]),t._v(" 题目大意")]),t._v(" "),s("p",[t._v("给定一个正整数 n,生成一个包含 1 到 n^2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵。")]),t._v(" "),s("h2",{attrs:{id:"解题思路"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#解题思路"}},[t._v("#")]),t._v(" 解题思路")]),t._v(" "),s("ul",[s("li",[t._v("给出一个数组 n,要求输出一个 n * n 的二维数组,里面元素是 1 - n*n,且数组排列顺序是螺旋排列的;")]),t._v(" "),s("li",[t._v("这一题是第 54 题的加强版,没有需要注意的特殊情况,直接模拟即可;")]),t._v(" "),s("li",[t._v("用四个指针控制每次上、下、左、右的边,然后按照逆时针的顺序从边界上依次访问元素;")]),t._v(" "),s("li",[t._v("当访问完当前边界之后,要更新一下边界位置,缩小范围,方便下一轮进行访问;")]),t._v(" "),s("li",[t._v("注意初始化 "),s("code",[t._v("res")]),t._v(" 时不能直接 "),s("code",[t._v("new Array(n).fill([])")]),t._v(",因为JS中将数组作为参数时,传递的是引用,而不是 "),s("code",[t._v("value")]),t._v(";")])]),t._v(" "),s("h2",{attrs:{id:"代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#代码"}},[t._v("#")]),t._v(" 代码")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/**\n * @param {number} n\n * @return {number[][]}\n */")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("generateMatrix")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("n")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" left "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" right "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" top "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" bottom "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" res "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Array")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("fill")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("map")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=>")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Array")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("while")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 在上边界向右扫描")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" left"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" right"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("top"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 缩小上边界")]),t._v("\n top"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 在右边界向下扫描")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" top"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<=")]),t._v(" bottom"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("right"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 缩小右边界")]),t._v("\n right"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 在下边界向左扫描")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" right"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">=")]),t._v(" left"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("bottom"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 缩小下边界")]),t._v("\n bottom"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 在左边界向上扫描")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" bottom"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">=")]),t._v(" top"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("--")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n count"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("left"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 缩小左边界")]),t._v("\n left"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" res"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/77.a1b4142c.js b/assets/js/77.a1b4142c.js deleted file mode 100644 index c8bc2fd674..0000000000 --- a/assets/js/77.a1b4142c.js +++ /dev/null @@ -1 +0,0 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[77],{515:function(t,s,a){"use strict";a.r(s);var n=a(30),r=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"_73-set-matrix-zeroes"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_73-set-matrix-zeroes"}},[t._v("#")]),t._v(" "),s("a",{attrs:{href:"https://leetcode.com/problems/set-matrix-zeroes/",target:"_blank",rel:"noopener noreferrer"}},[t._v("73. Set Matrix Zeroes"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"题目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目"}},[t._v("#")]),t._v(" 题目")]),t._v(" "),s("p",[t._v("Given an *"),s("code",[t._v("m* x *n*")]),t._v(" matrix. If an element is "),s("strong",[t._v("0")]),t._v(", set its entire row and column to "),s("strong",[t._v("0")]),t._v(". Do it "),s("strong",[s("a",{attrs:{href:"https://en.wikipedia.org/wiki/In-place_algorithm",target:"_blank",rel:"noopener noreferrer"}},[t._v("in-place"),s("OutboundLink")],1)]),t._v(".")]),t._v(" "),s("p",[s("strong",[t._v("Follow up:")])]),t._v(" "),s("ul",[s("li",[t._v("A straight forward solution using O("),s("em",[t._v("mn")]),t._v(") space is probably a bad idea.")]),t._v(" "),s("li",[t._v("A simple improvement uses O("),s("em",[t._v("m")]),t._v(" + "),s("em",[t._v("n")]),t._v(") space, but still not the best solution.")]),t._v(" "),s("li",[t._v("Could you devise a constant space solution?")])]),t._v(" "),s("p",[s("strong",[t._v("Example 1:")])]),t._v(" "),s("p",[s("img",{attrs:{src:"https://assets.leetcode.com/uploads/2020/08/17/mat1.jpg",alt:"https://assets.leetcode.com/uploads/2020/08/17/mat1.jpg"}})]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",[t._v("Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]")]),t._v(" "),s("p",[t._v("Output: [[1,0,1],[0,0,0],[1,0,1]]")])]),t._v(" "),s("p",[s("strong",[t._v("Example 2:")])]),t._v(" "),s("p",[s("img",{attrs:{src:"https://assets.leetcode.com/uploads/2020/08/17/mat2.jpg",alt:"https://assets.leetcode.com/uploads/2020/08/17/mat2.jpg"}})]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",[t._v("Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]")]),t._v(" "),s("p",[t._v("Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]")])]),t._v(" "),s("p",[s("strong",[t._v("Constraints:")])]),t._v(" "),s("ul",[s("li",[s("code",[t._v("m == matrix.length")])]),t._v(" "),s("li",[s("code",[t._v("n == matrix[0].length")])]),t._v(" "),s("li",[s("code",[t._v("1 <= m, n <= 200")])]),t._v(" "),s("li",[s("code",[t._v("2^31 <= matrix[i][j] <= 2^31 - 1")])])]),t._v(" "),s("h2",{attrs:{id:"题目大意"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目大意"}},[t._v("#")]),t._v(" 题目大意")]),t._v(" "),s("p",[t._v("给定一个 "),s("code",[t._v("m x n")]),t._v(" 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0。请使用原地算法。")]),t._v(" "),s("h2",{attrs:{id:"解题思路"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#解题思路"}},[t._v("#")]),t._v(" 解题思路")]),t._v(" "),s("ul",[s("li",[t._v("此题考查对程序的控制能力,无算法思想。题目要求采用原地的算法,所有修改即在原二维数组上进行。在二维数组中有 2 个特殊位置,一个是第一行,一个是第一列。它们的特殊性在于,它们之间只要有一个 0,它们都会变为全 0 。先用 2 个变量记录这一行和这一列中是否有 0,防止之后的修改覆盖了这 2 个地方。然后除去这一行和这一列以外的部分判断是否有 0,如果有 0,将它们所在的行第一个元素标记为 0,所在列的第一个元素标记为 0 。最后通过标记,将对应的行列置 0 即可。")])]),t._v(" "),s("h2",{attrs:{id:"代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#代码"}},[t._v("#")]),t._v(" 代码")]),t._v(" "),s("div",{staticClass:"language-go extra-class"},[s("pre",{pre:!0,attrs:{class:"language-go"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("package")]),t._v(" leetcode\n\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("setZeroes")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token builtin"}},[t._v("int")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("||")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\tisFirstRowExistZero"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" isFirstColExistZero "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tisFirstColExistZero "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("break")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tisFirstRowExistZero "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("break")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tmatrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v("\n\t\t\t\tmatrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 处理[1:]行全部置 0")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tmatrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 处理[1:]列全部置 0")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("==")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\t\tmatrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v("\n\t\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" isFirstRowExistZero "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tmatrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" isFirstColExistZero "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("len")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tmatrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),t._v("\n\t\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/77.a4a2a77e.js b/assets/js/77.a4a2a77e.js new file mode 100644 index 0000000000..d80c668e7c --- /dev/null +++ b/assets/js/77.a4a2a77e.js @@ -0,0 +1 @@ +(window.webpackJsonp=window.webpackJsonp||[]).push([[77],{515:function(t,s,a){"use strict";a.r(s);var n=a(30),r=Object(n.a)({},(function(){var t=this,s=t._self._c;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"_73-set-matrix-zeroes"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_73-set-matrix-zeroes"}},[t._v("#")]),t._v(" "),s("a",{attrs:{href:"https://leetcode.com/problems/set-matrix-zeroes/",target:"_blank",rel:"noopener noreferrer"}},[t._v("73. Set Matrix Zeroes"),s("OutboundLink")],1)]),t._v(" "),s("h2",{attrs:{id:"题目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目"}},[t._v("#")]),t._v(" 题目")]),t._v(" "),s("p",[t._v("Given an *"),s("code",[t._v("m* x *n*")]),t._v(" matrix. If an element is "),s("strong",[t._v("0")]),t._v(", set its entire row and column to "),s("strong",[t._v("0")]),t._v(". Do it "),s("strong",[s("a",{attrs:{href:"https://en.wikipedia.org/wiki/In-place_algorithm",target:"_blank",rel:"noopener noreferrer"}},[t._v("in-place"),s("OutboundLink")],1)]),t._v(".")]),t._v(" "),s("p",[s("strong",[t._v("Follow up:")])]),t._v(" "),s("ul",[s("li",[t._v("A straight forward solution using O("),s("em",[t._v("mn")]),t._v(") space is probably a bad idea.")]),t._v(" "),s("li",[t._v("A simple improvement uses O("),s("em",[t._v("m")]),t._v(" + "),s("em",[t._v("n")]),t._v(") space, but still not the best solution.")]),t._v(" "),s("li",[t._v("Could you devise a constant space solution?")])]),t._v(" "),s("p",[s("strong",[t._v("Example 1:")])]),t._v(" "),s("p",[s("img",{attrs:{src:"https://assets.leetcode.com/uploads/2020/08/17/mat1.jpg",alt:"https://assets.leetcode.com/uploads/2020/08/17/mat1.jpg"}})]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",[t._v("Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]")]),t._v(" "),s("p",[t._v("Output: [[1,0,1],[0,0,0],[1,0,1]]")])]),t._v(" "),s("p",[s("strong",[t._v("Example 2:")])]),t._v(" "),s("p",[s("img",{attrs:{src:"https://assets.leetcode.com/uploads/2020/08/17/mat2.jpg",alt:"https://assets.leetcode.com/uploads/2020/08/17/mat2.jpg"}})]),t._v(" "),s("div",{staticClass:"custom-block tip"},[s("p",[t._v("Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]")]),t._v(" "),s("p",[t._v("Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]")])]),t._v(" "),s("p",[s("strong",[t._v("Constraints:")])]),t._v(" "),s("ul",[s("li",[s("code",[t._v("m == matrix.length")])]),t._v(" "),s("li",[s("code",[t._v("n == matrix[0].length")])]),t._v(" "),s("li",[s("code",[t._v("1 <= m, n <= 200")])]),t._v(" "),s("li",[s("code",[t._v("2^31 <= matrix[i][j] <= 2^31 - 1")])])]),t._v(" "),s("h2",{attrs:{id:"题目大意"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#题目大意"}},[t._v("#")]),t._v(" 题目大意")]),t._v(" "),s("p",[t._v("给定一个 "),s("code",[t._v("m x n")]),t._v(" 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0。请使用原地算法。")]),t._v(" "),s("h2",{attrs:{id:"解题思路"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#解题思路"}},[t._v("#")]),t._v(" 解题思路")]),t._v(" "),s("ul",[s("li",[t._v("此题考查对程序的控制能力,无算法思想;")]),t._v(" "),s("li",[t._v("题目要求采用原地的算法,所有修改即在原二维数组上进行;")]),t._v(" "),s("li",[t._v("在二维数组中有 2 个特殊位置,一个是第一行,一个是第一列,先用 2 个变量记录这一行和这一列中是否有 0,防止之后的修改覆盖了这 2 个地方;")]),t._v(" "),s("li",[t._v("然后除去这一行和这一列以外的部分判断是否有 0,如果有 0,将它们所在的行第一个元素和所在列的第一个元素标记为 0 ;")]),t._v(" "),s("li",[t._v("最后通过标记,将对应的行列置 0 即可。")])]),t._v(" "),s("h2",{attrs:{id:"代码"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#代码"}},[t._v("#")]),t._v(" 代码")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("/**\n * @param {number[][]} matrix\n * @return {void} Do not return anything, modify matrix in-place instead.\n */")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("var")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("setZeroes")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("matrix")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" m "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" n "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("length"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" first_row_has_zero "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" first_line_has_zero "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n \n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 第一列是否有 0")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n first_row_has_zero "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("break")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 第一行是否有 0")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n first_line_has_zero "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("break")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 除第一行、第一列外,其他地方有 0,则将列首和行首置为 0")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 遍历第一列,有 0 则将整行置为 0")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 遍历第一行,有 0 则将整列置为 0")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("===")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 若第一列原本有 0,则将第一列都置为 0")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("first_row_has_zero"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" m"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" i"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("i"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 若第一行原本有 0,则将第一行都置为 0")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("first_line_has_zero"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("for")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v(" n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" j"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n matrix"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("j"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n")])])])])}),[],!1,null,null,null);s.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/87.79d5ddce.js b/assets/js/87.b80a6ef8.js similarity index 62% rename from assets/js/87.79d5ddce.js rename to assets/js/87.b80a6ef8.js index e3bd7cdc63..0efe449f46 100644 --- a/assets/js/87.79d5ddce.js +++ b/assets/js/87.b80a6ef8.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[87],{525:function(t,a,s){"use strict";s.r(a);var e=s(30),r=Object(e.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"_259-3sum-smaller"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_259-3sum-smaller"}},[t._v("#")]),t._v(" "),a("a",{attrs:{href:"https://leetcode.com/problems/3sum-smaller/",target:"_blank",rel:"noopener noreferrer"}},[t._v("259. 3Sum Smaller"),a("OutboundLink")],1)]),t._v(" "),a("h3",{attrs:{id:"题目"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#题目"}},[t._v("#")]),t._v(" 题目")]),t._v(" "),a("p",[t._v("Given an array of n integers nums and a target, find the number of index triplets "),a("code",[t._v("i, j, k")]),t._v(" with "),a("code",[t._v("0 <= i < j < k < n")]),t._v(" that satisfy the condition "),a("code",[t._v("nums[i] + nums[j] + nums[k] < target")]),t._v(".")]),t._v(" "),a("p",[a("strong",[t._v("Example:")])]),t._v(" "),a("div",{staticClass:"custom-block tip"},[a("p",[t._v("Input: nums = [-2,0,1,3], and target = 2")]),t._v(" "),a("p",[t._v("Output: 2")])]),t._v(" "),a("p",[t._v("Explanation:")]),t._v(" "),a("p",[t._v("Because there are two triplets which sums are less than 2: "),a("code",[t._v("[-2,0,1]")]),t._v("、"),a("code",[t._v("[-2,0,3]")])]),t._v(" "),a("p",[t._v("Follow up: Could you solve it in O(n2) runtime?")]),t._v(" "),a("h3",{attrs:{id:"题目大意"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#题目大意"}},[t._v("#")]),t._v(" 题目大意")]),t._v(" "),a("p",[t._v("给定一个数组 nums,要求返回三数之和小于一个目标值的情况的个数。")]),t._v(" "),a("h3",{attrs:{id:"解题思路"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#解题思路"}},[t._v("#")]),t._v(" 解题思路")]),t._v(" "),a("p",[t._v("这道题是 3Sum 问题的一个变形,")]),t._v(" "),a("h3",{attrs:{id:"代码"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#代码"}},[t._v("#")]),t._v(" 代码")]),t._v(" "),a("div",{staticClass:"language-javascript extra-class"},[a("pre",{pre:!0,attrs:{class:"language-javascript"}},[a("code",[t._v("\n")])])])])}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[87],{525:function(t,a,s){"use strict";s.r(a);var e=s(30),r=Object(e.a)({},(function(){var t=this,a=t._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"_259-3sum-smaller"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#_259-3sum-smaller"}},[t._v("#")]),t._v(" "),a("a",{attrs:{href:"https://leetcode.com/problems/3sum-smaller/",target:"_blank",rel:"noopener noreferrer"}},[t._v("259. 3Sum Smaller"),a("OutboundLink")],1)]),t._v(" "),a("h3",{attrs:{id:"题目"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#题目"}},[t._v("#")]),t._v(" 题目")]),t._v(" "),a("p",[t._v("Given an array of n integers nums and a target, find the number of index triplets "),a("code",[t._v("i, j, k")]),t._v(" with "),a("code",[t._v("0 <= i < j < k < n")]),t._v(" that satisfy the condition "),a("code",[t._v("nums[i] + nums[j] + nums[k] < target")]),t._v(".")]),t._v(" "),a("p",[a("strong",[t._v("Example:")])]),t._v(" "),a("div",{staticClass:"custom-block tip"},[a("p",[t._v("Input: nums = [-2,0,1,3], and target = 2")]),t._v(" "),a("p",[t._v("Output: 2")])]),t._v(" "),a("p",[t._v("Explanation:")]),t._v(" "),a("p",[t._v("Because there are two triplets which sums are less than 2: "),a("code",[t._v("[-2,0,1]")]),t._v("、"),a("code",[t._v("[-2,0,3]")])]),t._v(" "),a("p",[t._v("Follow up: Could you solve it in O(n^2) runtime?")]),t._v(" "),a("h3",{attrs:{id:"题目大意"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#题目大意"}},[t._v("#")]),t._v(" 题目大意")]),t._v(" "),a("p",[t._v("给定一个数组 nums,要求返回三数之和小于一个目标值的情况的个数。")]),t._v(" "),a("h3",{attrs:{id:"解题思路"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#解题思路"}},[t._v("#")]),t._v(" 解题思路")]),t._v(" "),a("p",[t._v("这道题是 3Sum 问题的一个变形,")]),t._v(" "),a("h3",{attrs:{id:"代码"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#代码"}},[t._v("#")]),t._v(" 代码")]),t._v(" "),a("div",{staticClass:"language-gojavascript extra-class"},[a("pre",{pre:!0,attrs:{class:"language-text"}},[a("code",[t._v("\n")])])])])}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/app.53d1ecaf.js b/assets/js/app.bddd4a5c.js similarity index 88% rename from assets/js/app.53d1ecaf.js rename to assets/js/app.bddd4a5c.js index 81a44ef627..ecf77fe817 100644 --- a/assets/js/app.53d1ecaf.js +++ b/assets/js/app.bddd4a5c.js @@ -1,19 +1,19 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[0],[]]);!function(e){function t(t){for(var i,a,s=t[0],l=t[1],u=t[2],d=0,h=[];d=0&&Math.floor(t)===t&&isFinite(e)}function m(e){return a(e)&&"function"==typeof e.then&&"function"==typeof e.catch}function v(e){return null==e?"":Array.isArray(e)||h(e)&&e.toString===d?JSON.stringify(e,null,2):String(e)}function g(e){var t=parseFloat(e);return isNaN(t)?e:t}function b(e,t){for(var n=Object.create(null),i=e.split(","),r=0;r-1)return e.splice(i,1)}}var x=Object.prototype.hasOwnProperty;function w(e,t){return x.call(e,t)}function C(e){var t=Object.create(null);return function(n){return t[n]||(t[n]=e(n))}}var k=/-(\w)/g,S=C((function(e){return e.replace(k,(function(e,t){return t?t.toUpperCase():""}))})),O=C((function(e){return e.charAt(0).toUpperCase()+e.slice(1)})),E=/\B([A-Z])/g,$=C((function(e){return e.replace(E,"-$1").toLowerCase()}));var D=Function.prototype.bind?function(e,t){return e.bind(t)}:function(e,t){function n(n){var i=arguments.length;return i?i>1?e.apply(t,arguments):e.call(t,n):e.call(t)}return n._length=e.length,n};function T(e,t){t=t||0;for(var n=e.length-t,i=new Array(n);n--;)i[n]=e[n+t];return i}function P(e,t){for(var n in t)e[n]=t[n];return e}function M(e){for(var t={},n=0;n0,J=G&&G.indexOf("edge/")>0;G&&G.indexOf("android");var Q=G&&/iphone|ipad|ipod|ios/.test(G);G&&/chrome\/\d+/.test(G),G&&/phantomjs/.test(G);var ee,te=G&&G.match(/firefox\/(\d+)/),ne={}.watch,ie=!1;if(K)try{var re={};Object.defineProperty(re,"passive",{get:function(){ie=!0}}),window.addEventListener("test-passive",null,re)}catch(e){}var oe=function(){return void 0===ee&&(ee=!K&&"undefined"!=typeof global&&(global.process&&"server"===global.process.env.VUE_ENV)),ee},ae=K&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__;function se(e){return"function"==typeof e&&/native code/.test(e.toString())}var le,ue="undefined"!=typeof Symbol&&se(Symbol)&&"undefined"!=typeof Reflect&&se(Reflect.ownKeys);le="undefined"!=typeof Set&&se(Set)?Set:function(){function e(){this.set=Object.create(null)}return e.prototype.has=function(e){return!0===this.set[e]},e.prototype.add=function(e){this.set[e]=!0},e.prototype.clear=function(){this.set=Object.create(null)},e}();var ce=null;function de(){return ce&&{proxy:ce}}function he(e){void 0===e&&(e=null),e||ce&&ce._scope.off(),ce=e,e&&e._scope.on()}var fe=function(){function e(e,t,n,i,r,o,a,s){this.tag=e,this.data=t,this.children=n,this.text=i,this.elm=r,this.ns=void 0,this.context=o,this.fnContext=void 0,this.fnOptions=void 0,this.fnScopeId=void 0,this.key=t&&t.key,this.componentOptions=a,this.componentInstance=void 0,this.parent=void 0,this.raw=!1,this.isStatic=!1,this.isRootInsert=!0,this.isComment=!1,this.isCloned=!1,this.isOnce=!1,this.asyncFactory=s,this.asyncMeta=void 0,this.isAsyncPlaceholder=!1}return Object.defineProperty(e.prototype,"child",{get:function(){return this.componentInstance},enumerable:!1,configurable:!0}),e}(),pe=function(e){void 0===e&&(e="");var t=new fe;return t.text=e,t.isComment=!0,t};function me(e){return new fe(void 0,void 0,void 0,String(e))}function ve(e){var t=new fe(e.tag,e.data,e.children&&e.children.slice(),e.text,e.elm,e.context,e.componentOptions,e.asyncFactory);return t.ns=e.ns,t.isStatic=e.isStatic,t.key=e.key,t.isComment=e.isComment,t.fnContext=e.fnContext,t.fnOptions=e.fnOptions,t.fnScopeId=e.fnScopeId,t.asyncMeta=e.asyncMeta,t.isCloned=!0,t}var ge=0,be=[],ye=function(){function e(){this._pending=!1,this.id=ge++,this.subs=[]}return e.prototype.addSub=function(e){this.subs.push(e)},e.prototype.removeSub=function(e){this.subs[this.subs.indexOf(e)]=null,this._pending||(this._pending=!0,be.push(this))},e.prototype.depend=function(t){e.target&&e.target.addDep(this)},e.prototype.notify=function(e){var t=this.subs.filter((function(e){return e}));for(var n=0,i=t.length;n1)return n&&u(t)?t.call(i):t}else 0}var kt=C((function(e){var t="&"===e.charAt(0),n="~"===(e=t?e.slice(1):e).charAt(0),i="!"===(e=n?e.slice(1):e).charAt(0);return{name:e=i?e.slice(1):e,once:n,capture:i,passive:t}}));function St(e,t){function n(){var e=n.fns;if(!r(e))return pn(e,null,arguments,t,"v-on handler");for(var i=e.slice(),o=0;o0&&(Tt((u=e(u,"".concat(n||"","_").concat(i)))[0])&&Tt(d)&&(h[c]=me(d.text+u[0].text),u.shift()),h.push.apply(h,u)):l(u)?Tt(d)?h[c]=me(d.text+u):""!==u&&h.push(me(u)):Tt(u)&&Tt(d)?h[c]=me(d.text+u.text):(s(t._isVList)&&a(u.tag)&&o(u.key)&&a(n)&&(u.key="__vlist".concat(n,"_").concat(i,"__")),h.push(u)));return h}(e):void 0}function Tt(e){return a(e)&&a(e.text)&&!1===e.isComment}function Pt(e,t){var n,i,o,s,l=null;if(r(e)||"string"==typeof e)for(l=new Array(e.length),n=0,i=e.length;n0,s=t?!!t.$stable:!a,l=t&&t.$key;if(t){if(t._normalized)return t._normalized;if(s&&r&&r!==i&&l===r.$key&&!a&&!r.$hasNormal)return r;for(var u in o={},t)t[u]&&"$"!==u[0]&&(o[u]=Xt(e,n,u,t[u]))}else o={};for(var c in n)c in o||(o[c]=Zt(n,c));return t&&Object.isExtensible(t)&&(t._normalized=o),W(o,"$stable",s),W(o,"$key",l),W(o,"$hasNormal",a),o}function Xt(e,t,n,i){var o=function(){var t=ce;he(e);var n=arguments.length?i.apply(null,arguments):i({}),o=(n=n&&"object"==typeof n&&!r(n)?[n]:Dt(n))&&n[0];return he(t),n&&(!o||1===n.length&&o.isComment&&!Kt(o))?void 0:n};return i.proxy&&Object.defineProperty(t,n,{get:o,enumerable:!0,configurable:!0}),o}function Zt(e,t){return function(){return e[t]}}function Jt(e){return{get attrs(){if(!e._attrsProxy){var t=e._attrsProxy={};W(t,"_v_attr_proxy",!0),Qt(t,e.$attrs,i,e,"$attrs")}return e._attrsProxy},get listeners(){e._listenersProxy||Qt(e._listenersProxy={},e.$listeners,i,e,"$listeners");return e._listenersProxy},get slots(){return function(e){e._slotsProxy||tn(e._slotsProxy={},e.$scopedSlots);return e._slotsProxy}(e)},emit:D(e.$emit,e),expose:function(t){t&&Object.keys(t).forEach((function(n){return Je(e,t,n)}))}}}function Qt(e,t,n,i,r){var o=!1;for(var a in t)a in e?t[a]!==n[a]&&(o=!0):(o=!0,en(e,a,i,r));for(var a in e)a in t||(o=!0,delete e[a]);return o}function en(e,t,n,i){Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:function(){return n[i][t]}})}function tn(e,t){for(var n in t)e[n]=t[n];for(var n in e)n in t||delete e[n]}function nn(){return an().slots}function rn(){return an().attrs}function on(){return an().listeners}function an(){var e=ce;return e._setupContext||(e._setupContext=Jt(e))}function sn(e,t){var n=r(e)?e.reduce((function(e,t){return e[t]={},e}),{}):e;for(var i in t){var o=n[i];o?r(o)||u(o)?n[i]={type:o,default:t[i]}:o.default=t[i]:null===o&&(n[i]={default:t[i]})}return n}var ln=null;function un(e,t){return(e.__esModule||ue&&"Module"===e[Symbol.toStringTag])&&(e=e.default),c(e)?t.extend(e):e}function cn(e){if(r(e))for(var t=0;tdocument.createEvent("Event").timeStamp&&(fi=function(){return pi.now()})}var mi=function(e,t){if(e.post){if(!t.post)return 1}else if(t.post)return-1;return e.id-t.id};function vi(){var e,t;for(hi=fi(),ci=!0,ai.sort(mi),di=0;didi&&ai[n].id>e.id;)n--;ai.splice(n+1,0,e)}else ai.push(e);ui||(ui=!0,On(vi))}}function bi(e,t){if(e){for(var n=Object.create(null),i=ue?Reflect.ownKeys(e):Object.keys(e),r=0;r-1)if(o&&!w(r,"default"))a=!1;else if(""===a||a===$(e)){var l=zi(String,r.type);(l<0||s-1:"string"==typeof e?e.split(",").indexOf(t)>-1:!!f(e)&&e.test(t)}function tr(e,t){var n=e.cache,i=e.keys,r=e._vnode;for(var o in n){var a=n[o];if(a){var s=a.name;s&&!t(s)&&nr(n,o,i,r)}}}function nr(e,t,n,i){var r=e[t];!r||i&&r.tag===i.tag||r.componentInstance.$destroy(),e[t]=null,_(n,t)}!function(e){e.prototype._init=function(e){var t=this;t._uid=Gi++,t._isVue=!0,t.__v_skip=!0,t._scope=new gt(!0),t._scope._vm=!0,e&&e._isComponent?function(e,t){var n=e.$options=Object.create(e.constructor.options),i=t._parentVnode;n.parent=t.parent,n._parentVnode=i;var r=i.componentOptions;n.propsData=r.propsData,n._parentListeners=r.listeners,n._renderChildren=r.children,n._componentTag=r.tag,t.render&&(n.render=t.render,n.staticRenderFns=t.staticRenderFns)}(t,e):t.$options=Ii(Xi(t.constructor),e||{},t),t._renderProxy=t,t._self=t,function(e){var t=e.$options,n=t.parent;if(n&&!t.abstract){for(;n.$options.abstract&&n.$parent;)n=n.$parent;n.$children.push(e)}e.$parent=n,e.$root=n?n.$root:e,e.$children=[],e.$refs={},e._provided=n?n._provided:Object.create(null),e._watcher=null,e._inactive=null,e._directInactive=!1,e._isMounted=!1,e._isDestroyed=!1,e._isBeingDestroyed=!1}(t),function(e){e._events=Object.create(null),e._hasHookEvent=!1;var t=e.$options._parentListeners;t&&ei(e,t)}(t),function(e){e._vnode=null,e._staticTrees=null;var t=e.$options,n=e.$vnode=t._parentVnode,r=n&&n.context;e.$slots=qt(t._renderChildren,r),e.$scopedSlots=n?Gt(e.$parent,n.data.scopedSlots,e.$slots):i,e._c=function(t,n,i,r){return dn(e,t,n,i,r,!1)},e.$createElement=function(t,n,i,r){return dn(e,t,n,i,r,!0)};var o=n&&n.data;Me(e,"$attrs",o&&o.attrs||i,null,!0),Me(e,"$listeners",t._parentListeners||i,null,!0)}(t),oi(t,"beforeCreate",void 0,!1),function(e){var t=bi(e.$options.inject,e);t&&($e(!1),Object.keys(t).forEach((function(n){Me(e,n,t[n])})),$e(!0))}(t),Hi(t),function(e){var t=e.$options.provide;if(t){var n=u(t)?t.call(e):t;if(!c(n))return;for(var i=wt(e),r=ue?Reflect.ownKeys(n):Object.keys(n),o=0;o1?T(n):n;for(var i=T(arguments,1),r='event handler for "'.concat(e,'"'),o=0,a=n.length;oparseInt(this.max)&&nr(e,t[0],t,this._vnode),this.vnodeToCache=null}}},created:function(){this.cache=Object.create(null),this.keys=[]},destroyed:function(){for(var e in this.cache)nr(this.cache,e,this.keys)},mounted:function(){var e=this;this.cacheVNode(),this.$watch("include",(function(t){tr(e,(function(e){return er(t,e)}))})),this.$watch("exclude",(function(t){tr(e,(function(e){return!er(t,e)}))}))},updated:function(){this.cacheVNode()},render:function(){var e=this.$slots.default,t=cn(e),n=t&&t.componentOptions;if(n){var i=Qi(n),r=this.include,o=this.exclude;if(r&&(!i||!er(r,i))||o&&i&&er(o,i))return t;var a=this.cache,s=this.keys,l=null==t.key?n.Ctor.cid+(n.tag?"::".concat(n.tag):""):t.key;a[l]?(t.componentInstance=a[l].componentInstance,_(s,l),s.push(l)):(this.vnodeToCache=t,this.keyToCache=l),t.data.keepAlive=!0}return t||e&&e[0]}}};!function(e){var t={get:function(){return B}};Object.defineProperty(e,"config",t),e.util={warn:Ei,extend:P,mergeOptions:Ii,defineReactive:Me},e.set=je,e.delete=Ie,e.nextTick=On,e.observable=function(e){return Pe(e),e},e.options=Object.create(null),z.forEach((function(t){e.options[t+"s"]=Object.create(null)})),e.options._base=e,P(e.options.components,rr),function(e){e.use=function(e){var t=this._installedPlugins||(this._installedPlugins=[]);if(t.indexOf(e)>-1)return this;var n=T(arguments,1);return n.unshift(this),u(e.install)?e.install.apply(e,n):u(e)&&e.apply(null,n),t.push(e),this}}(e),function(e){e.mixin=function(e){return this.options=Ii(this.options,e),this}}(e),Ji(e),function(e){z.forEach((function(t){e[t]=function(e,n){return n?("component"===t&&h(n)&&(n.name=n.name||e,n=this.options._base.extend(n)),"directive"===t&&u(n)&&(n={bind:n,update:n}),this.options[t+"s"][e]=n,n):this.options[t+"s"][e]}}))}(e)}(Zi),Object.defineProperty(Zi.prototype,"$isServer",{get:oe}),Object.defineProperty(Zi.prototype,"$ssrContext",{get:function(){return this.$vnode&&this.$vnode.ssrContext}}),Object.defineProperty(Zi,"FunctionalRenderContext",{value:yi}),Zi.version=Un;var or=b("style,class"),ar=b("input,textarea,option,select,progress"),sr=b("contenteditable,draggable,spellcheck"),lr=b("events,caret,typing,plaintext-only"),ur=b("allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,default,defaultchecked,defaultmuted,defaultselected,defer,disabled,enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,required,reversed,scoped,seamless,selected,sortable,truespeed,typemustmatch,visible"),cr="http://www.w3.org/1999/xlink",dr=function(e){return":"===e.charAt(5)&&"xlink"===e.slice(0,5)},hr=function(e){return dr(e)?e.slice(6,e.length):""},fr=function(e){return null==e||!1===e};function pr(e){for(var t=e.data,n=e,i=e;a(i.componentInstance);)(i=i.componentInstance._vnode)&&i.data&&(t=mr(i.data,t));for(;a(n=n.parent);)n&&n.data&&(t=mr(t,n.data));return function(e,t){if(a(e)||a(t))return vr(e,gr(t));return""}(t.staticClass,t.class)}function mr(e,t){return{staticClass:vr(e.staticClass,t.staticClass),class:a(e.class)?[e.class,t.class]:t.class}}function vr(e,t){return e?t?e+" "+t:e:t||""}function gr(e){return Array.isArray(e)?function(e){for(var t,n="",i=0,r=e.length;i-1?Rr(e,t,n):ur(t)?fr(n)?e.removeAttribute(t):(n="allowfullscreen"===t&&"EMBED"===e.tagName?"true":t,e.setAttribute(t,n)):sr(t)?e.setAttribute(t,function(e,t){return fr(t)||"false"===t?"false":"contenteditable"===e&&lr(t)?t:"true"}(t,n)):dr(t)?fr(n)?e.removeAttributeNS(cr,hr(t)):e.setAttributeNS(cr,t,n):Rr(e,t,n)}function Rr(e,t,n){if(fr(n))e.removeAttribute(t);else{if(X&&!Z&&"TEXTAREA"===e.tagName&&"placeholder"===t&&""!==n&&!e.__ieph){var i=function(t){t.stopImmediatePropagation(),e.removeEventListener("input",i)};e.addEventListener("input",i),e.__ieph=!0}e.setAttribute(t,n)}}var Br={create:Vr,update:Vr};function Hr(e,t){var n=t.elm,i=t.data,r=e.data;if(!(o(i.staticClass)&&o(i.class)&&(o(r)||o(r.staticClass)&&o(r.class)))){var s=pr(t),l=n._transitionClasses;a(l)&&(s=vr(s,gr(l))),s!==n._prevClass&&(n.setAttribute("class",s),n._prevClass=s)}}var Ur,Wr={create:Hr,update:Hr};function qr(e,t,n){var i=Ur;return function r(){var o=t.apply(null,arguments);null!==o&&Gr(e,r,n,i)}}var Yr=bn&&!(te&&Number(te[1])<=53);function Kr(e,t,n,i){if(Yr){var r=hi,o=t;t=o._wrapper=function(e){if(e.target===e.currentTarget||e.timeStamp>=r||e.timeStamp<=0||e.target.ownerDocument!==document)return o.apply(this,arguments)}}Ur.addEventListener(e,t,ie?{capture:n,passive:i}:n)}function Gr(e,t,n,i){(i||Ur).removeEventListener(e,t._wrapper||t,n)}function Xr(e,t){if(!o(e.data.on)||!o(t.data.on)){var n=t.data.on||{},i=e.data.on||{};Ur=t.elm||e.elm,function(e){if(a(e.__r)){var t=X?"change":"input";e[t]=[].concat(e.__r,e[t]||[]),delete e.__r}a(e.__c)&&(e.change=[].concat(e.__c,e.change||[]),delete e.__c)}(n),Ot(n,i,Kr,Gr,qr,t.context),Ur=void 0}}var Zr,Jr={create:Xr,update:Xr,destroy:function(e){return Xr(e,$r)}};function Qr(e,t){if(!o(e.data.domProps)||!o(t.data.domProps)){var n,i,r=t.elm,l=e.data.domProps||{},u=t.data.domProps||{};for(n in(a(u.__ob__)||s(u._v_attr_proxy))&&(u=t.data.domProps=P({},u)),l)n in u||(r[n]="");for(n in u){if(i=u[n],"textContent"===n||"innerHTML"===n){if(t.children&&(t.children.length=0),i===l[n])continue;1===r.childNodes.length&&r.removeChild(r.childNodes[0])}if("value"===n&&"PROGRESS"!==r.tagName){r._value=i;var c=o(i)?"":String(i);eo(r,c)&&(r.value=c)}else if("innerHTML"===n&&_r(r.tagName)&&o(r.innerHTML)){(Zr=Zr||document.createElement("div")).innerHTML="".concat(i,"");for(var d=Zr.firstChild;r.firstChild;)r.removeChild(r.firstChild);for(;d.firstChild;)r.appendChild(d.firstChild)}else if(i!==l[n])try{r[n]=i}catch(e){}}}}function eo(e,t){return!e.composing&&("OPTION"===e.tagName||function(e,t){var n=!0;try{n=document.activeElement!==e}catch(e){}return n&&e.value!==t}(e,t)||function(e,t){var n=e.value,i=e._vModifiers;if(a(i)){if(i.number)return g(n)!==g(t);if(i.trim)return n.trim()!==t.trim()}return n!==t}(e,t))}var to={create:Qr,update:Qr},no=C((function(e){var t={},n=/:(.+)/;return e.split(/;(?![^(]*\))/g).forEach((function(e){if(e){var i=e.split(n);i.length>1&&(t[i[0].trim()]=i[1].trim())}})),t}));function io(e){var t=ro(e.style);return e.staticStyle?P(e.staticStyle,t):t}function ro(e){return Array.isArray(e)?M(e):"string"==typeof e?no(e):e}var oo,ao=/^--/,so=/\s*!important$/,lo=function(e,t,n){if(ao.test(t))e.style.setProperty(t,n);else if(so.test(n))e.style.setProperty($(t),n.replace(so,""),"important");else{var i=co(t);if(Array.isArray(n))for(var r=0,o=n.length;r-1?t.split(po).forEach((function(t){return e.classList.add(t)})):e.classList.add(t);else{var n=" ".concat(e.getAttribute("class")||""," ");n.indexOf(" "+t+" ")<0&&e.setAttribute("class",(n+t).trim())}}function vo(e,t){if(t&&(t=t.trim()))if(e.classList)t.indexOf(" ")>-1?t.split(po).forEach((function(t){return e.classList.remove(t)})):e.classList.remove(t),e.classList.length||e.removeAttribute("class");else{for(var n=" ".concat(e.getAttribute("class")||""," "),i=" "+t+" ";n.indexOf(i)>=0;)n=n.replace(i," ");(n=n.trim())?e.setAttribute("class",n):e.removeAttribute("class")}}function go(e){if(e){if("object"==typeof e){var t={};return!1!==e.css&&P(t,bo(e.name||"v")),P(t,e),t}return"string"==typeof e?bo(e):void 0}}var bo=C((function(e){return{enterClass:"".concat(e,"-enter"),enterToClass:"".concat(e,"-enter-to"),enterActiveClass:"".concat(e,"-enter-active"),leaveClass:"".concat(e,"-leave"),leaveToClass:"".concat(e,"-leave-to"),leaveActiveClass:"".concat(e,"-leave-active")}})),yo=K&&!Z,_o="transition",xo="transitionend",wo="animation",Co="animationend";yo&&(void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(_o="WebkitTransition",xo="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(wo="WebkitAnimation",Co="webkitAnimationEnd"));var ko=K?window.requestAnimationFrame?window.requestAnimationFrame.bind(window):setTimeout:function(e){return e()};function So(e){ko((function(){ko(e)}))}function Oo(e,t){var n=e._transitionClasses||(e._transitionClasses=[]);n.indexOf(t)<0&&(n.push(t),mo(e,t))}function Eo(e,t){e._transitionClasses&&_(e._transitionClasses,t),vo(e,t)}function $o(e,t,n){var i=To(e,t),r=i.type,o=i.timeout,a=i.propCount;if(!r)return n();var s="transition"===r?xo:Co,l=0,u=function(){e.removeEventListener(s,c),n()},c=function(t){t.target===e&&++l>=a&&u()};setTimeout((function(){l0&&(n="transition",c=a,d=o.length):"animation"===t?u>0&&(n="animation",c=u,d=l.length):d=(n=(c=Math.max(a,u))>0?a>u?"transition":"animation":null)?"transition"===n?o.length:l.length:0,{type:n,timeout:c,propCount:d,hasTransform:"transition"===n&&Do.test(i[_o+"Property"])}}function Po(e,t){for(;e.length1}function Lo(e,t){!0!==t.data.show&&jo(t)}var Fo=function(e){var t,n,i={},u=e.modules,c=e.nodeOps;for(t=0;tp?_(e,o(n[g+1])?null:n[g+1].elm,n,f,g,i):f>g&&w(t,d,p)}(d,m,g,n,u):a(g)?(a(e.text)&&c.setTextContent(d,""),_(d,null,g,0,g.length-1,n)):a(m)?w(m,0,m.length-1):a(e.text)&&c.setTextContent(d,""):e.text!==t.text&&c.setTextContent(d,t.text),a(p)&&a(f=p.hook)&&a(f=f.postpatch)&&f(e,t)}}}function O(e,t,n){if(s(n)&&a(e.parent))e.parent.data.pendingInsert=t;else for(var i=0;i-1,a.selected!==o&&(a.selected=o);else if(N(Ho(a),i))return void(e.selectedIndex!==s&&(e.selectedIndex=s));r||(e.selectedIndex=-1)}}function Bo(e,t){return t.every((function(t){return!N(t,e)}))}function Ho(e){return"_value"in e?e._value:e.value}function Uo(e){e.target.composing=!0}function Wo(e){e.target.composing&&(e.target.composing=!1,qo(e.target,"input"))}function qo(e,t){var n=document.createEvent("HTMLEvents");n.initEvent(t,!0,!0),e.dispatchEvent(n)}function Yo(e){return!e.componentInstance||e.data&&e.data.transition?e:Yo(e.componentInstance._vnode)}var Ko={model:Vo,show:{bind:function(e,t,n){var i=t.value,r=(n=Yo(n)).data&&n.data.transition,o=e.__vOriginalDisplay="none"===e.style.display?"":e.style.display;i&&r?(n.data.show=!0,jo(n,(function(){e.style.display=o}))):e.style.display=i?o:"none"},update:function(e,t,n){var i=t.value;!i!=!t.oldValue&&((n=Yo(n)).data&&n.data.transition?(n.data.show=!0,i?jo(n,(function(){e.style.display=e.__vOriginalDisplay})):Io(n,(function(){e.style.display="none"}))):e.style.display=i?e.__vOriginalDisplay:"none")},unbind:function(e,t,n,i,r){r||(e.style.display=e.__vOriginalDisplay)}}},Go={name:String,appear:Boolean,css:Boolean,mode:String,type:String,enterClass:String,leaveClass:String,enterToClass:String,leaveToClass:String,enterActiveClass:String,leaveActiveClass:String,appearClass:String,appearActiveClass:String,appearToClass:String,duration:[Number,String,Object]};function Xo(e){var t=e&&e.componentOptions;return t&&t.Ctor.options.abstract?Xo(cn(t.children)):e}function Zo(e){var t={},n=e.$options;for(var i in n.propsData)t[i]=e[i];var r=n._parentListeners;for(var i in r)t[S(i)]=r[i];return t}function Jo(e,t){if(/\d-keep-alive$/.test(t.tag))return e("keep-alive",{props:t.componentOptions.propsData})}var Qo=function(e){return e.tag||Kt(e)},ea=function(e){return"show"===e.name},ta={name:"transition",props:Go,abstract:!0,render:function(e){var t=this,n=this.$slots.default;if(n&&(n=n.filter(Qo)).length){0;var i=this.mode;0;var r=n[0];if(function(e){for(;e=e.parent;)if(e.data.transition)return!0}(this.$vnode))return r;var o=Xo(r);if(!o)return r;if(this._leaving)return Jo(e,r);var a="__transition-".concat(this._uid,"-");o.key=null==o.key?o.isComment?a+"comment":a+o.tag:l(o.key)?0===String(o.key).indexOf(a)?o.key:a+o.key:o.key;var s=(o.data||(o.data={})).transition=Zo(this),u=this._vnode,c=Xo(u);if(o.data.directives&&o.data.directives.some(ea)&&(o.data.show=!0),c&&c.data&&!function(e,t){return t.key===e.key&&t.tag===e.tag}(o,c)&&!Kt(c)&&(!c.componentInstance||!c.componentInstance._vnode.isComment)){var d=c.data.transition=P({},s);if("out-in"===i)return this._leaving=!0,Et(d,"afterLeave",(function(){t._leaving=!1,t.$forceUpdate()})),Jo(e,r);if("in-out"===i){if(Kt(o))return u;var h,f=function(){h()};Et(s,"afterEnter",f),Et(s,"enterCancelled",f),Et(d,"delayLeave",(function(e){h=e}))}}return r}}},na=P({tag:String,moveClass:String},Go);function ia(e){e.elm._moveCb&&e.elm._moveCb(),e.elm._enterCb&&e.elm._enterCb()}function ra(e){e.data.newPos=e.elm.getBoundingClientRect()}function oa(e){var t=e.data.pos,n=e.data.newPos,i=t.left-n.left,r=t.top-n.top;if(i||r){e.data.moved=!0;var o=e.elm.style;o.transform=o.WebkitTransform="translate(".concat(i,"px,").concat(r,"px)"),o.transitionDuration="0s"}}delete na.mode;var aa={Transition:ta,TransitionGroup:{props:na,beforeMount:function(){var e=this,t=this._update;this._update=function(n,i){var r=ni(e);e.__patch__(e._vnode,e.kept,!1,!0),e._vnode=e.kept,r(),t.call(e,n,i)}},render:function(e){for(var t=this.tag||this.$vnode.data.tag||"span",n=Object.create(null),i=this.prevChildren=this.children,r=this.$slots.default||[],o=this.children=[],a=Zo(this),s=0;s-1?wr[e]=t.constructor===window.HTMLUnknownElement||t.constructor===window.HTMLElement:wr[e]=/HTMLUnknownElement/.test(t.toString())},P(Zi.options.directives,Ko),P(Zi.options.components,aa),Zi.prototype.__patch__=K?Fo:j,Zi.prototype.$mount=function(e,t){return function(e,t,n){var i;e.$el=t,e.$options.render||(e.$options.render=pe),oi(e,"beforeMount"),i=function(){e._update(e._render(),n)},new Xn(e,i,j,{before:function(){e._isMounted&&!e._isDestroyed&&oi(e,"beforeUpdate")}},!0),n=!1;var r=e._preWatchers;if(r)for(var o=0;o0&&void 0!==arguments[0]?arguments[0]:"";return String(e).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")};var c=t.arrayFindIndex=function(e,t){for(var n=0;n!==e.length;++n)if(t(e[n]))return n;return-1},d=(t.arrayFind=function(e,t){var n=c(e,t);return-1!==n?e[n]:void 0},t.coerceTruthyValueToArray=function(e){return Array.isArray(e)?e:e?[e]:[]},t.isIE=function(){return!a.default.prototype.$isServer&&!isNaN(Number(document.documentMode))},t.isEdge=function(){return!a.default.prototype.$isServer&&navigator.userAgent.indexOf("Edge")>-1},t.isFirefox=function(){return!a.default.prototype.$isServer&&!!window.navigator.userAgent.match(/firefox/i)},t.autoprefixer=function(e){if("object"!==(void 0===e?"undefined":i(e)))return e;var t=["ms-","webkit-"];return["transform","transition","animation"].forEach((function(n){var i=e[n];n&&i&&t.forEach((function(t){e[t+n]=i}))})),e},t.kebabCase=function(e){var t=/([^-])([A-Z])/g;return e.replace(t,"$1-$2").replace(t,"$1-$2").toLowerCase()},t.capitalize=function(e){return(0,s.isString)(e)?e.charAt(0).toUpperCase()+e.slice(1):e},t.looseEqual=function(e,t){var n=(0,s.isObject)(e),i=(0,s.isObject)(t);return n&&i?JSON.stringify(e)===JSON.stringify(t):!n&&!i&&String(e)===String(t)}),h=t.arrayEquals=function(e,t){if(t=t||[],(e=e||[]).length!==t.length)return!1;for(var n=0;n-1}var p=t.getStyle=u<9?function(e,t){if(!a){if(!e||!t)return null;"float"===(t=c(t))&&(t="styleFloat");try{switch(t){case"opacity":try{return e.filters.item("alpha").opacity/100}catch(e){return 1}default:return e.style[t]||e.currentStyle?e.currentStyle[t]:null}}catch(n){return e.style[t]}}}:function(e,t){if(!a){if(!e||!t)return null;"float"===(t=c(t))&&(t="cssFloat");try{var n=document.defaultView.getComputedStyle(e,"");return e.style[t]||n?n[t]:null}catch(n){return e.style[t]}}};var m=t.isScroll=function(e,t){if(!a)return p(e,null!=t?t?"overflow-y":"overflow-x":"overflow").match(/(scroll|auto|overlay)/)};t.getScrollContainer=function(e,t){if(!a){for(var n=e;n;){if([window,document,document.documentElement].includes(n))return window;if(m(n,t))return n;n=n.parentNode}return n}},t.isInContainer=function(e,t){if(a||!e||!t)return!1;var n=e.getBoundingClientRect(),i=void 0;return i=[window,document,document.documentElement,null,void 0].includes(t)?{top:0,right:window.innerWidth,bottom:window.innerHeight,left:0}:t.getBoundingClientRect(),n.topi.top&&n.right>i.left&&n.left-1?"center "+t:t+" center"}},appendArrow:function(e){var t=void 0;if(!this.appended){for(var n in this.appended=!0,e.attributes)if(/^_v-/.test(e.attributes[n].name)){t=e.attributes[n].name;break}var i=document.createElement("div");t&&i.setAttribute(t,""),i.setAttribute("x-arrow",""),i.className="popper__arrow",e.appendChild(i)}}},beforeDestroy:function(){this.doDestroy(!0),this.popperElm&&this.popperElm.parentNode===document.body&&(this.popperElm.removeEventListener("click",l),document.body.removeChild(this.popperElm))},deactivated:function(){this.$options.beforeDestroy[0].call(this)}}},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){for(var t=1,n=arguments.length;t=0&&Math.floor(t)===t&&isFinite(e)}function m(e){return a(e)&&"function"==typeof e.then&&"function"==typeof e.catch}function v(e){return null==e?"":Array.isArray(e)||h(e)&&e.toString===d?JSON.stringify(e,null,2):String(e)}function g(e){var t=parseFloat(e);return isNaN(t)?e:t}function b(e,t){for(var n=Object.create(null),i=e.split(","),r=0;r-1)return e.splice(i,1)}}var x=Object.prototype.hasOwnProperty;function w(e,t){return x.call(e,t)}function C(e){var t=Object.create(null);return function(n){return t[n]||(t[n]=e(n))}}var k=/-(\w)/g,S=C((function(e){return e.replace(k,(function(e,t){return t?t.toUpperCase():""}))})),O=C((function(e){return e.charAt(0).toUpperCase()+e.slice(1)})),E=/\B([A-Z])/g,$=C((function(e){return e.replace(E,"-$1").toLowerCase()}));var D=Function.prototype.bind?function(e,t){return e.bind(t)}:function(e,t){function n(n){var i=arguments.length;return i?i>1?e.apply(t,arguments):e.call(t,n):e.call(t)}return n._length=e.length,n};function P(e,t){t=t||0;for(var n=e.length-t,i=new Array(n);n--;)i[n]=e[n+t];return i}function T(e,t){for(var n in t)e[n]=t[n];return e}function M(e){for(var t={},n=0;n0,J=G&&G.indexOf("edge/")>0;G&&G.indexOf("android");var Q=G&&/iphone|ipad|ipod|ios/.test(G);G&&/chrome\/\d+/.test(G),G&&/phantomjs/.test(G);var ee,te=G&&G.match(/firefox\/(\d+)/),ne={}.watch,ie=!1;if(K)try{var re={};Object.defineProperty(re,"passive",{get:function(){ie=!0}}),window.addEventListener("test-passive",null,re)}catch(e){}var oe=function(){return void 0===ee&&(ee=!K&&"undefined"!=typeof global&&(global.process&&"server"===global.process.env.VUE_ENV)),ee},ae=K&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__;function se(e){return"function"==typeof e&&/native code/.test(e.toString())}var le,ue="undefined"!=typeof Symbol&&se(Symbol)&&"undefined"!=typeof Reflect&&se(Reflect.ownKeys);le="undefined"!=typeof Set&&se(Set)?Set:function(){function e(){this.set=Object.create(null)}return e.prototype.has=function(e){return!0===this.set[e]},e.prototype.add=function(e){this.set[e]=!0},e.prototype.clear=function(){this.set=Object.create(null)},e}();var ce=null;function de(){return ce&&{proxy:ce}}function he(e){void 0===e&&(e=null),e||ce&&ce._scope.off(),ce=e,e&&e._scope.on()}var fe=function(){function e(e,t,n,i,r,o,a,s){this.tag=e,this.data=t,this.children=n,this.text=i,this.elm=r,this.ns=void 0,this.context=o,this.fnContext=void 0,this.fnOptions=void 0,this.fnScopeId=void 0,this.key=t&&t.key,this.componentOptions=a,this.componentInstance=void 0,this.parent=void 0,this.raw=!1,this.isStatic=!1,this.isRootInsert=!0,this.isComment=!1,this.isCloned=!1,this.isOnce=!1,this.asyncFactory=s,this.asyncMeta=void 0,this.isAsyncPlaceholder=!1}return Object.defineProperty(e.prototype,"child",{get:function(){return this.componentInstance},enumerable:!1,configurable:!0}),e}(),pe=function(e){void 0===e&&(e="");var t=new fe;return t.text=e,t.isComment=!0,t};function me(e){return new fe(void 0,void 0,void 0,String(e))}function ve(e){var t=new fe(e.tag,e.data,e.children&&e.children.slice(),e.text,e.elm,e.context,e.componentOptions,e.asyncFactory);return t.ns=e.ns,t.isStatic=e.isStatic,t.key=e.key,t.isComment=e.isComment,t.fnContext=e.fnContext,t.fnOptions=e.fnOptions,t.fnScopeId=e.fnScopeId,t.asyncMeta=e.asyncMeta,t.isCloned=!0,t}var ge=0,be=[],ye=function(){function e(){this._pending=!1,this.id=ge++,this.subs=[]}return e.prototype.addSub=function(e){this.subs.push(e)},e.prototype.removeSub=function(e){this.subs[this.subs.indexOf(e)]=null,this._pending||(this._pending=!0,be.push(this))},e.prototype.depend=function(t){e.target&&e.target.addDep(this)},e.prototype.notify=function(e){var t=this.subs.filter((function(e){return e}));for(var n=0,i=t.length;n1)return n&&u(t)?t.call(i):t}else 0}var kt=C((function(e){var t="&"===e.charAt(0),n="~"===(e=t?e.slice(1):e).charAt(0),i="!"===(e=n?e.slice(1):e).charAt(0);return{name:e=i?e.slice(1):e,once:n,capture:i,passive:t}}));function St(e,t){function n(){var e=n.fns;if(!r(e))return pn(e,null,arguments,t,"v-on handler");for(var i=e.slice(),o=0;o0&&(Pt((u=e(u,"".concat(n||"","_").concat(i)))[0])&&Pt(d)&&(h[c]=me(d.text+u[0].text),u.shift()),h.push.apply(h,u)):l(u)?Pt(d)?h[c]=me(d.text+u):""!==u&&h.push(me(u)):Pt(u)&&Pt(d)?h[c]=me(d.text+u.text):(s(t._isVList)&&a(u.tag)&&o(u.key)&&a(n)&&(u.key="__vlist".concat(n,"_").concat(i,"__")),h.push(u)));return h}(e):void 0}function Pt(e){return a(e)&&a(e.text)&&!1===e.isComment}function Tt(e,t){var n,i,o,s,l=null;if(r(e)||"string"==typeof e)for(l=new Array(e.length),n=0,i=e.length;n0,s=t?!!t.$stable:!a,l=t&&t.$key;if(t){if(t._normalized)return t._normalized;if(s&&r&&r!==i&&l===r.$key&&!a&&!r.$hasNormal)return r;for(var u in o={},t)t[u]&&"$"!==u[0]&&(o[u]=Xt(e,n,u,t[u]))}else o={};for(var c in n)c in o||(o[c]=Zt(n,c));return t&&Object.isExtensible(t)&&(t._normalized=o),W(o,"$stable",s),W(o,"$key",l),W(o,"$hasNormal",a),o}function Xt(e,t,n,i){var o=function(){var t=ce;he(e);var n=arguments.length?i.apply(null,arguments):i({}),o=(n=n&&"object"==typeof n&&!r(n)?[n]:Dt(n))&&n[0];return he(t),n&&(!o||1===n.length&&o.isComment&&!Kt(o))?void 0:n};return i.proxy&&Object.defineProperty(t,n,{get:o,enumerable:!0,configurable:!0}),o}function Zt(e,t){return function(){return e[t]}}function Jt(e){return{get attrs(){if(!e._attrsProxy){var t=e._attrsProxy={};W(t,"_v_attr_proxy",!0),Qt(t,e.$attrs,i,e,"$attrs")}return e._attrsProxy},get listeners(){e._listenersProxy||Qt(e._listenersProxy={},e.$listeners,i,e,"$listeners");return e._listenersProxy},get slots(){return function(e){e._slotsProxy||tn(e._slotsProxy={},e.$scopedSlots);return e._slotsProxy}(e)},emit:D(e.$emit,e),expose:function(t){t&&Object.keys(t).forEach((function(n){return Je(e,t,n)}))}}}function Qt(e,t,n,i,r){var o=!1;for(var a in t)a in e?t[a]!==n[a]&&(o=!0):(o=!0,en(e,a,i,r));for(var a in e)a in t||(o=!0,delete e[a]);return o}function en(e,t,n,i){Object.defineProperty(e,t,{enumerable:!0,configurable:!0,get:function(){return n[i][t]}})}function tn(e,t){for(var n in t)e[n]=t[n];for(var n in e)n in t||delete e[n]}function nn(){return an().slots}function rn(){return an().attrs}function on(){return an().listeners}function an(){var e=ce;return e._setupContext||(e._setupContext=Jt(e))}function sn(e,t){var n=r(e)?e.reduce((function(e,t){return e[t]={},e}),{}):e;for(var i in t){var o=n[i];o?r(o)||u(o)?n[i]={type:o,default:t[i]}:o.default=t[i]:null===o&&(n[i]={default:t[i]})}return n}var ln=null;function un(e,t){return(e.__esModule||ue&&"Module"===e[Symbol.toStringTag])&&(e=e.default),c(e)?t.extend(e):e}function cn(e){if(r(e))for(var t=0;tdocument.createEvent("Event").timeStamp&&(fi=function(){return pi.now()})}var mi=function(e,t){if(e.post){if(!t.post)return 1}else if(t.post)return-1;return e.id-t.id};function vi(){var e,t;for(hi=fi(),ci=!0,ai.sort(mi),di=0;didi&&ai[n].id>e.id;)n--;ai.splice(n+1,0,e)}else ai.push(e);ui||(ui=!0,On(vi))}}function bi(e,t){if(e){for(var n=Object.create(null),i=ue?Reflect.ownKeys(e):Object.keys(e),r=0;r-1)if(o&&!w(r,"default"))a=!1;else if(""===a||a===$(e)){var l=zi(String,r.type);(l<0||s-1:"string"==typeof e?e.split(",").indexOf(t)>-1:!!f(e)&&e.test(t)}function tr(e,t){var n=e.cache,i=e.keys,r=e._vnode;for(var o in n){var a=n[o];if(a){var s=a.name;s&&!t(s)&&nr(n,o,i,r)}}}function nr(e,t,n,i){var r=e[t];!r||i&&r.tag===i.tag||r.componentInstance.$destroy(),e[t]=null,_(n,t)}!function(e){e.prototype._init=function(e){var t=this;t._uid=Gi++,t._isVue=!0,t.__v_skip=!0,t._scope=new gt(!0),t._scope._vm=!0,e&&e._isComponent?function(e,t){var n=e.$options=Object.create(e.constructor.options),i=t._parentVnode;n.parent=t.parent,n._parentVnode=i;var r=i.componentOptions;n.propsData=r.propsData,n._parentListeners=r.listeners,n._renderChildren=r.children,n._componentTag=r.tag,t.render&&(n.render=t.render,n.staticRenderFns=t.staticRenderFns)}(t,e):t.$options=Ii(Xi(t.constructor),e||{},t),t._renderProxy=t,t._self=t,function(e){var t=e.$options,n=t.parent;if(n&&!t.abstract){for(;n.$options.abstract&&n.$parent;)n=n.$parent;n.$children.push(e)}e.$parent=n,e.$root=n?n.$root:e,e.$children=[],e.$refs={},e._provided=n?n._provided:Object.create(null),e._watcher=null,e._inactive=null,e._directInactive=!1,e._isMounted=!1,e._isDestroyed=!1,e._isBeingDestroyed=!1}(t),function(e){e._events=Object.create(null),e._hasHookEvent=!1;var t=e.$options._parentListeners;t&&ei(e,t)}(t),function(e){e._vnode=null,e._staticTrees=null;var t=e.$options,n=e.$vnode=t._parentVnode,r=n&&n.context;e.$slots=qt(t._renderChildren,r),e.$scopedSlots=n?Gt(e.$parent,n.data.scopedSlots,e.$slots):i,e._c=function(t,n,i,r){return dn(e,t,n,i,r,!1)},e.$createElement=function(t,n,i,r){return dn(e,t,n,i,r,!0)};var o=n&&n.data;Me(e,"$attrs",o&&o.attrs||i,null,!0),Me(e,"$listeners",t._parentListeners||i,null,!0)}(t),oi(t,"beforeCreate",void 0,!1),function(e){var t=bi(e.$options.inject,e);t&&($e(!1),Object.keys(t).forEach((function(n){Me(e,n,t[n])})),$e(!0))}(t),Hi(t),function(e){var t=e.$options.provide;if(t){var n=u(t)?t.call(e):t;if(!c(n))return;for(var i=wt(e),r=ue?Reflect.ownKeys(n):Object.keys(n),o=0;o1?P(n):n;for(var i=P(arguments,1),r='event handler for "'.concat(e,'"'),o=0,a=n.length;oparseInt(this.max)&&nr(e,t[0],t,this._vnode),this.vnodeToCache=null}}},created:function(){this.cache=Object.create(null),this.keys=[]},destroyed:function(){for(var e in this.cache)nr(this.cache,e,this.keys)},mounted:function(){var e=this;this.cacheVNode(),this.$watch("include",(function(t){tr(e,(function(e){return er(t,e)}))})),this.$watch("exclude",(function(t){tr(e,(function(e){return!er(t,e)}))}))},updated:function(){this.cacheVNode()},render:function(){var e=this.$slots.default,t=cn(e),n=t&&t.componentOptions;if(n){var i=Qi(n),r=this.include,o=this.exclude;if(r&&(!i||!er(r,i))||o&&i&&er(o,i))return t;var a=this.cache,s=this.keys,l=null==t.key?n.Ctor.cid+(n.tag?"::".concat(n.tag):""):t.key;a[l]?(t.componentInstance=a[l].componentInstance,_(s,l),s.push(l)):(this.vnodeToCache=t,this.keyToCache=l),t.data.keepAlive=!0}return t||e&&e[0]}}};!function(e){var t={get:function(){return B}};Object.defineProperty(e,"config",t),e.util={warn:Ei,extend:T,mergeOptions:Ii,defineReactive:Me},e.set=je,e.delete=Ie,e.nextTick=On,e.observable=function(e){return Te(e),e},e.options=Object.create(null),z.forEach((function(t){e.options[t+"s"]=Object.create(null)})),e.options._base=e,T(e.options.components,rr),function(e){e.use=function(e){var t=this._installedPlugins||(this._installedPlugins=[]);if(t.indexOf(e)>-1)return this;var n=P(arguments,1);return n.unshift(this),u(e.install)?e.install.apply(e,n):u(e)&&e.apply(null,n),t.push(e),this}}(e),function(e){e.mixin=function(e){return this.options=Ii(this.options,e),this}}(e),Ji(e),function(e){z.forEach((function(t){e[t]=function(e,n){return n?("component"===t&&h(n)&&(n.name=n.name||e,n=this.options._base.extend(n)),"directive"===t&&u(n)&&(n={bind:n,update:n}),this.options[t+"s"][e]=n,n):this.options[t+"s"][e]}}))}(e)}(Zi),Object.defineProperty(Zi.prototype,"$isServer",{get:oe}),Object.defineProperty(Zi.prototype,"$ssrContext",{get:function(){return this.$vnode&&this.$vnode.ssrContext}}),Object.defineProperty(Zi,"FunctionalRenderContext",{value:yi}),Zi.version=Un;var or=b("style,class"),ar=b("input,textarea,option,select,progress"),sr=b("contenteditable,draggable,spellcheck"),lr=b("events,caret,typing,plaintext-only"),ur=b("allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,default,defaultchecked,defaultmuted,defaultselected,defer,disabled,enabled,formnovalidate,hidden,indeterminate,inert,ismap,itemscope,loop,multiple,muted,nohref,noresize,noshade,novalidate,nowrap,open,pauseonexit,readonly,required,reversed,scoped,seamless,selected,sortable,truespeed,typemustmatch,visible"),cr="http://www.w3.org/1999/xlink",dr=function(e){return":"===e.charAt(5)&&"xlink"===e.slice(0,5)},hr=function(e){return dr(e)?e.slice(6,e.length):""},fr=function(e){return null==e||!1===e};function pr(e){for(var t=e.data,n=e,i=e;a(i.componentInstance);)(i=i.componentInstance._vnode)&&i.data&&(t=mr(i.data,t));for(;a(n=n.parent);)n&&n.data&&(t=mr(t,n.data));return function(e,t){if(a(e)||a(t))return vr(e,gr(t));return""}(t.staticClass,t.class)}function mr(e,t){return{staticClass:vr(e.staticClass,t.staticClass),class:a(e.class)?[e.class,t.class]:t.class}}function vr(e,t){return e?t?e+" "+t:e:t||""}function gr(e){return Array.isArray(e)?function(e){for(var t,n="",i=0,r=e.length;i-1?Rr(e,t,n):ur(t)?fr(n)?e.removeAttribute(t):(n="allowfullscreen"===t&&"EMBED"===e.tagName?"true":t,e.setAttribute(t,n)):sr(t)?e.setAttribute(t,function(e,t){return fr(t)||"false"===t?"false":"contenteditable"===e&&lr(t)?t:"true"}(t,n)):dr(t)?fr(n)?e.removeAttributeNS(cr,hr(t)):e.setAttributeNS(cr,t,n):Rr(e,t,n)}function Rr(e,t,n){if(fr(n))e.removeAttribute(t);else{if(X&&!Z&&"TEXTAREA"===e.tagName&&"placeholder"===t&&""!==n&&!e.__ieph){var i=function(t){t.stopImmediatePropagation(),e.removeEventListener("input",i)};e.addEventListener("input",i),e.__ieph=!0}e.setAttribute(t,n)}}var Br={create:Vr,update:Vr};function Hr(e,t){var n=t.elm,i=t.data,r=e.data;if(!(o(i.staticClass)&&o(i.class)&&(o(r)||o(r.staticClass)&&o(r.class)))){var s=pr(t),l=n._transitionClasses;a(l)&&(s=vr(s,gr(l))),s!==n._prevClass&&(n.setAttribute("class",s),n._prevClass=s)}}var Ur,Wr={create:Hr,update:Hr};function qr(e,t,n){var i=Ur;return function r(){var o=t.apply(null,arguments);null!==o&&Gr(e,r,n,i)}}var Yr=bn&&!(te&&Number(te[1])<=53);function Kr(e,t,n,i){if(Yr){var r=hi,o=t;t=o._wrapper=function(e){if(e.target===e.currentTarget||e.timeStamp>=r||e.timeStamp<=0||e.target.ownerDocument!==document)return o.apply(this,arguments)}}Ur.addEventListener(e,t,ie?{capture:n,passive:i}:n)}function Gr(e,t,n,i){(i||Ur).removeEventListener(e,t._wrapper||t,n)}function Xr(e,t){if(!o(e.data.on)||!o(t.data.on)){var n=t.data.on||{},i=e.data.on||{};Ur=t.elm||e.elm,function(e){if(a(e.__r)){var t=X?"change":"input";e[t]=[].concat(e.__r,e[t]||[]),delete e.__r}a(e.__c)&&(e.change=[].concat(e.__c,e.change||[]),delete e.__c)}(n),Ot(n,i,Kr,Gr,qr,t.context),Ur=void 0}}var Zr,Jr={create:Xr,update:Xr,destroy:function(e){return Xr(e,$r)}};function Qr(e,t){if(!o(e.data.domProps)||!o(t.data.domProps)){var n,i,r=t.elm,l=e.data.domProps||{},u=t.data.domProps||{};for(n in(a(u.__ob__)||s(u._v_attr_proxy))&&(u=t.data.domProps=T({},u)),l)n in u||(r[n]="");for(n in u){if(i=u[n],"textContent"===n||"innerHTML"===n){if(t.children&&(t.children.length=0),i===l[n])continue;1===r.childNodes.length&&r.removeChild(r.childNodes[0])}if("value"===n&&"PROGRESS"!==r.tagName){r._value=i;var c=o(i)?"":String(i);eo(r,c)&&(r.value=c)}else if("innerHTML"===n&&_r(r.tagName)&&o(r.innerHTML)){(Zr=Zr||document.createElement("div")).innerHTML="".concat(i,"");for(var d=Zr.firstChild;r.firstChild;)r.removeChild(r.firstChild);for(;d.firstChild;)r.appendChild(d.firstChild)}else if(i!==l[n])try{r[n]=i}catch(e){}}}}function eo(e,t){return!e.composing&&("OPTION"===e.tagName||function(e,t){var n=!0;try{n=document.activeElement!==e}catch(e){}return n&&e.value!==t}(e,t)||function(e,t){var n=e.value,i=e._vModifiers;if(a(i)){if(i.number)return g(n)!==g(t);if(i.trim)return n.trim()!==t.trim()}return n!==t}(e,t))}var to={create:Qr,update:Qr},no=C((function(e){var t={},n=/:(.+)/;return e.split(/;(?![^(]*\))/g).forEach((function(e){if(e){var i=e.split(n);i.length>1&&(t[i[0].trim()]=i[1].trim())}})),t}));function io(e){var t=ro(e.style);return e.staticStyle?T(e.staticStyle,t):t}function ro(e){return Array.isArray(e)?M(e):"string"==typeof e?no(e):e}var oo,ao=/^--/,so=/\s*!important$/,lo=function(e,t,n){if(ao.test(t))e.style.setProperty(t,n);else if(so.test(n))e.style.setProperty($(t),n.replace(so,""),"important");else{var i=co(t);if(Array.isArray(n))for(var r=0,o=n.length;r-1?t.split(po).forEach((function(t){return e.classList.add(t)})):e.classList.add(t);else{var n=" ".concat(e.getAttribute("class")||""," ");n.indexOf(" "+t+" ")<0&&e.setAttribute("class",(n+t).trim())}}function vo(e,t){if(t&&(t=t.trim()))if(e.classList)t.indexOf(" ")>-1?t.split(po).forEach((function(t){return e.classList.remove(t)})):e.classList.remove(t),e.classList.length||e.removeAttribute("class");else{for(var n=" ".concat(e.getAttribute("class")||""," "),i=" "+t+" ";n.indexOf(i)>=0;)n=n.replace(i," ");(n=n.trim())?e.setAttribute("class",n):e.removeAttribute("class")}}function go(e){if(e){if("object"==typeof e){var t={};return!1!==e.css&&T(t,bo(e.name||"v")),T(t,e),t}return"string"==typeof e?bo(e):void 0}}var bo=C((function(e){return{enterClass:"".concat(e,"-enter"),enterToClass:"".concat(e,"-enter-to"),enterActiveClass:"".concat(e,"-enter-active"),leaveClass:"".concat(e,"-leave"),leaveToClass:"".concat(e,"-leave-to"),leaveActiveClass:"".concat(e,"-leave-active")}})),yo=K&&!Z,_o="transition",xo="transitionend",wo="animation",Co="animationend";yo&&(void 0===window.ontransitionend&&void 0!==window.onwebkittransitionend&&(_o="WebkitTransition",xo="webkitTransitionEnd"),void 0===window.onanimationend&&void 0!==window.onwebkitanimationend&&(wo="WebkitAnimation",Co="webkitAnimationEnd"));var ko=K?window.requestAnimationFrame?window.requestAnimationFrame.bind(window):setTimeout:function(e){return e()};function So(e){ko((function(){ko(e)}))}function Oo(e,t){var n=e._transitionClasses||(e._transitionClasses=[]);n.indexOf(t)<0&&(n.push(t),mo(e,t))}function Eo(e,t){e._transitionClasses&&_(e._transitionClasses,t),vo(e,t)}function $o(e,t,n){var i=Po(e,t),r=i.type,o=i.timeout,a=i.propCount;if(!r)return n();var s="transition"===r?xo:Co,l=0,u=function(){e.removeEventListener(s,c),n()},c=function(t){t.target===e&&++l>=a&&u()};setTimeout((function(){l0&&(n="transition",c=a,d=o.length):"animation"===t?u>0&&(n="animation",c=u,d=l.length):d=(n=(c=Math.max(a,u))>0?a>u?"transition":"animation":null)?"transition"===n?o.length:l.length:0,{type:n,timeout:c,propCount:d,hasTransform:"transition"===n&&Do.test(i[_o+"Property"])}}function To(e,t){for(;e.length1}function Ao(e,t){!0!==t.data.show&&jo(t)}var Fo=function(e){var t,n,i={},u=e.modules,c=e.nodeOps;for(t=0;tp?_(e,o(n[g+1])?null:n[g+1].elm,n,f,g,i):f>g&&w(t,d,p)}(d,m,g,n,u):a(g)?(a(e.text)&&c.setTextContent(d,""),_(d,null,g,0,g.length-1,n)):a(m)?w(m,0,m.length-1):a(e.text)&&c.setTextContent(d,""):e.text!==t.text&&c.setTextContent(d,t.text),a(p)&&a(f=p.hook)&&a(f=f.postpatch)&&f(e,t)}}}function O(e,t,n){if(s(n)&&a(e.parent))e.parent.data.pendingInsert=t;else for(var i=0;i-1,a.selected!==o&&(a.selected=o);else if(L(Ho(a),i))return void(e.selectedIndex!==s&&(e.selectedIndex=s));r||(e.selectedIndex=-1)}}function Bo(e,t){return t.every((function(t){return!L(t,e)}))}function Ho(e){return"_value"in e?e._value:e.value}function Uo(e){e.target.composing=!0}function Wo(e){e.target.composing&&(e.target.composing=!1,qo(e.target,"input"))}function qo(e,t){var n=document.createEvent("HTMLEvents");n.initEvent(t,!0,!0),e.dispatchEvent(n)}function Yo(e){return!e.componentInstance||e.data&&e.data.transition?e:Yo(e.componentInstance._vnode)}var Ko={model:Vo,show:{bind:function(e,t,n){var i=t.value,r=(n=Yo(n)).data&&n.data.transition,o=e.__vOriginalDisplay="none"===e.style.display?"":e.style.display;i&&r?(n.data.show=!0,jo(n,(function(){e.style.display=o}))):e.style.display=i?o:"none"},update:function(e,t,n){var i=t.value;!i!=!t.oldValue&&((n=Yo(n)).data&&n.data.transition?(n.data.show=!0,i?jo(n,(function(){e.style.display=e.__vOriginalDisplay})):Io(n,(function(){e.style.display="none"}))):e.style.display=i?e.__vOriginalDisplay:"none")},unbind:function(e,t,n,i,r){r||(e.style.display=e.__vOriginalDisplay)}}},Go={name:String,appear:Boolean,css:Boolean,mode:String,type:String,enterClass:String,leaveClass:String,enterToClass:String,leaveToClass:String,enterActiveClass:String,leaveActiveClass:String,appearClass:String,appearActiveClass:String,appearToClass:String,duration:[Number,String,Object]};function Xo(e){var t=e&&e.componentOptions;return t&&t.Ctor.options.abstract?Xo(cn(t.children)):e}function Zo(e){var t={},n=e.$options;for(var i in n.propsData)t[i]=e[i];var r=n._parentListeners;for(var i in r)t[S(i)]=r[i];return t}function Jo(e,t){if(/\d-keep-alive$/.test(t.tag))return e("keep-alive",{props:t.componentOptions.propsData})}var Qo=function(e){return e.tag||Kt(e)},ea=function(e){return"show"===e.name},ta={name:"transition",props:Go,abstract:!0,render:function(e){var t=this,n=this.$slots.default;if(n&&(n=n.filter(Qo)).length){0;var i=this.mode;0;var r=n[0];if(function(e){for(;e=e.parent;)if(e.data.transition)return!0}(this.$vnode))return r;var o=Xo(r);if(!o)return r;if(this._leaving)return Jo(e,r);var a="__transition-".concat(this._uid,"-");o.key=null==o.key?o.isComment?a+"comment":a+o.tag:l(o.key)?0===String(o.key).indexOf(a)?o.key:a+o.key:o.key;var s=(o.data||(o.data={})).transition=Zo(this),u=this._vnode,c=Xo(u);if(o.data.directives&&o.data.directives.some(ea)&&(o.data.show=!0),c&&c.data&&!function(e,t){return t.key===e.key&&t.tag===e.tag}(o,c)&&!Kt(c)&&(!c.componentInstance||!c.componentInstance._vnode.isComment)){var d=c.data.transition=T({},s);if("out-in"===i)return this._leaving=!0,Et(d,"afterLeave",(function(){t._leaving=!1,t.$forceUpdate()})),Jo(e,r);if("in-out"===i){if(Kt(o))return u;var h,f=function(){h()};Et(s,"afterEnter",f),Et(s,"enterCancelled",f),Et(d,"delayLeave",(function(e){h=e}))}}return r}}},na=T({tag:String,moveClass:String},Go);function ia(e){e.elm._moveCb&&e.elm._moveCb(),e.elm._enterCb&&e.elm._enterCb()}function ra(e){e.data.newPos=e.elm.getBoundingClientRect()}function oa(e){var t=e.data.pos,n=e.data.newPos,i=t.left-n.left,r=t.top-n.top;if(i||r){e.data.moved=!0;var o=e.elm.style;o.transform=o.WebkitTransform="translate(".concat(i,"px,").concat(r,"px)"),o.transitionDuration="0s"}}delete na.mode;var aa={Transition:ta,TransitionGroup:{props:na,beforeMount:function(){var e=this,t=this._update;this._update=function(n,i){var r=ni(e);e.__patch__(e._vnode,e.kept,!1,!0),e._vnode=e.kept,r(),t.call(e,n,i)}},render:function(e){for(var t=this.tag||this.$vnode.data.tag||"span",n=Object.create(null),i=this.prevChildren=this.children,r=this.$slots.default||[],o=this.children=[],a=Zo(this),s=0;s-1?wr[e]=t.constructor===window.HTMLUnknownElement||t.constructor===window.HTMLElement:wr[e]=/HTMLUnknownElement/.test(t.toString())},T(Zi.options.directives,Ko),T(Zi.options.components,aa),Zi.prototype.__patch__=K?Fo:j,Zi.prototype.$mount=function(e,t){return function(e,t,n){var i;e.$el=t,e.$options.render||(e.$options.render=pe),oi(e,"beforeMount"),i=function(){e._update(e._render(),n)},new Xn(e,i,j,{before:function(){e._isMounted&&!e._isDestroyed&&oi(e,"beforeUpdate")}},!0),n=!1;var r=e._preWatchers;if(r)for(var o=0;o0&&void 0!==arguments[0]?arguments[0]:"";return String(e).replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")};var c=t.arrayFindIndex=function(e,t){for(var n=0;n!==e.length;++n)if(t(e[n]))return n;return-1},d=(t.arrayFind=function(e,t){var n=c(e,t);return-1!==n?e[n]:void 0},t.coerceTruthyValueToArray=function(e){return Array.isArray(e)?e:e?[e]:[]},t.isIE=function(){return!a.default.prototype.$isServer&&!isNaN(Number(document.documentMode))},t.isEdge=function(){return!a.default.prototype.$isServer&&navigator.userAgent.indexOf("Edge")>-1},t.isFirefox=function(){return!a.default.prototype.$isServer&&!!window.navigator.userAgent.match(/firefox/i)},t.autoprefixer=function(e){if("object"!==(void 0===e?"undefined":i(e)))return e;var t=["ms-","webkit-"];return["transform","transition","animation"].forEach((function(n){var i=e[n];n&&i&&t.forEach((function(t){e[t+n]=i}))})),e},t.kebabCase=function(e){var t=/([^-])([A-Z])/g;return e.replace(t,"$1-$2").replace(t,"$1-$2").toLowerCase()},t.capitalize=function(e){return(0,s.isString)(e)?e.charAt(0).toUpperCase()+e.slice(1):e},t.looseEqual=function(e,t){var n=(0,s.isObject)(e),i=(0,s.isObject)(t);return n&&i?JSON.stringify(e)===JSON.stringify(t):!n&&!i&&String(e)===String(t)}),h=t.arrayEquals=function(e,t){if(t=t||[],(e=e||[]).length!==t.length)return!1;for(var n=0;n-1}var p=t.getStyle=u<9?function(e,t){if(!a){if(!e||!t)return null;"float"===(t=c(t))&&(t="styleFloat");try{switch(t){case"opacity":try{return e.filters.item("alpha").opacity/100}catch(e){return 1}default:return e.style[t]||e.currentStyle?e.currentStyle[t]:null}}catch(n){return e.style[t]}}}:function(e,t){if(!a){if(!e||!t)return null;"float"===(t=c(t))&&(t="cssFloat");try{var n=document.defaultView.getComputedStyle(e,"");return e.style[t]||n?n[t]:null}catch(n){return e.style[t]}}};var m=t.isScroll=function(e,t){if(!a)return p(e,null!=t?t?"overflow-y":"overflow-x":"overflow").match(/(scroll|auto|overlay)/)};t.getScrollContainer=function(e,t){if(!a){for(var n=e;n;){if([window,document,document.documentElement].includes(n))return window;if(m(n,t))return n;n=n.parentNode}return n}},t.isInContainer=function(e,t){if(a||!e||!t)return!1;var n=e.getBoundingClientRect(),i=void 0;return i=[window,document,document.documentElement,null,void 0].includes(t)?{top:0,right:window.innerWidth,bottom:window.innerHeight,left:0}:t.getBoundingClientRect(),n.topi.top&&n.right>i.left&&n.left-1?"center "+t:t+" center"}},appendArrow:function(e){var t=void 0;if(!this.appended){for(var n in this.appended=!0,e.attributes)if(/^_v-/.test(e.attributes[n].name)){t=e.attributes[n].name;break}var i=document.createElement("div");t&&i.setAttribute(t,""),i.setAttribute("x-arrow",""),i.className="popper__arrow",e.appendChild(i)}}},beforeDestroy:function(){this.doDestroy(!0),this.popperElm&&this.popperElm.parentNode===document.body&&(this.popperElm.removeEventListener("click",l),document.body.removeChild(this.popperElm))},deactivated:function(){this.$options.beforeDestroy[0].call(this)}}},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){for(var t=1,n=arguments.length;t
'};function r(e,t,n){return en?n:e}function o(e){return 100*(-1+e)}n.configure=function(e){var t,n;for(t in e)void 0!==(n=e[t])&&e.hasOwnProperty(t)&&(i[t]=n);return this},n.status=null,n.set=function(e){var t=n.isStarted();e=r(e,i.minimum,1),n.status=1===e?null:e;var l=n.render(!t),u=l.querySelector(i.barSelector),c=i.speed,d=i.easing;return l.offsetWidth,a((function(t){""===i.positionUsing&&(i.positionUsing=n.getPositioningCSS()),s(u,function(e,t,n){var r;return(r="translate3d"===i.positionUsing?{transform:"translate3d("+o(e)+"%,0,0)"}:"translate"===i.positionUsing?{transform:"translate("+o(e)+"%,0)"}:{"margin-left":o(e)+"%"}).transition="all "+t+"ms "+n,r}(e,c,d)),1===e?(s(l,{transition:"none",opacity:1}),l.offsetWidth,setTimeout((function(){s(l,{transition:"all "+c+"ms linear",opacity:0}),setTimeout((function(){n.remove(),t()}),c)}),c)):setTimeout(t,c)})),this},n.isStarted=function(){return"number"==typeof n.status},n.start=function(){n.status||n.set(0);var e=function(){setTimeout((function(){n.status&&(n.trickle(),e())}),i.trickleSpeed)};return i.trickle&&e(),this},n.done=function(e){return e||n.status?n.inc(.3+.5*Math.random()).set(1):this},n.inc=function(e){var t=n.status;return t?("number"!=typeof e&&(e=(1-t)*r(Math.random()*t,.1,.95)),t=r(t+e,0,.994),n.set(t)):n.start()},n.trickle=function(){return n.inc(Math.random()*i.trickleRate)},e=0,t=0,n.promise=function(i){return i&&"resolved"!==i.state()?(0===t&&n.start(),e++,t++,i.always((function(){0==--t?(e=0,n.done()):n.set((e-t)/e)})),this):this},n.render=function(e){if(n.isRendered())return document.getElementById("nprogress");u(document.documentElement,"nprogress-busy");var t=document.createElement("div");t.id="nprogress",t.innerHTML=i.template;var r,a=t.querySelector(i.barSelector),l=e?"-100":o(n.status||0),c=document.querySelector(i.parent);return s(a,{transition:"all 0 linear",transform:"translate3d("+l+"%,0,0)"}),i.showSpinner||(r=t.querySelector(i.spinnerSelector))&&h(r),c!=document.body&&u(c,"nprogress-custom-parent"),c.appendChild(t),t},n.remove=function(){c(document.documentElement,"nprogress-busy"),c(document.querySelector(i.parent),"nprogress-custom-parent");var e=document.getElementById("nprogress");e&&h(e)},n.isRendered=function(){return!!document.getElementById("nprogress")},n.getPositioningCSS=function(){var e=document.body.style,t="WebkitTransform"in e?"Webkit":"MozTransform"in e?"Moz":"msTransform"in e?"ms":"OTransform"in e?"O":"";return t+"Perspective"in e?"translate3d":t+"Transform"in e?"translate":"margin"};var a=function(){var e=[];function t(){var n=e.shift();n&&n(t)}return function(n){e.push(n),1==e.length&&t()}}(),s=function(){var e=["Webkit","O","Moz","ms"],t={};function n(n){return n=n.replace(/^-ms-/,"ms-").replace(/-([\da-z])/gi,(function(e,t){return t.toUpperCase()})),t[n]||(t[n]=function(t){var n=document.body.style;if(t in n)return t;for(var i,r=e.length,o=t.charAt(0).toUpperCase()+t.slice(1);r--;)if((i=e[r]+o)in n)return i;return t}(n))}function i(e,t,i){t=n(t),e.style[t]=i}return function(e,t){var n,r,o=arguments;if(2==o.length)for(n in t)void 0!==(r=t[n])&&t.hasOwnProperty(n)&&i(e,n,r);else i(e,o[1],o[2])}}();function l(e,t){return("string"==typeof e?e:d(e)).indexOf(" "+t+" ")>=0}function u(e,t){var n=d(e),i=n+t;l(n,t)||(e.className=i.substring(1))}function c(e,t){var n,i=d(e);l(e,t)&&(n=i.replace(" "+t+" "," "),e.className=n.substring(1,n.length-1))}function d(e){return(" "+(e.className||"")+" ").replace(/\s+/gi," ")}function h(e){e&&e.parentNode&&e.parentNode.removeChild(e)}return n})?i.call(t,n,t,e):i)||(e.exports=r)},function(e,t,n){"use strict";var i=n(2),r=n(95).f,o=n(24),a=n(172),s=n(58),l=n(111),u=n(188);e.exports=function(e,t){var n,c,d,h,f,p=e.target,m=e.global,v=e.stat;if(n=m?i:v?i[p]||s(p,{}):(i[p]||{}).prototype)for(c in t){if(h=t[c],d=e.dontCallGetSet?(f=r(n,c))&&f.value:n[c],!u(m?c:p+(v?".":"#")+c,e.forced)&&void 0!==d){if(typeof h==typeof d)continue;l(h,d)}(e.sham||d&&d.sham)&&o(h,"sham",!0),a(n,c,h,e)}}},function(e,t,n){"use strict";var i=n(51),r=Function.prototype.call;e.exports=i?r.bind(r):function(){return r.apply(r,arguments)}},function(e,t,n){"use strict";var i=n(4);e.exports=!i((function(){var e=function(){}.bind();return"function"!=typeof e||e.hasOwnProperty("prototype")}))},function(e,t,n){"use strict";e.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},function(e,t,n){"use strict";var i=n(96),r=n(97);e.exports=function(e){return i(r(e))}},function(e,t,n){"use strict";var i=n(2),r=n(1),o=function(e){return r(e)?e:void 0};e.exports=function(e,t){return arguments.length<2?o(i[e]):i[e]&&i[e][t]}},function(e,t,n){"use strict";var i=n(1),r=n(168),o=TypeError;e.exports=function(e){if(i(e))return e;throw new o(r(e)+" is not a function")}},function(e,t,n){"use strict";var i=n(2),r=n(106),o=n(11),a=n(108),s=n(104),l=n(103),u=i.Symbol,c=r("wks"),d=l?u.for||u:u&&u.withoutSetter||a;e.exports=function(e){return o(c,e)||(c[e]=s&&o(u,e)?u[e]:d("Symbol."+e)),c[e]}},function(e,t,n){"use strict";var i=n(2),r=n(58),o=i["__core-js_shared__"]||r("__core-js_shared__",{});e.exports=o},function(e,t,n){"use strict";var i=n(2),r=Object.defineProperty;e.exports=function(e,t){try{r(i,e,{value:t,configurable:!0,writable:!0})}catch(n){i[e]=t}return t}},function(e,t,n){"use strict";var i=n(97),r=Object;e.exports=function(e){return r(i(e))}},function(e,t,n){"use strict";var i=n(13),r=String,o=TypeError;e.exports=function(e){if(i(e))return e;throw new o(r(e)+" is not an object")}},function(e,t,n){"use strict";var i=n(185);e.exports=function(e){return i(e.length)}},function(e,t,n){var i=n(212),r=n(19),o=Object.prototype,a=o.hasOwnProperty,s=o.propertyIsEnumerable,l=i(function(){return arguments}())?i:function(e){return r(e)&&a.call(e,"callee")&&!s.call(e,"callee")};e.exports=l},function(e,t,n){var i=n(14)(n(8),"Map");e.exports=i},function(e,t){e.exports=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}},function(e,t,n){var i=n(232),r=n(239),o=n(241),a=n(242),s=n(243);function l(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t-1&&e%1==0&&e<=9007199254740991}},function(e,t,n){var i=n(9),r=n(70),o=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,a=/^\w*$/;e.exports=function(e,t){if(i(e))return!1;var n=typeof e;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=e&&!r(e))||(a.test(e)||!o.test(e)||null!=t&&e in Object(t))}},function(e,t,n){var i=n(26),r=n(19);e.exports=function(e){return"symbol"==typeof e||r(e)&&"[object Symbol]"==i(e)}},function(e,t){e.exports=function(e){return e}},function(e,t,n){"use strict";t.__esModule=!0,t.i18n=t.use=t.t=void 0;var i=a(n(305)),r=a(n(0)),o=a(n(306));function a(e){return e&&e.__esModule?e:{default:e}}var s=(0,a(n(307)).default)(r.default),l=i.default,u=!1,c=function(){var e=Object.getPrototypeOf(this||r.default).$t;if("function"==typeof e&&r.default.locale)return u||(u=!0,r.default.locale(r.default.config.lang,(0,o.default)(l,r.default.locale(r.default.config.lang)||{},{clone:!0}))),e.apply(this,arguments)},d=t.t=function(e,t){var n=c.apply(this,arguments);if(null!=n)return n;for(var i=e.split("."),r=l,o=0,a=i.length;o1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;l||(l=document.createElement("textarea"),document.body.appendChild(l));var i=d(e),r=i.paddingSize,o=i.borderSize,a=i.boxSizing,s=i.contextStyle;l.setAttribute("style",s+";"+u),l.value=e.value||e.placeholder||"";var c=l.scrollHeight,h={};"border-box"===a?c+=o:"content-box"===a&&(c-=r),l.value="";var f=l.scrollHeight-r;if(null!==t){var p=f*t;"border-box"===a&&(p=p+r+o),c=Math.max(p,c),h.minHeight=p+"px"}if(null!==n){var m=f*n;"border-box"===a&&(m=m+r+o),c=Math.min(m,c)}return h.height=c+"px",l.parentNode&&l.parentNode.removeChild(l),l=null,h}var f=n(9),p=n.n(f),m=n(21),v={name:"ElInput",componentName:"ElInput",mixins:[o.a,s.a],inheritAttrs:!1,inject:{elForm:{default:""},elFormItem:{default:""}},data:function(){return{textareaCalcStyle:{},hovering:!1,focused:!1,isComposing:!1,passwordVisible:!1}},props:{value:[String,Number],size:String,resize:String,form:String,disabled:Boolean,readonly:Boolean,type:{type:String,default:"text"},autosize:{type:[Boolean,Object],default:!1},autocomplete:{type:String,default:"off"},autoComplete:{type:String,validator:function(e){return!0}},validateEvent:{type:Boolean,default:!0},suffixIcon:String,prefixIcon:String,label:String,clearable:{type:Boolean,default:!1},showPassword:{type:Boolean,default:!1},showWordLimit:{type:Boolean,default:!1},tabindex:String},computed:{_elFormItemSize:function(){return(this.elFormItem||{}).elFormItemSize},validateState:function(){return this.elFormItem?this.elFormItem.validateState:""},needStatusIcon:function(){return!!this.elForm&&this.elForm.statusIcon},validateIcon:function(){return{validating:"el-icon-loading",success:"el-icon-circle-check",error:"el-icon-circle-close"}[this.validateState]},textareaStyle:function(){return p()({},this.textareaCalcStyle,{resize:this.resize})},inputSize:function(){return this.size||this._elFormItemSize||(this.$ELEMENT||{}).size},inputDisabled:function(){return this.disabled||(this.elForm||{}).disabled},nativeInputValue:function(){return null===this.value||void 0===this.value?"":String(this.value)},showClear:function(){return this.clearable&&!this.inputDisabled&&!this.readonly&&this.nativeInputValue&&(this.focused||this.hovering)},showPwdVisible:function(){return this.showPassword&&!this.inputDisabled&&!this.readonly&&(!!this.nativeInputValue||this.focused)},isWordLimitVisible:function(){return this.showWordLimit&&this.$attrs.maxlength&&("text"===this.type||"textarea"===this.type)&&!this.inputDisabled&&!this.readonly&&!this.showPassword},upperLimit:function(){return this.$attrs.maxlength},textLength:function(){return"number"==typeof this.value?String(this.value).length:(this.value||"").length},inputExceed:function(){return this.isWordLimitVisible&&this.textLength>this.upperLimit}},watch:{value:function(e){this.$nextTick(this.resizeTextarea),this.validateEvent&&this.dispatch("ElFormItem","el.form.change",[e])},nativeInputValue:function(){this.setNativeInputValue()},type:function(){var e=this;this.$nextTick((function(){e.setNativeInputValue(),e.resizeTextarea(),e.updateIconOffset()}))}},methods:{focus:function(){this.getInput().focus()},blur:function(){this.getInput().blur()},getMigratingConfig:function(){return{props:{icon:"icon is removed, use suffix-icon / prefix-icon instead.","on-icon-click":"on-icon-click is removed."},events:{click:"click is removed."}}},handleBlur:function(e){this.focused=!1,this.$emit("blur",e),this.validateEvent&&this.dispatch("ElFormItem","el.form.blur",[this.value])},select:function(){this.getInput().select()},resizeTextarea:function(){if(!this.$isServer){var e=this.autosize;if("textarea"===this.type)if(e){var t=e.minRows,n=e.maxRows;this.textareaCalcStyle=h(this.$refs.textarea,t,n)}else this.textareaCalcStyle={minHeight:h(this.$refs.textarea).minHeight}}},setNativeInputValue:function(){var e=this.getInput();e&&e.value!==this.nativeInputValue&&(e.value=this.nativeInputValue)},handleFocus:function(e){this.focused=!0,this.$emit("focus",e)},handleCompositionStart:function(e){this.$emit("compositionstart",e),this.isComposing=!0},handleCompositionUpdate:function(e){this.$emit("compositionupdate",e);var t=e.target.value,n=t[t.length-1]||"";this.isComposing=!Object(m.isKorean)(n)},handleCompositionEnd:function(e){this.$emit("compositionend",e),this.isComposing&&(this.isComposing=!1,this.handleInput(e))},handleInput:function(e){this.isComposing||e.target.value!==this.nativeInputValue&&(this.$emit("input",e.target.value),this.$nextTick(this.setNativeInputValue))},handleChange:function(e){this.$emit("change",e.target.value)},calcIconOffset:function(e){var t=[].slice.call(this.$el.querySelectorAll(".el-input__"+e)||[]);if(t.length){for(var n=null,i=0;i=t.length)break;r=t[i++]}else{if((i=t.next()).done)break;r=i.value}var o=r.target.__resizeListeners__||[];o.length&&o.forEach((function(e){e()}))}};t.addResizeListener=function(e,t){s||(e.__resizeListeners__||(e.__resizeListeners__=[],e.__ro__=new o.default((0,a.debounce)(16,l)),e.__ro__.observe(e)),e.__resizeListeners__.push(t))},t.removeResizeListener=function(e,t){e&&e.__resizeListeners__&&(e.__resizeListeners__.splice(e.__resizeListeners__.indexOf(t),1),e.__resizeListeners__.length||e.__ro__.disconnect())}},function(e,t){e.exports=function(e,t,n,i){var r,o=0;return"boolean"!=typeof t&&(i=n,n=t,t=void 0),function(){var a=this,s=Number(new Date)-o,l=arguments;function u(){o=Number(new Date),n.apply(a,l)}function c(){r=void 0}i&&!r&&u(),r&&clearTimeout(r),void 0===i&&s>e?u():!0!==t&&(r=setTimeout(i?c:u,void 0===i?e-s:e))}}},function(e,t,n){e.exports=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=133)}({133:function(e,t,n){"use strict";n.r(t);var i=n(16),r=n(39),o=n.n(r),a=n(3),s=n(2),l={vertical:{offset:"offsetHeight",scroll:"scrollTop",scrollSize:"scrollHeight",size:"height",key:"vertical",axis:"Y",client:"clientY",direction:"top"},horizontal:{offset:"offsetWidth",scroll:"scrollLeft",scrollSize:"scrollWidth",size:"width",key:"horizontal",axis:"X",client:"clientX",direction:"left"}};function u(e){var t=e.move,n=e.size,i=e.bar,r={},o="translate"+i.axis+"("+t+"%)";return r[i.size]=n,r.transform=o,r.msTransform=o,r.webkitTransform=o,r}var c={name:"Bar",props:{vertical:Boolean,size:String,move:Number},computed:{bar:function(){return l[this.vertical?"vertical":"horizontal"]},wrap:function(){return this.$parent.wrap}},render:function(e){var t=this.size,n=this.move,i=this.bar;return e("div",{class:["el-scrollbar__bar","is-"+i.key],on:{mousedown:this.clickTrackHandler}},[e("div",{ref:"thumb",class:"el-scrollbar__thumb",on:{mousedown:this.clickThumbHandler},style:u({size:t,move:n,bar:i})})])},methods:{clickThumbHandler:function(e){e.ctrlKey||2===e.button||(this.startDrag(e),this[this.bar.axis]=e.currentTarget[this.bar.offset]-(e[this.bar.client]-e.currentTarget.getBoundingClientRect()[this.bar.direction]))},clickTrackHandler:function(e){var t=100*(Math.abs(e.target.getBoundingClientRect()[this.bar.direction]-e[this.bar.client])-this.$refs.thumb[this.bar.offset]/2)/this.$el[this.bar.offset];this.wrap[this.bar.scroll]=t*this.wrap[this.bar.scrollSize]/100},startDrag:function(e){e.stopImmediatePropagation(),this.cursorDown=!0,Object(s.on)(document,"mousemove",this.mouseMoveDocumentHandler),Object(s.on)(document,"mouseup",this.mouseUpDocumentHandler),document.onselectstart=function(){return!1}},mouseMoveDocumentHandler:function(e){if(!1!==this.cursorDown){var t=this[this.bar.axis];if(t){var n=100*(-1*(this.$el.getBoundingClientRect()[this.bar.direction]-e[this.bar.client])-(this.$refs.thumb[this.bar.offset]-t))/this.$el[this.bar.offset];this.wrap[this.bar.scroll]=n*this.wrap[this.bar.scrollSize]/100}}},mouseUpDocumentHandler:function(e){this.cursorDown=!1,this[this.bar.axis]=0,Object(s.off)(document,"mousemove",this.mouseMoveDocumentHandler),document.onselectstart=null}},destroyed:function(){Object(s.off)(document,"mouseup",this.mouseUpDocumentHandler)}},d={name:"ElScrollbar",components:{Bar:c},props:{native:Boolean,wrapStyle:{},wrapClass:{},viewClass:{},viewStyle:{},noresize:Boolean,tag:{type:String,default:"div"}},data:function(){return{sizeWidth:"0",sizeHeight:"0",moveX:0,moveY:0}},computed:{wrap:function(){return this.$refs.wrap}},render:function(e){var t=o()(),n=this.wrapStyle;if(t){var i="-"+t+"px",r="margin-bottom: "+i+"; margin-right: "+i+";";Array.isArray(this.wrapStyle)?(n=Object(a.toObject)(this.wrapStyle)).marginRight=n.marginBottom=i:"string"==typeof this.wrapStyle?n+=r:n=r}var s=e(this.tag,{class:["el-scrollbar__view",this.viewClass],style:this.viewStyle,ref:"resize"},this.$slots.default),l=e("div",{ref:"wrap",style:n,on:{scroll:this.handleScroll},class:[this.wrapClass,"el-scrollbar__wrap",t?"":"el-scrollbar__wrap--hidden-default"]},[[s]]),u=void 0;return u=this.native?[e("div",{ref:"wrap",class:[this.wrapClass,"el-scrollbar__wrap"],style:n},[[s]])]:[l,e(c,{attrs:{move:this.moveX,size:this.sizeWidth}}),e(c,{attrs:{vertical:!0,move:this.moveY,size:this.sizeHeight}})],e("div",{class:"el-scrollbar"},u)},methods:{handleScroll:function(){var e=this.wrap;this.moveY=100*e.scrollTop/e.clientHeight,this.moveX=100*e.scrollLeft/e.clientWidth},update:function(){var e,t,n=this.wrap;n&&(e=100*n.clientHeight/n.scrollHeight,t=100*n.clientWidth/n.scrollWidth,this.sizeHeight=e<100?e+"%":"",this.sizeWidth=t<100?t+"%":"")}},mounted:function(){this.native||(this.$nextTick(this.update),!this.noresize&&Object(i.addResizeListener)(this.$refs.resize,this.update))},beforeDestroy:function(){this.native||!this.noresize&&Object(i.removeResizeListener)(this.$refs.resize,this.update)},install:function(e){e.component(d.name,d)}};t.default=d},16:function(e,t){e.exports=n(76)},2:function(e,t){e.exports=n(10)},3:function(e,t){e.exports=n(6)},39:function(e,t){e.exports=n(74)}})},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e){return{methods:{focus:function(){this.$refs[e].focus()}}}}},function(e,t,n){"use strict";t.__esModule=!0,t.default=function(e,t){if(o.default.prototype.$isServer)return;if(!t)return void(e.scrollTop=0);var n=[],i=t.offsetParent;for(;i&&e!==i&&e.contains(i);)n.push(i),i=i.offsetParent;var r=t.offsetTop+n.reduce((function(e,t){return e+t.offsetTop}),0),a=r+t.offsetHeight,s=e.scrollTop,l=s+e.clientHeight;rl&&(e.scrollTop=a-e.clientHeight)};var i,r=n(0),o=(i=r)&&i.__esModule?i:{default:i}},function(e,t,n){"use strict";t.__esModule=!0;var i=i||{};i.Utils=i.Utils||{},i.Utils.focusFirstDescendant=function(e){for(var t=0;t=0;t--){var n=e.childNodes[t];if(i.Utils.attemptFocus(n)||i.Utils.focusLastDescendant(n))return!0}return!1},i.Utils.attemptFocus=function(e){if(!i.Utils.isFocusable(e))return!1;i.Utils.IgnoreUtilFocusChanges=!0;try{e.focus()}catch(e){}return i.Utils.IgnoreUtilFocusChanges=!1,document.activeElement===e},i.Utils.isFocusable=function(e){if(e.tabIndex>0||0===e.tabIndex&&null!==e.getAttribute("tabIndex"))return!0;if(e.disabled)return!1;switch(e.nodeName){case"A":return!!e.href&&"ignore"!==e.rel;case"INPUT":return"hidden"!==e.type&&"file"!==e.type;case"BUTTON":case"SELECT":case"TEXTAREA":return!0;default:return!1}},i.Utils.triggerEvent=function(e,t){var n=void 0;n=/^mouse|click/.test(t)?"MouseEvents":/^key/.test(t)?"KeyboardEvent":"HTMLEvents";for(var i=document.createEvent(n),r=arguments.length,o=Array(r>2?r-2:0),a=2;a0?i:n)(e)}},function(e,t,n){var i=n(87)("keys"),r=n(46);e.exports=function(e){return i[e]||(i[e]=r(e))}},function(e,t,n){var i=n(27),r=n(12),o=r["__core-js_shared__"]||(r["__core-js_shared__"]={});(e.exports=function(e,t){return o[e]||(o[e]=void 0!==t?t:{})})("versions",[]).push({version:i.version,mode:n(45)?"pure":"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})},function(e,t){e.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(e,t){t.f=Object.getOwnPropertySymbols},function(e,t,n){var i=n(84);e.exports=function(e){return Object(i(e))}},function(e,t){e.exports={}},function(e,t,n){var i=n(21).f,r=n(17),o=n(23)("toStringTag");e.exports=function(e,t,n){e&&!r(e=n?e:e.prototype,o)&&i(e,o,{configurable:!0,value:t})}},function(e,t,n){t.f=n(23)},function(e,t,n){var i=n(12),r=n(27),o=n(45),a=n(93),s=n(21).f;e.exports=function(e){var t=r.Symbol||(r.Symbol=o?{}:i.Symbol||{});"_"==e.charAt(0)||e in t||s(t,e,{value:a.f(e)})}},function(e,t,n){"use strict";var i=n(7),r=n(50),o=n(164),a=n(52),s=n(53),l=n(99),u=n(11),c=n(109),d=Object.getOwnPropertyDescriptor;t.f=i?d:function(e,t){if(e=s(e),t=l(t),c)try{return d(e,t)}catch(e){}if(u(e,t))return a(!r(o.f,e,t),e[t])}},function(e,t,n){"use strict";var i=n(5),r=n(4),o=n(31),a=Object,s=i("".split);e.exports=r((function(){return!a("z").propertyIsEnumerable(0)}))?function(e){return"String"===o(e)?s(e,""):a(e)}:a},function(e,t,n){"use strict";var i=n(98),r=TypeError;e.exports=function(e){if(i(e))throw new r("Can't call method on "+e);return e}},function(e,t,n){"use strict";e.exports=function(e){return null==e}},function(e,t,n){"use strict";var i=n(165),r=n(101);e.exports=function(e){var t=i(e,"string");return r(t)?t:t+""}},function(e,t,n){"use strict";var i="object"==typeof document&&document.all,r=void 0===i&&void 0!==i;e.exports={all:i,IS_HTMLDDA:r}},function(e,t,n){"use strict";var i=n(54),r=n(1),o=n(102),a=n(103),s=Object;e.exports=a?function(e){return"symbol"==typeof e}:function(e){var t=i("Symbol");return r(t)&&o(t.prototype,s(e))}},function(e,t,n){"use strict";var i=n(5);e.exports=i({}.isPrototypeOf)},function(e,t,n){"use strict";var i=n(104);e.exports=i&&!Symbol.sham&&"symbol"==typeof Symbol.iterator},function(e,t,n){"use strict";var i=n(105),r=n(4),o=n(2).String;e.exports=!!Object.getOwnPropertySymbols&&!r((function(){var e=Symbol("symbol detection");return!o(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&i&&i<41}))},function(e,t,n){"use strict";var i,r,o=n(2),a=n(166),s=o.process,l=o.Deno,u=s&&s.versions||l&&l.version,c=u&&u.v8;c&&(r=(i=c.split("."))[0]>0&&i[0]<4?1:+(i[0]+i[1])),!r&&a&&(!(i=a.match(/Edge\/(\d+)/))||i[1]>=74)&&(i=a.match(/Chrome\/(\d+)/))&&(r=+i[1]),e.exports=r},function(e,t,n){"use strict";var i=n(107),r=n(57);(e.exports=function(e,t){return r[e]||(r[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.33.1",mode:i?"pure":"global",copyright:"© 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.33.1/LICENSE",source:"https://github.com/zloirock/core-js"})},function(e,t,n){"use strict";e.exports=!1},function(e,t,n){"use strict";var i=n(5),r=0,o=Math.random(),a=i(1..toString);e.exports=function(e){return"Symbol("+(void 0===e?"":e)+")_"+a(++r+o,36)}},function(e,t,n){"use strict";var i=n(7),r=n(4),o=n(170);e.exports=!i&&!r((function(){return 7!==Object.defineProperty(o("div"),"a",{get:function(){return 7}}).a}))},function(e,t,n){"use strict";e.exports={}},function(e,t,n){"use strict";var i=n(11),r=n(179),o=n(95),a=n(32);e.exports=function(e,t,n){for(var s=r(t),l=a.f,u=o.f,c=0;cc))return!1;var h=l.get(e),f=l.get(t);if(h&&f)return h==t&&f==e;var p=-1,m=!0,v=2&n?new i:void 0;for(l.set(e,t),l.set(t,e);++p-1&&e%1==0&&e3?0:(e-e%10!=10)*e%10]}};var g={D:function(e){return e.getDay()},DD:function(e){return h(e.getDay())},Do:function(e,t){return t.DoFn(e.getDate())},d:function(e){return e.getDate()},dd:function(e){return h(e.getDate())},ddd:function(e,t){return t.dayNamesShort[e.getDay()]},dddd:function(e,t){return t.dayNames[e.getDay()]},M:function(e){return e.getMonth()+1},MM:function(e){return h(e.getMonth()+1)},MMM:function(e,t){return t.monthNamesShort[e.getMonth()]},MMMM:function(e,t){return t.monthNames[e.getMonth()]},yy:function(e){return h(String(e.getFullYear()),4).substr(2)},yyyy:function(e){return h(e.getFullYear(),4)},h:function(e){return e.getHours()%12||12},hh:function(e){return h(e.getHours()%12||12)},H:function(e){return e.getHours()},HH:function(e){return h(e.getHours())},m:function(e){return e.getMinutes()},mm:function(e){return h(e.getMinutes())},s:function(e){return e.getSeconds()},ss:function(e){return h(e.getSeconds())},S:function(e){return Math.round(e.getMilliseconds()/100)},SS:function(e){return h(Math.round(e.getMilliseconds()/10),2)},SSS:function(e){return h(e.getMilliseconds(),3)},a:function(e,t){return e.getHours()<12?t.amPm[0]:t.amPm[1]},A:function(e,t){return e.getHours()<12?t.amPm[0].toUpperCase():t.amPm[1].toUpperCase()},ZZ:function(e){var t=e.getTimezoneOffset();return(t>0?"-":"+")+h(100*Math.floor(Math.abs(t)/60)+Math.abs(t)%60,4)}},b={d:["\\d\\d?",function(e,t){e.day=t}],Do:["\\d\\d?"+s,function(e,t){e.day=parseInt(t,10)}],M:["\\d\\d?",function(e,t){e.month=t-1}],yy:["\\d\\d?",function(e,t){var n=+(""+(new Date).getFullYear()).substr(0,2);e.year=""+(t>68?n-1:n)+t}],h:["\\d\\d?",function(e,t){e.hour=t}],m:["\\d\\d?",function(e,t){e.minute=t}],s:["\\d\\d?",function(e,t){e.second=t}],yyyy:["\\d{4}",function(e,t){e.year=t}],S:["\\d",function(e,t){e.millisecond=100*t}],SS:["\\d{2}",function(e,t){e.millisecond=10*t}],SSS:["\\d{3}",function(e,t){e.millisecond=t}],D:["\\d\\d?",u],ddd:[s,u],MMM:[s,d("monthNamesShort")],MMMM:[s,d("monthNames")],a:[s,function(e,t,n){var i=t.toLowerCase();i===n.amPm[0]?e.isPm=!1:i===n.amPm[1]&&(e.isPm=!0)}],ZZ:["[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z",function(e,t){var n,i=(t+"").match(/([+-]|\d\d)/gi);i&&(n=60*i[1]+parseInt(i[2],10),e.timezoneOffset="+"===i[0]?n:-n)}]};b.dd=b.d,b.dddd=b.ddd,b.DD=b.D,b.mm=b.m,b.hh=b.H=b.HH=b.h,b.MM=b.M,b.ss=b.s,b.A=b.a,o.masks={default:"ddd MMM dd yyyy HH:mm:ss",shortDate:"M/D/yy",mediumDate:"MMM d, yyyy",longDate:"MMMM d, yyyy",fullDate:"dddd, MMMM d, yyyy",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"},o.format=function(e,t,n){var i=n||o.i18n;if("number"==typeof e&&(e=new Date(e)),"[object Date]"!==Object.prototype.toString.call(e)||isNaN(e.getTime()))throw new Error("Invalid Date in fecha.format");t=o.masks[t]||t||o.masks.default;var r=[];return(t=(t=t.replace(l,(function(e,t){return r.push(t),"@@@"}))).replace(a,(function(t){return t in g?g[t](e,i):t.slice(1,t.length-1)}))).replace(/@@@/g,(function(){return r.shift()}))},o.parse=function(e,t,n){var i=n||o.i18n;if("string"!=typeof t)throw new Error("Invalid format in fecha.parse");if(t=o.masks[t]||t,e.length>1e3)return null;var r={},s=[],u=[];t=t.replace(l,(function(e,t){return u.push(t),"@@@"}));var c,d=(c=t,c.replace(/[|\\{()[^$+*?.-]/g,"\\$&")).replace(a,(function(e){if(b[e]){var t=b[e];return s.push(t[1]),"("+t[0]+")"}return e}));d=d.replace(/@@@/g,(function(){return u.shift()}));var h=e.match(new RegExp(d,"i"));if(!h)return null;for(var f=1;f0?this._openTimer=setTimeout((function(){t._openTimer=null,t.doOpen(n)}),i):this.doOpen(n)},doOpen:function(e){if(!this.$isServer&&(!this.willOpen||this.willOpen())&&!this.opened){this._opening=!0;var t=this.$el,n=e.modal,i=e.zIndex;if(i&&(o.default.zIndex=i),n&&(this._closing&&(o.default.closeModal(this._popupId),this._closing=!1),o.default.openModal(this._popupId,o.default.nextZIndex(),this.modalAppendToBody?void 0:t,e.modalClass,e.modalFade),e.lockScroll)){this.withoutHiddenClass=!(0,s.hasClass)(document.body,"el-popup-parent--hidden"),this.withoutHiddenClass&&(this.bodyPaddingRight=document.body.style.paddingRight,this.computedBodyPaddingRight=parseInt((0,s.getStyle)(document.body,"paddingRight"),10)),c=(0,a.default)();var r=document.documentElement.clientHeight0&&(r||"scroll"===l)&&this.withoutHiddenClass&&(document.body.style.paddingRight=this.computedBodyPaddingRight+c+"px"),(0,s.addClass)(document.body,"el-popup-parent--hidden")}"static"===getComputedStyle(t).position&&(t.style.position="absolute"),t.style.zIndex=o.default.nextZIndex(),this.opened=!0,this.onOpen&&this.onOpen(),this.doAfterOpen()}},doAfterOpen:function(){this._opening=!1},close:function(){var e=this;if(!this.willClose||this.willClose()){null!==this._openTimer&&(clearTimeout(this._openTimer),this._openTimer=null),clearTimeout(this._closeTimer);var t=Number(this.closeDelay);t>0?this._closeTimer=setTimeout((function(){e._closeTimer=null,e.doClose()}),t):this.doClose()}},doClose:function(){this._closing=!0,this.onClose&&this.onClose(),this.lockScroll&&setTimeout(this.restoreBodyStyle,200),this.opened=!1,this.doAfterClose()},doAfterClose:function(){o.default.closeModal(this._popupId),this._closing=!1},restoreBodyStyle:function(){this.modal&&this.withoutHiddenClass&&(document.body.style.paddingRight=this.bodyPaddingRight,(0,s.removeClass)(document.body,"el-popup-parent--hidden")),this.withoutHiddenClass=!0}}},t.PopupManager=o.default},function(e,t,n){"use strict";t.__esModule=!0;n(6);t.default={mounted:function(){},methods:{getMigratingConfig:function(){return{props:{},events:{}}}}}},function(e,t,n){"use strict";t.__esModule=!0;var i,r=n(0),o=(i=r)&&i.__esModule?i:{default:i},a=n(10);var s=[],l="@@clickoutsideContext",u=void 0,c=0;function d(e,t,n){return function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!(n&&n.context&&i.target&&r.target)||e.contains(i.target)||e.contains(r.target)||e===i.target||n.context.popperElm&&(n.context.popperElm.contains(i.target)||n.context.popperElm.contains(r.target))||(t.expression&&e[l].methodName&&n.context[e[l].methodName]?n.context[e[l].methodName]():e[l].bindingFn&&e[l].bindingFn())}}!o.default.prototype.$isServer&&(0,a.on)(document,"mousedown",(function(e){return u=e})),!o.default.prototype.$isServer&&(0,a.on)(document,"mouseup",(function(e){s.forEach((function(t){return t[l].documentHandler(e,u)}))})),t.default={bind:function(e,t,n){s.push(e);var i=c++;e[l]={id:i,documentHandler:d(e,t,n),methodName:t.expression,bindingFn:t.value}},update:function(e,t,n){e[l].documentHandler=d(e,t,n),e[l].methodName=t.expression,e[l].bindingFn=t.value},unbind:function(e){for(var t=s.length,n=0;n-1:e._q(e.model,e.trueLabel)},on:{change:[function(t){var n=e.model,i=t.target,r=i.checked?e.trueLabel:e.falseLabel;if(Array.isArray(n)){var o=e._i(n,null);i.checked?o<0&&(e.model=n.concat([null])):o>-1&&(e.model=n.slice(0,o).concat(n.slice(o+1)))}else e.model=r},e.handleChange],focus:function(t){e.focus=!0},blur:function(t){e.focus=!1}}}):n("input",{directives:[{name:"model",rawName:"v-model",value:e.model,expression:"model"}],staticClass:"el-checkbox__original",attrs:{type:"checkbox","aria-hidden":e.indeterminate?"true":"false",disabled:e.isDisabled,name:e.name},domProps:{value:e.label,checked:Array.isArray(e.model)?e._i(e.model,e.label)>-1:e.model},on:{change:[function(t){var n=e.model,i=t.target,r=!!i.checked;if(Array.isArray(n)){var o=e.label,a=e._i(n,o);i.checked?a<0&&(e.model=n.concat([o])):a>-1&&(e.model=n.slice(0,a).concat(n.slice(a+1)))}else e.model=r},e.handleChange],focus:function(t){e.focus=!0},blur:function(t){e.focus=!1}}})]),e.$slots.default||e.label?n("span",{staticClass:"el-checkbox__label"},[e._t("default"),e.$slots.default?e._e():[e._v(e._s(e.label))]],2):e._e()])};i._withStripped=!0;var r=n(4),o={name:"ElCheckbox",mixins:[n.n(r).a],inject:{elForm:{default:""},elFormItem:{default:""}},componentName:"ElCheckbox",data:function(){return{selfModel:!1,focus:!1,isLimitExceeded:!1}},computed:{model:{get:function(){return this.isGroup?this.store:void 0!==this.value?this.value:this.selfModel},set:function(e){this.isGroup?(this.isLimitExceeded=!1,void 0!==this._checkboxGroup.min&&e.lengththis._checkboxGroup.max&&(this.isLimitExceeded=!0),!1===this.isLimitExceeded&&this.dispatch("ElCheckboxGroup","input",[e])):(this.$emit("input",e),this.selfModel=e)}},isChecked:function(){return"[object Boolean]"==={}.toString.call(this.model)?this.model:Array.isArray(this.model)?this.model.indexOf(this.label)>-1:null!==this.model&&void 0!==this.model?this.model===this.trueLabel:void 0},isGroup:function(){for(var e=this.$parent;e;){if("ElCheckboxGroup"===e.$options.componentName)return this._checkboxGroup=e,!0;e=e.$parent}return!1},store:function(){return this._checkboxGroup?this._checkboxGroup.value:this.value},isLimitDisabled:function(){var e=this._checkboxGroup,t=e.max,n=e.min;return!(!t&&!n)&&this.model.length>=t&&!this.isChecked||this.model.length<=n&&this.isChecked},isDisabled:function(){return this.isGroup?this._checkboxGroup.disabled||this.disabled||(this.elForm||{}).disabled||this.isLimitDisabled:this.disabled||(this.elForm||{}).disabled},_elFormItemSize:function(){return(this.elFormItem||{}).elFormItemSize},checkboxSize:function(){var e=this.size||this._elFormItemSize||(this.$ELEMENT||{}).size;return this.isGroup&&this._checkboxGroup.checkboxGroupSize||e}},props:{value:{},label:{},indeterminate:Boolean,disabled:Boolean,checked:Boolean,name:String,trueLabel:[String,Number],falseLabel:[String,Number],id:String,controls:String,border:Boolean,size:String},methods:{addToStore:function(){Array.isArray(this.model)&&-1===this.model.indexOf(this.label)?this.model.push(this.label):this.model=this.trueLabel||!0},handleChange:function(e){var t=this;if(!this.isLimitExceeded){var n=void 0;n=e.target.checked?void 0===this.trueLabel||this.trueLabel:void 0!==this.falseLabel&&this.falseLabel,this.$emit("change",n,e),this.$nextTick((function(){t.isGroup&&t.dispatch("ElCheckboxGroup","change",[t._checkboxGroup.value])}))}}},created:function(){this.checked&&this.addToStore()},mounted:function(){this.indeterminate&&this.$el.setAttribute("aria-controls",this.controls)},watch:{value:function(e){this.dispatch("ElFormItem","el.form.change",e)}}},a=n(0),s=Object(a.a)(o,i,[],!1,null,null,null);s.options.__file="packages/checkbox/src/checkbox.vue";var l=s.exports;l.install=function(e){e.component(l.name,l)};t.default=l}})},function(e,t,n){var i=n(77),r=n(41);e.exports={throttle:i,debounce:r}},function(e,t){var n=/^(attrs|props|on|nativeOn|class|style|hook)$/;function i(e,t){return function(){e&&e.apply(this,arguments),t&&t.apply(this,arguments)}}e.exports=function(e){return e.reduce((function(e,t){var r,o,a,s,l;for(a in t)if(r=e[a],o=t[a],r&&n.test(a))if("class"===a&&("string"==typeof r&&(l=r,e[a]=r={},r[l]=!0),"string"==typeof o&&(l=o,t[a]=o={},o[l]=!0)),"on"===a||"nativeOn"===a||"hook"===a)for(s in o)r[s]=i(r[s],o[s]);else if(Array.isArray(r))e[a]=r.concat(o);else if(Array.isArray(o))e[a]=[r].concat(o);else for(s in o)r[s]=o[s];else e[a]=t[a];return e}),{})}},function(e,t){(function(t){e.exports=t}).call(this,{})},function(e,t,n){e.exports=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=132)}({0:function(e,t,n){"use strict";function i(e,t,n,i,r,o,a,s){var l,u="function"==typeof e?e.options:e;if(t&&(u.render=t,u.staticRenderFns=n,u._compiled=!0),i&&(u.functional=!0),o&&(u._scopeId="data-v-"+o),a?(l=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),r&&r.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(a)},u._ssrRegister=l):r&&(l=s?function(){r.call(this,this.$root.$options.shadowRoot)}:r),l)if(u.functional){u._injectStyles=l;var c=u.render;u.render=function(e,t){return l.call(t),c(e,t)}}else{var d=u.beforeCreate;u.beforeCreate=d?[].concat(d,l):[l]}return{exports:e,options:u}}n.d(t,"a",(function(){return i}))},132:function(e,t,n){"use strict";n.r(t);var i={name:"ElTag",props:{text:String,closable:Boolean,type:String,hit:Boolean,disableTransitions:Boolean,color:String,size:String,effect:{type:String,default:"light",validator:function(e){return-1!==["dark","light","plain"].indexOf(e)}}},methods:{handleClose:function(e){e.stopPropagation(),this.$emit("close",e)},handleClick:function(e){this.$emit("click",e)}},computed:{tagSize:function(){return this.size||(this.$ELEMENT||{}).size}},render:function(e){var t=this.type,n=this.tagSize,i=this.hit,r=this.effect,o=e("span",{class:["el-tag",t?"el-tag--"+t:"",n?"el-tag--"+n:"",r?"el-tag--"+r:"",i&&"is-hit"],style:{backgroundColor:this.color},on:{click:this.handleClick}},[this.$slots.default,this.closable&&e("i",{class:"el-tag__close el-icon-close",on:{click:this.handleClose}})]);return this.disableTransitions?o:e("transition",{attrs:{name:"el-zoom-in-center"}},[o])}},r=n(0),o=Object(r.a)(i,void 0,void 0,!1,null,null,null);o.options.__file="packages/tag/src/tag.vue";var a=o.exports;a.install=function(e){e.component(a.name,a)};t.default=a}})},function(e,t,n){e.exports=!n(16)&&!n(29)((function(){return 7!=Object.defineProperty(n(145)("div"),"a",{get:function(){return 7}}).a}))},function(e,t,n){var i=n(28),r=n(12).document,o=i(r)&&i(r.createElement);e.exports=function(e){return o?r.createElement(e):{}}},function(e,t,n){var i=n(17),r=n(22),o=n(334)(!1),a=n(86)("IE_PROTO");e.exports=function(e,t){var n,s=r(e),l=0,u=[];for(n in s)n!=a&&i(s,n)&&u.push(n);for(;t.length>l;)i(s,n=t[l++])&&(~o(u,n)||u.push(n));return u}},function(e,t,n){var i=n(148);e.exports=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==i(e)?e.split(""):Object(e)}},function(e,t){var n={}.toString;e.exports=function(e){return n.call(e).slice(8,-1)}},function(e,t,n){"use strict";var i=n(45),r=n(82),o=n(150),a=n(20),s=n(91),l=n(341),u=n(92),c=n(344),d=n(23)("iterator"),h=!([].keys&&"next"in[].keys()),f=function(){return this};e.exports=function(e,t,n,p,m,v,g){l(n,t,p);var b,y,_,x=function(e){if(!h&&e in S)return S[e];switch(e){case"keys":case"values":return function(){return new n(this,e)}}return function(){return new n(this,e)}},w=t+" Iterator",C="values"==m,k=!1,S=e.prototype,O=S[d]||S["@@iterator"]||m&&S[m],E=O||x(m),$=m?C?x("entries"):E:void 0,D="Array"==t&&S.entries||O;if(D&&(_=c(D.call(new e)))!==Object.prototype&&_.next&&(u(_,w,!0),i||"function"==typeof _[d]||a(_,d,f)),C&&O&&"values"!==O.name&&(k=!0,E=function(){return O.call(this)}),i&&!g||!h&&!k&&S[d]||a(S,d,E),s[t]=E,s[w]=f,m)if(b={values:C?E:x("values"),keys:v?E:x("keys"),entries:$},g)for(y in b)y in S||o(S,y,b[y]);else r(r.P+r.F*(h||k),t,b);return b}},function(e,t,n){e.exports=n(20)},function(e,t,n){var i=n(42),r=n(342),o=n(88),a=n(86)("IE_PROTO"),s=function(){},l=function(){var e,t=n(145)("iframe"),i=o.length;for(t.style.display="none",n(343).appendChild(t),t.src="javascript:",(e=t.contentWindow.document).open(),e.write(" +
作者:2xiao
+ diff --git a/fe/index.html b/fe/index.html index 7de72e4f07..5e905d6bc6 100644 --- a/fe/index.html +++ b/fe/index.html @@ -8,7 +8,7 @@ - + @@ -17,7 +17,7 @@ (opens new window)

# 前端与工作

本部分内容将带你走过前端工程师的学习路径,包括:

开始阅读 ->

- +
作者:2xiao
+ diff --git a/index.html b/index.html index 296f861add..fe0d0aca7e 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - + @@ -24,7 +24,7 @@ 开始阅读 →
- +
+ diff --git a/leetcode/algorithm/0_enumeration.html b/leetcode/algorithm/0_enumeration.html index e787a3ca5c..db6541c499 100644 --- a/leetcode/algorithm/0_enumeration.html +++ b/leetcode/algorithm/0_enumeration.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 3.2 递归算法 → -

- +

+ diff --git a/leetcode/algorithm/10_slide_window.html b/leetcode/algorithm/10_slide_window.html index f2e0f1e90c..a8f3626018 100644 --- a/leetcode/algorithm/10_slide_window.html +++ b/leetcode/algorithm/10_slide_window.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 索引 → -

- +

+ diff --git a/leetcode/algorithm/1_recursion.html b/leetcode/algorithm/1_recursion.html index ef7bbde5e0..4cb0994e69 100644 --- a/leetcode/algorithm/1_recursion.html +++ b/leetcode/algorithm/1_recursion.html @@ -8,7 +8,7 @@ - + @@ -29,7 +29,7 @@ 3.3 分治算法 → -

- +

+ diff --git a/leetcode/algorithm/2_divide_conquer.html b/leetcode/algorithm/2_divide_conquer.html index 52a121c293..418b832298 100644 --- a/leetcode/algorithm/2_divide_conquer.html +++ b/leetcode/algorithm/2_divide_conquer.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 3.4 回溯算法 → -

- +

+ diff --git a/leetcode/algorithm/3_backtracking.html b/leetcode/algorithm/3_backtracking.html index 93882970ad..6be7649ce8 100644 --- a/leetcode/algorithm/3_backtracking.html +++ b/leetcode/algorithm/3_backtracking.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 3.5 贪心算法 → -

- +

+ diff --git a/leetcode/algorithm/4_greed.html b/leetcode/algorithm/4_greed.html index aec835f207..0dae53f375 100644 --- a/leetcode/algorithm/4_greed.html +++ b/leetcode/algorithm/4_greed.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 3.6 动态规划 → -

- +

+ diff --git a/leetcode/algorithm/5_dynamic_programming.html b/leetcode/algorithm/5_dynamic_programming.html index b0afc52bd0..83db923ba6 100644 --- a/leetcode/algorithm/5_dynamic_programming.html +++ b/leetcode/algorithm/5_dynamic_programming.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 3.7 位运算 → -

- +

+ diff --git a/leetcode/algorithm/6_bit.html b/leetcode/algorithm/6_bit.html index 5ed0aae147..633009e7cc 100644 --- a/leetcode/algorithm/6_bit.html +++ b/leetcode/algorithm/6_bit.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 3.8 排序算法 → -

- +

+ diff --git a/leetcode/algorithm/7_sort.html b/leetcode/algorithm/7_sort.html index 6417ac610f..9e0dae5026 100644 --- a/leetcode/algorithm/7_sort.html +++ b/leetcode/algorithm/7_sort.html @@ -8,7 +8,7 @@ - + @@ -152,7 +152,7 @@ 3.9 二分查找 → -

- +

+ diff --git a/leetcode/algorithm/8_binary_search.html b/leetcode/algorithm/8_binary_search.html index f52455b304..3d20ddee8d 100644 --- a/leetcode/algorithm/8_binary_search.html +++ b/leetcode/algorithm/8_binary_search.html @@ -8,7 +8,7 @@ - + @@ -128,7 +128,7 @@ 3.10 双指针 → -

- +

+ diff --git a/leetcode/algorithm/9_two_pointer.html b/leetcode/algorithm/9_two_pointer.html index fd02841e77..24ffdf8ba4 100644 --- a/leetcode/algorithm/9_two_pointer.html +++ b/leetcode/algorithm/9_two_pointer.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 3.11 滑动窗口 → -

- +

+ diff --git a/leetcode/ds/0_array.html b/leetcode/ds/0_array.html index 5da094cf45..3fff1394c6 100644 --- a/leetcode/ds/0_array.html +++ b/leetcode/ds/0_array.html @@ -8,7 +8,7 @@ - + @@ -16,7 +16,7 @@ Github (opens new window)

# 2.1 数组

# 数组的定义

数组(Array)是一种线性表数据结构。它用一组连续的内存空间,来存储一组具有相同类型的数据。

// 一维数组:
+     (opens new window)    

# 2.1 数组

# 数组的定义

**数组(Array)**是一种线性表数据结构。它用一组连续的内存空间,来存储一组具有相同类型的数据。

// 一维数组:
 // 数组的每一个元素是一个数据类型
 [1, 2, 3]
 
@@ -45,7 +45,7 @@
           2.2 链表
         
         →
-      

- +

+ diff --git a/leetcode/ds/1_linked_list.html b/leetcode/ds/1_linked_list.html index d14b351557..bf32c947a6 100644 --- a/leetcode/ds/1_linked_list.html +++ b/leetcode/ds/1_linked_list.html @@ -8,7 +8,7 @@ - + @@ -154,7 +154,7 @@ 2.3 栈 → -

- +

+ diff --git a/leetcode/ds/2_stack.html b/leetcode/ds/2_stack.html index aa697f63c1..8f6d8659eb 100644 --- a/leetcode/ds/2_stack.html +++ b/leetcode/ds/2_stack.html @@ -8,7 +8,7 @@ - + @@ -97,7 +97,7 @@ 2.4 队列 → -

- +

+ diff --git a/leetcode/ds/3_queue.html b/leetcode/ds/3_queue.html index f4f5782f12..b7a7310cab 100644 --- a/leetcode/ds/3_queue.html +++ b/leetcode/ds/3_queue.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 2.5 哈希表 → -

- +

+ diff --git a/leetcode/ds/4_hash_table.html b/leetcode/ds/4_hash_table.html index cca8a976f8..14406533e7 100644 --- a/leetcode/ds/4_hash_table.html +++ b/leetcode/ds/4_hash_table.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 2.6 字符串 → -

- +

+ diff --git a/leetcode/ds/5_string.html b/leetcode/ds/5_string.html index 963515f915..70011a4db2 100644 --- a/leetcode/ds/5_string.html +++ b/leetcode/ds/5_string.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 2.7 树 → -

- +

+ diff --git a/leetcode/ds/6_tree.html b/leetcode/ds/6_tree.html index d7e55b94e4..512b1edd29 100644 --- a/leetcode/ds/6_tree.html +++ b/leetcode/ds/6_tree.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 2.8 图 → -

- +

+ diff --git a/leetcode/ds/7_graph.html b/leetcode/ds/7_graph.html index 3c8ee17ec9..787010c897 100644 --- a/leetcode/ds/7_graph.html +++ b/leetcode/ds/7_graph.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 3.1 枚举算法 → -

- +

+ diff --git a/leetcode/index.html b/leetcode/index.html index 4e7ae3bbb5..5375efad81 100644 --- a/leetcode/index.html +++ b/leetcode/index.html @@ -8,7 +8,7 @@ - + @@ -21,7 +21,7 @@ 1.1 数据结构与算法 → -

- +

+ diff --git a/leetcode/outline/0_table.html b/leetcode/outline/0_table.html index b086619b21..d5e5fae75d 100644 --- a/leetcode/outline/0_table.html +++ b/leetcode/outline/0_table.html @@ -8,7 +8,7 @@ - + @@ -16,7 +16,7 @@ Github (opens new window)

# 1.1 数据结构与算法

首先我们来明确一下数据结构与算法的定义。

从广义上讲,数据结构就是指一组数据的存储结构,算法就是操作数据的一组方法。

从狭义上讲,也就是本书要讲的,是指某些经典的数据结构和算法,比如队列、栈、堆、二分查找、动态规划等。这些都是前人从实际操作场景中抽象出来的,经过非常多的求证和检验,可以高效地帮助我们解决实际的开发问题。

# 如何学习

数据结构与算法涵盖的内容很多,要如何高效地系统性学习呢?

你并不需要掌握图里面的所有知识点。很多高级的数据结构与算法,比如二分图、最大流等,在我们平常的开发中很少会用到。

我总结了 19 个最常用、最基础的数据结构与算法,不管是应付面试还是工作需要,只要集中精力逐一攻克这 19 个知识点就足够了。

我对每个知识点都做了精讲,并配有对应的 LeetCode 题目,可以帮你打下扎实的基础,形成自己的知识体系。

想要对数据结构和算法有更全面的认识,可以查看这张思维导图,里面几乎涵盖了所有数据结构和算法书籍中都会讲到的知识点。

# 如何刷题

LeetCode 题目虽然多,但如果分类别来看,其实也没多少,很多题目都是类似的套路和延伸。

对于计算机基础不扎实的同学,如果按照高频顺序刷题,通过每道题反向获取知识,这样的方法不是不可以,但效率可能不高,还会造成知识零散化,不能融会贯通。

建议采用“分类知识学习 + 核心题目 + 反复训练 + 融会贯通”的系统性学习方法。

我整理了 高频面试题(按分类排序)LeetCode 题解(分类),建议先从这些题入手,分类别练习,点击标题可以跳转到LeetCode对应答题页面,点击题解(JS)可以查看我的答题思路和代码,遇到不熟悉的知识点可以去对应的知识点精讲学习。

掌握了这十几种常见算法类型的基本原理和思路,就对数据结构与算法有了一个大体的了解,即便出现很多新题,大多也能用现有知识体系去化解。

对算法模板、数据结构形成初步的认识之后,可以再结合 高频面试题(按频次排序)高频面试题(按公司排序)LeetCode 题解 多加练习,逐渐提升自己对答题思路的掌握,和对内在原理的领悟。

电影《师父》里面有一句话:「每日挥刀五百下,这个数管住了我。」

成功往往来自于,把简单、正确的事情重复做,不相信也不追求快速而一劳永逸的必胜之法。

想要通关 LeetCode,没有什么神奇的方法,最重要还是自己动手刷题。

多花时间思考怎么 AC 手上的题目,少花时间幻想走了多少进度条。

- +

+ diff --git a/leetcode/outline/1_complexity.html b/leetcode/outline/1_complexity.html index dd5c2f4d17..2af2fca880 100644 --- a/leetcode/outline/1_complexity.html +++ b/leetcode/outline/1_complexity.html @@ -8,7 +8,7 @@ - + @@ -16,7 +16,7 @@ Github (opens new window)

# 1.2 复杂度分析

想要学习数据结构与算法,首先要掌握一个最重要的概念——复杂度分析,它可以帮我们分析如何更省、更快地存储和处理数据。

# 时间复杂度

算法的时间复杂度(time complexity)是一个函数,它定性描述该算法的运行时间。用于评估执行程序所消耗的时间,可以估算出程序对处理器的使用程度。

时间复杂度常用大O符号表述,使用这种方式时,时间复杂度可被称为是渐近的,亦即考察输入值大小趋近无穷时的情况。

相同大小的不同输入值仍可能造成算法的执行时间不同,因此我们通常使用算法的最坏情况复杂度,记为 T(n) ,定义为任何大小的输入 n 所需的最大执行时间。

以下是一些最常用的 大O标记法 列表以及它们与不同大小输入数据的性能比较。

大O标记法 计算10个元素 计算100个元素 计算1000个元素
O(1) 1 1 1
O(log N) 3 6 9
O(N) 10 100 1000
O(N log N) 30 600 9000
O(N^2) 100 10000 1000000
O(2^N) 1024 1.26e+29 1.07e+301
O(N!) 3628800 9.3e+157 4.02e+2567

# 数据结构操作的复杂性

数据结构 连接 查找 插入 删除 备注
数组 1 n n n
n n 1 1
队列 n n 1 1
链表 n n 1 1
哈希表 - n n n 在完全哈希函数情况下,复杂度是 O(1)
二分查找树 n n n n 在平衡树情况下,复杂度是 O(log(n))
B 树 log(n) log(n) log(n) log(n)
红黑树 log(n) log(n) log(n) log(n)
AVL 树 log(n) log(n) log(n) log(n)
布隆过滤器 - 1 1 - 存在一定概率的判断错误(误判成存在)

# 数组排序算法的复杂性

名称 最优 平均 最坏 内存 稳定 备注
冒泡排序 n n^2 n^2 1 Yes
插入排序 n n^2 n^2 1 Yes
选择排序 n^2 n^2 n^2 1 No
堆排序 n log(n) n log(n) n log(n) 1 No
归并排序 n log(n) n log(n) n log(n) n Yes
快速排序 n log(n) n log(n) n^2 log(n) No 在 in-place 版本下,内存复杂度通常是 O(log(n))
希尔排序 n log(n) 取决于差距序列 n (log(n))^2 1 No
计数排序 n + r n + r n + r n + r Yes r - 数组里最大的数
基数排序 n * k n * k n * k n + k Yes k - 最长 key 的升序

# 分析复杂度的一些规则

  • 多个时间复杂度相加,如果都是与n相关,则取取复杂度高的那一个,例如:O(nlogn + n) = O(nlogn),O(nlogn + n^2) = O(n^2)
  • 多个时间复杂度相加,如果其中有些项的复杂度和n不相关则不能忽略任何项,例如:O(AlogA + B),O(AlogA + B^2)
  • 两个循环依次执行,则取复杂度高的那个,嵌套多个循环则需要累乘复杂度。

一个时间复杂度分析的例子:

有一个字符串数组,将数组中的每个字符串按照字母排序,然后在将整个字符串数组按照字典顺序排序。求整个操作的时间复杂度。

  • 我们来分析一下,假设最长字符串的长度是s,数组中有n个字符串。

  • 对每个字符串排序 O(slogs),将数组中的每个字符串按照字母排序O(n * slogs)

  • 将整个字符串数组按字典排序 O(s * nlogn)

  • 所以最后的时间复杂度是O(n * slogs) + O(s * nlogn) = O(nslogs + nslogn) = O(ns * (logs+logn))

# 时间复杂度优化

  • 采用更好的算法:举例:1+2+3...n1~n 求和,直接循环法,for i->n: sum+=i ,我们也可以用求和公式: n(n+1)/2;有些问题可以用二分查找等。
  • 空间换时间,比如用set 或map 加快查找的速度,用二叉搜索树或者字典树加快字符串的搜索。

# 空间复杂度

空间复杂度(Space Complexity)指的是算法在运行过程中所占存储空间的大小,依然使用大O来表示。用于评估执行程序所占用的内存空间,可以估算出程序对计算机内存的使用程度。

# 常见的空间复杂度

  • 一维数组空间,如果存储了n个元素,空间复杂度O(n)
  • 二维数组空间,总共有n个数组,每个数组存储了n个元素,空间复杂度O(n^2)
  • 常数空间复杂度O(1)
- +

+ diff --git a/leetcode/outline/2_solution_list.html b/leetcode/outline/2_solution_list.html index d86a5c7a78..31a06b453b 100644 --- a/leetcode/outline/2_solution_list.html +++ b/leetcode/outline/2_solution_list.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 1.4 LeetCode 题解(分类 ★★★) → -

- +

+ diff --git a/leetcode/outline/3_categories_list.html b/leetcode/outline/3_categories_list.html index 27f97e3fe8..af30a68848 100644 --- a/leetcode/outline/3_categories_list.html +++ b/leetcode/outline/3_categories_list.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 1.5 高频面试题(按分类排序) → -

- +

+ diff --git a/leetcode/outline/4_top_200_list.html b/leetcode/outline/4_top_200_list.html index 5850541b74..8c474be05f 100644 --- a/leetcode/outline/4_top_200_list.html +++ b/leetcode/outline/4_top_200_list.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 1.6 高频面试题(按频次排序) → -

- +

+ diff --git a/leetcode/outline/5_frequency_list.html b/leetcode/outline/5_frequency_list.html index 80a410138b..7b19d0938d 100644 --- a/leetcode/outline/5_frequency_list.html +++ b/leetcode/outline/5_frequency_list.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 1.7 高频面试题(按公司排序) → -

- +

+ diff --git a/leetcode/outline/6_company_list.html b/leetcode/outline/6_company_list.html index f780453f73..6b19933905 100644 --- a/leetcode/outline/6_company_list.html +++ b/leetcode/outline/6_company_list.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 2.1 数组 → -

- +

+ diff --git a/leetcode/problem/0001.html b/leetcode/problem/0001.html index 493668ef38..a4823c3c04 100644 --- a/leetcode/problem/0001.html +++ b/leetcode/problem/0001.html @@ -8,7 +8,7 @@ - + @@ -35,7 +35,7 @@ 2. Add Two Numbers → -

- +

+ diff --git a/leetcode/problem/0002.html b/leetcode/problem/0002.html index fbf1742805..863d9f47e7 100644 --- a/leetcode/problem/0002.html +++ b/leetcode/problem/0002.html @@ -8,7 +8,7 @@ - + @@ -63,7 +63,7 @@ 3. Longest Substring Without Repeating Characters → -

- +

+ diff --git a/leetcode/problem/0003.html b/leetcode/problem/0003.html index 2671af3e5d..14f9da6d93 100644 --- a/leetcode/problem/0003.html +++ b/leetcode/problem/0003.html @@ -8,7 +8,7 @@ - + @@ -43,7 +43,7 @@ 4. Median of Two Sorted Arrays → -

- +

+ diff --git a/leetcode/problem/0004.html b/leetcode/problem/0004.html index f6c5530f53..b44cec1c8e 100644 --- a/leetcode/problem/0004.html +++ b/leetcode/problem/0004.html @@ -8,7 +8,7 @@ - + @@ -54,7 +54,7 @@ 5. Longest Palindromic Substring → -

- +

+ diff --git a/leetcode/problem/0005.html b/leetcode/problem/0005.html index 40e0cc2609..0bfe3e2fd2 100644 --- a/leetcode/problem/0005.html +++ b/leetcode/problem/0005.html @@ -8,7 +8,7 @@ - + @@ -142,7 +142,7 @@ 6. ZigZag Conversion → -

- +

+ diff --git a/leetcode/problem/0006.html b/leetcode/problem/0006.html index aad39eab28..53edbfce29 100644 --- a/leetcode/problem/0006.html +++ b/leetcode/problem/0006.html @@ -8,7 +8,7 @@ - + @@ -62,7 +62,7 @@ 7. Reverse Integer → -

- +

+ diff --git a/leetcode/problem/0007.html b/leetcode/problem/0007.html index 76d2b4d61c..970db317b4 100644 --- a/leetcode/problem/0007.html +++ b/leetcode/problem/0007.html @@ -8,7 +8,7 @@ - + @@ -44,7 +44,7 @@ 8. String to Integer (atoi) → -

- +

+ diff --git a/leetcode/problem/0008.html b/leetcode/problem/0008.html index f5e43d068d..27f71389ed 100644 --- a/leetcode/problem/0008.html +++ b/leetcode/problem/0008.html @@ -8,7 +8,7 @@ - + @@ -55,7 +55,7 @@ 9. Palindrome Number → -

- +

+ diff --git a/leetcode/problem/0009.html b/leetcode/problem/0009.html index 1882ffca38..d57ba6d775 100644 --- a/leetcode/problem/0009.html +++ b/leetcode/problem/0009.html @@ -8,7 +8,7 @@ - + @@ -43,7 +43,7 @@ 11. Container With Most Water → -

- +

+ diff --git a/leetcode/problem/0011.html b/leetcode/problem/0011.html index bfea827237..b06c22b36c 100644 --- a/leetcode/problem/0011.html +++ b/leetcode/problem/0011.html @@ -8,7 +8,7 @@ - + @@ -48,7 +48,7 @@ 13. Roman to Integer → -

- +

+ diff --git a/leetcode/problem/0013.html b/leetcode/problem/0013.html index 1c6ef78468..4198e681aa 100644 --- a/leetcode/problem/0013.html +++ b/leetcode/problem/0013.html @@ -8,7 +8,7 @@ - + @@ -71,7 +71,7 @@ 15. 3Sum → -

- +

+ diff --git a/leetcode/problem/0015.html b/leetcode/problem/0015.html index cc05739b00..54265f58d9 100644 --- a/leetcode/problem/0015.html +++ b/leetcode/problem/0015.html @@ -8,7 +8,7 @@ - + @@ -63,7 +63,7 @@ 16. 3Sum Closest → -

- +

+ diff --git a/leetcode/problem/0016.html b/leetcode/problem/0016.html index 17314106ca..28e0b9c413 100644 --- a/leetcode/problem/0016.html +++ b/leetcode/problem/0016.html @@ -8,7 +8,7 @@ - + @@ -60,7 +60,7 @@ 18. 4Sum → -

- +

+ diff --git a/leetcode/problem/0018.html b/leetcode/problem/0018.html index b2ac22c026..8d591e9bcf 100644 --- a/leetcode/problem/0018.html +++ b/leetcode/problem/0018.html @@ -8,7 +8,7 @@ - + @@ -60,7 +60,7 @@ 20. Valid Parentheses → -

- +

+ diff --git a/leetcode/problem/0020.html b/leetcode/problem/0020.html index 6b6a6a9927..2240431ec6 100644 --- a/leetcode/problem/0020.html +++ b/leetcode/problem/0020.html @@ -8,7 +8,7 @@ - + @@ -49,7 +49,7 @@ 26. Remove Duplicates from Sorted Array → -

- +

+ diff --git a/leetcode/problem/0026.html b/leetcode/problem/0026.html index 1bb2fedb50..54d2b7fb74 100644 --- a/leetcode/problem/0026.html +++ b/leetcode/problem/0026.html @@ -8,7 +8,7 @@ - + @@ -46,7 +46,7 @@ 27. Remove Element → -

- +

+ diff --git a/leetcode/problem/0027.html b/leetcode/problem/0027.html index 54d43701d6..7b29de3e8e 100644 --- a/leetcode/problem/0027.html +++ b/leetcode/problem/0027.html @@ -8,7 +8,7 @@ - + @@ -41,7 +41,7 @@ 33. Search in Rotated Sorted Array → -

- +

+ diff --git a/leetcode/problem/0033.html b/leetcode/problem/0033.html index 82cd1d1ac3..2c12e3f8b8 100644 --- a/leetcode/problem/0033.html +++ b/leetcode/problem/0033.html @@ -8,7 +8,7 @@ - + @@ -60,7 +60,7 @@ 48. Rotate Image → -

- +

+ diff --git a/leetcode/problem/0048.html b/leetcode/problem/0048.html index fb30eda64d..ce7bf81b31 100644 --- a/leetcode/problem/0048.html +++ b/leetcode/problem/0048.html @@ -8,7 +8,7 @@ - + @@ -44,99 +44,49 @@ [12, 6, 8, 9], [16, 7,10,11] ] -

# 题目大意

给定一个 n × n 的二维矩阵表示一个图像。将图像顺时针旋转 90 度。说明:你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要使用另一个矩阵来旋转图像。

# 解题思路

  • 给出一个二维数组,要求顺时针旋转 90 度。
  • 这一题比较简单,按照题意做就可以。这里给出 2 种旋转方法的实现,顺时针旋转和逆时针旋转。

-    /*
-     * clockwise rotate 顺时针旋转
-     * first reverse up to down, then swap the symmetry 
-     * 1 2 3     7 8 9     7 4 1
-     * 4 5 6  => 4 5 6  => 8 5 2
-     * 7 8 9     1 2 3     9 6 3
-    */
-    void rotate(vector<vector<int> > &matrix) {
-        reverse(matrix.begin(), matrix.end());
-        for (int i = 0; i < matrix.size(); ++i) {
-            for (int j = i + 1; j < matrix[i].size(); ++j)
-                swap(matrix[i][j], matrix[j][i]);
+

# 题目大意

给定一个 n × n 的二维矩阵表示一个图像。将图像顺时针旋转 90 度。说明:你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要使用另一个矩阵来旋转图像。

# 解题思路

  • 给出一个二维数组,要求顺时针旋转 90 度,这一题比较简单;
  • 这里给出 2 种旋转方法的实现,顺时针旋转和逆时针旋转;
  • 顺时针旋转:先将二维数组上下翻转,然后将二维数组沿对角线交换;
  • 逆时针旋转:先将二维数组左右翻转,然后将二维数组沿对角线交换;
/*
+  * clockwise rotate 顺时针旋转
+  * first reverse up to down, then swap the symmetry 
+  * 1 2 3     7 8 9     7 4 1
+  * 4 5 6  => 4 5 6  => 8 5 2
+  * 7 8 9     1 2 3     9 6 3
+*/
+
+
+/*
+  * anticlockwise rotate 逆时针旋转
+  * first reverse left to right, then swap the symmetry
+  * 1 2 3     3 2 1     3 6 9
+  * 4 5 6  => 6 5 4  => 2 5 8
+  * 7 8 9     9 8 7     1 4 7
+*/
+

# 代码

/**
+ * @param {number[][]} matrix
+ * @return {void} Do not return anything, modify matrix in-place instead.
+ */
+var rotate = function(matrix) {
+    const len = matrix.length
+    // 上下翻转
+    // 此处要注意:只能针对一半的行数翻转
+    // 否则翻转两遍等于没变
+    for (let i = 0; i < len / 2; i++) {
+        for (let j = 0; j < len; j++) {
+            let temp = matrix[i][j]
+            matrix[i][j] = matrix[len - i - 1][j]
+            matrix[len - i - 1][j] = temp
         }
     }
-    
-    /*
-     * anticlockwise rotate 逆时针旋转
-     * first reverse left to right, then swap the symmetry
-     * 1 2 3     3 2 1     3 6 9
-     * 4 5 6  => 6 5 4  => 2 5 8
-     * 7 8 9     9 8 7     1 4 7
-    */
-    void anti_rotate(vector<vector<int> > &matrix) {
-        for (auto vi : matrix) reverse(vi.begin(), vi.end());
-        for (int i = 0; i < matrix.size(); ++i) {
-            for (int j = i + 1; j < matrix[i].size(); ++j)
-                swap(matrix[i][j], matrix[j][i]);
+    // 沿对角线翻转
+    // 此处要注意:只能对左下角或者右上角的一半数据做翻转
+    // 否则翻转两遍等于没变
+    for (let i = 0; i < len; i++) {
+        for (let j = i + 1; j < len; j++) {
+            let temp = matrix[i][j]
+            matrix[i][j] = matrix[j][i]
+            matrix[j][i] = temp
         }
     }
-    
-

# 代码

package leetcode
-
-// 解法一
-func rotate(matrix [][]int) {
-	length := len(matrix)
-	// rotate by diagonal 对角线变换
-	for i := 0; i < length; i++ {
-		for j := i + 1; j < length; j++ {
-			matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
-		}
-	}
-	// rotate by vertical centerline 竖直轴对称翻转
-	for i := 0; i < length; i++ {
-		for j := 0; j < length/2; j++ {
-			matrix[i][j], matrix[i][length-j-1] = matrix[i][length-j-1], matrix[i][j]
-		}
-	}
-}
-
-// 解法二
-func rotate1(matrix [][]int) {
-	n := len(matrix)
-	if n == 1 {
-		return
-	}
-	/* rotate clock-wise = 1. transpose matrix => 2. reverse(matrix[i])
-
-	1   2  3  4      1   5  9  13        13  9  5  1
-	5   6  7  8  =>  2   6  10 14  =>    14  10 6  2
-	9  10 11 12      3   7  11 15        15  11 7  3
-	13 14 15 16      4   8  12 16        16  12 8  4
-
-	*/
-
-	for i := 0; i < n; i++ {
-		// transpose, i=rows, j=columns
-		// j = i+1, coz diagonal elements didn't change in a square matrix
-		for j := i + 1; j < n; j++ {
-			swap(matrix, i, j)
-		}
-		// reverse each row of the image
-		matrix[i] = reverse(matrix[i])
-	}
-}
-
-// swap changes original slice's i,j position
-func swap(nums [][]int, i, j int) {
-	nums[i][j], nums[j][i] = nums[j][i], nums[i][j]
-}
-
-// reverses a row of image, matrix[i]
-func reverse(nums []int) []int {
-	var lp, rp = 0, len(nums) - 1
-
-	for lp < rp {
-		nums[lp], nums[rp] = nums[rp], nums[lp]
-		lp++
-		rp--
-	}
-	return nums
-}
-
+};
 
- +

+ diff --git a/leetcode/problem/0054.html b/leetcode/problem/0054.html index 9f17333bb1..85766e5fe1 100644 --- a/leetcode/problem/0054.html +++ b/leetcode/problem/0054.html @@ -8,7 +8,7 @@ - + @@ -30,126 +30,44 @@ [9,10,11,12] ] Output: [1,2,3,4,8,12,11,10,9,5,6,7] -

# 题目大意

给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。

# 解题思路

  • 给出一个二维数组,按照螺旋的方式输出
  • 解法一:需要注意的是特殊情况,比如二维数组退化成一维或者一列或者一个元素。注意了这些情况,基本就可以一次通过了。
  • 解法二:提前算出一共多少个元素,一圈一圈地遍历矩阵,停止条件就是遍历了所有元素(count == sum)

# 代码


-package leetcode
-
-// 解法 1
-func spiralOrder(matrix [][]int) []int {
-	if len(matrix) == 0 {
-		return []int{}
-	}
-	res := []int{}
-	if len(matrix) == 1 {
-		for i := 0; i < len(matrix[0]); i++ {
-			res = append(res, matrix[0][i])
-		}
-		return res
-	}
-	if len(matrix[0]) == 1 {
-		for i := 0; i < len(matrix); i++ {
-			res = append(res, matrix[i][0])
-		}
-		return res
-	}
-	visit, m, n, round, x, y, spDir := make([][]int, len(matrix)), len(matrix), len(matrix[0]), 0, 0, 0, [][]int{
-		[]int{0, 1},  // 朝右
-		[]int{1, 0},  // 朝下
-		[]int{0, -1}, // 朝左
-		[]int{-1, 0}, // 朝上
-	}
-	for i := 0; i < m; i++ {
-		visit[i] = make([]int, n)
-	}
-	visit[x][y] = 1
-	res = append(res, matrix[x][y])
-	for i := 0; i < m*n; i++ {
-		x += spDir[round%4][0]
-		y += spDir[round%4][1]
-		if (x == 0 && y == n-1) || (x == m-1 && y == n-1) || (y == 0 && x == m-1) {
-			round++
-		}
-		if x > m-1 || y > n-1 || x < 0 || y < 0 {
-			return res
-		}
-		if visit[x][y] == 0 {
-			visit[x][y] = 1
-			res = append(res, matrix[x][y])
-		}
-		switch round % 4 {
-		case 0:
-			if y+1 <= n-1 && visit[x][y+1] == 1 {
-				round++
-				continue
-			}
-		case 1:
-			if x+1 <= m-1 && visit[x+1][y] == 1 {
-				round++
-				continue
-			}
-		case 2:
-			if y-1 >= 0 && visit[x][y-1] == 1 {
-				round++
-				continue
-			}
-		case 3:
-			if x-1 >= 0 && visit[x-1][y] == 1 {
-				round++
-				continue
-			}
-		}
-	}
-	return res
-}
-
-// 解法 2
-func spiralOrder2(matrix [][]int) []int {
-	m := len(matrix)
-	if m == 0 {
-		return nil
-	}
-
-	n := len(matrix[0])
-	if n == 0 {
-		return nil
-	}
-
-	// top、left、right、bottom 分别是剩余区域的上、左、右、下的下标
-	top, left, bottom, right := 0, 0, m-1, n-1 
-	count, sum := 0, m*n
-	res := []int{}
-	
-	// 外层循环每次遍历一圈
-	for count < sum {
-		i, j := top, left
-		for j <= right && count < sum {
-			res = append(res, matrix[i][j])
-			count++
-			j++
-		}
-		i, j = top + 1, right
-		for i <= bottom && count < sum {
-			res = append(res, matrix[i][j])
-			count++
-			i++
-		}
-		i, j = bottom, right - 1
-		for j >= left && count < sum {
-			res = append(res, matrix[i][j])
-			count++
-			j--
-		}
-		i, j = bottom - 1, left
-		for i > top && count < sum {
-			res = append(res, matrix[i][j])
-			count++
-			i--
-		}
-		// 进入到下一层
-		top, left, bottom, right = top+1, left+1, bottom-1, right-1
-	}
-	return res
-}
+

# 题目大意

给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。

# 解题思路

  • 给出一个二维数组,按照螺旋的方式输出;
  • 用四个指针控制每次上、下、左、右的边,然后按照逆时针的顺序从边界上依次访问元素;
  • 当访问完当前边界之后,要更新一下边界位置,缩小范围,方便下一轮进行访问;
  • 注意由于输入的数组 matrixm * n 的矩阵,m 不一定等于 n,所以在螺旋遍历时可能出现多遍历了行或者列,返回时需要删除 res 中多余的数: res.slice(0, m * n)

# 代码

/**
+ * @param {number[][]} matrix
+ * @return {number[]}
+ */
+var spiralOrder = function(matrix) {
+    let m = matrix.length
+    let n = matrix[0].length
+    let res = []
+    let count = 0
+    let left = 0
+    let right = n - 1
+    let top = 0
+    let bottom = m - 1
 
+    while (count < m * n) {
+        for (let i = left; i <= right; i++) {
+            res[count] = matrix[top][i]
+            count++
+        }
+        top++
+        for (let i = top; i <= bottom; i++) {
+            res[count] = matrix[i][right]
+            count++
+        }
+        right--
+        for (let i = right; i >= left; i--) {
+            res[count] = matrix[bottom][i]
+            count++
+        }
+        bottom--
+        for (let i = bottom; i >= top; i--) {
+            res[count] = matrix[i][left]
+            count++
+        }
+        left++
+    }
+    return res.slice(0, m * n)
+};
 
- +

+ diff --git a/leetcode/problem/0059.html b/leetcode/problem/0059.html index bd285c8758..cee4acaf4c 100644 --- a/leetcode/problem/0059.html +++ b/leetcode/problem/0059.html @@ -8,7 +8,7 @@ - + @@ -23,67 +23,53 @@ [ 8, 9, 4 ], [ 7, 6, 5 ] ] -

# 题目大意

给定一个正整数 n,生成一个包含 1 到 n^2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵。

# 解题思路

  • 给出一个数组 n,要求输出一个 n * n 的二维数组,里面元素是 1 - n*n,且数组排列顺序是螺旋排列的
  • 这一题是第 54 题的加强版,没有需要注意的特殊情况,直接模拟即可。

# 代码


-package leetcode
+

# 题目大意

给定一个正整数 n,生成一个包含 1 到 n^2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵。

# 解题思路

  • 给出一个数组 n,要求输出一个 n * n 的二维数组,里面元素是 1 - n*n,且数组排列顺序是螺旋排列的;
  • 这一题是第 54 题的加强版,没有需要注意的特殊情况,直接模拟即可;
  • 用四个指针控制每次上、下、左、右的边,然后按照逆时针的顺序从边界上依次访问元素;
  • 当访问完当前边界之后,要更新一下边界位置,缩小范围,方便下一轮进行访问;
  • 注意初始化 res 时不能直接 new Array(n).fill([]),因为JS中将数组作为参数时,传递的是引用,而不是 value

# 代码

/**
+ * @param {number} n
+ * @return {number[][]}
+ */
+var generateMatrix = function (n) {
+  let count = 0;
+  let left = 0;
+  let right = n - 1;
+  let top = 0;
+  let bottom = n - 1;
+  let res = new Array(n).fill(0).map(() => new Array(n));
 
-func generateMatrix(n int) [][]int {
-	if n == 0 {
-		return [][]int{}
-	}
-	if n == 1 {
-		return [][]int{[]int{1}}
-	}
-	res, visit, round, x, y, spDir := make([][]int, n), make([][]int, n), 0, 0, 0, [][]int{
-		[]int{0, 1},  // 朝右
-		[]int{1, 0},  // 朝下
-		[]int{0, -1}, // 朝左
-		[]int{-1, 0}, // 朝上
-	}
-	for i := 0; i < n; i++ {
-		visit[i] = make([]int, n)
-		res[i] = make([]int, n)
-	}
-	visit[x][y] = 1
-	res[x][y] = 1
-	for i := 0; i < n*n; i++ {
-		x += spDir[round%4][0]
-		y += spDir[round%4][1]
-		if (x == 0 && y == n-1) || (x == n-1 && y == n-1) || (y == 0 && x == n-1) {
-			round++
-		}
-		if x > n-1 || y > n-1 || x < 0 || y < 0 {
-			return res
-		}
-		if visit[x][y] == 0 {
-			visit[x][y] = 1
-			res[x][y] = i + 2
-		}
-		switch round % 4 {
-		case 0:
-			if y+1 <= n-1 && visit[x][y+1] == 1 {
-				round++
-				continue
-			}
-		case 1:
-			if x+1 <= n-1 && visit[x+1][y] == 1 {
-				round++
-				continue
-			}
-		case 2:
-			if y-1 >= 0 && visit[x][y-1] == 1 {
-				round++
-				continue
-			}
-		case 3:
-			if x-1 >= 0 && visit[x-1][y] == 1 {
-				round++
-				continue
-			}
-		}
-	}
-	return res
-}
+  while (count < n * n) {
+	// 在上边界向右扫描
+    for (let i = left; i <= right; i++) {
+      count++;
+      res[top][i] = count;
+    }
+	// 缩小上边界
+    top++;
 
+	// 在右边界向下扫描
+    for (let i = top; i <= bottom; i++) {
+      count++;
+      res[i][right] = count;
+    }
+	// 缩小右边界
+    right--;
+
+	// 在下边界向左扫描
+    for (let i = right; i >= left; i--) {
+      count++;
+      res[bottom][i] = count;
+    }
+	// 缩小下边界
+    bottom--;
+	
+	// 在左边界向上扫描
+    for (let i = bottom; i >= top; i--) {
+      count++;
+      res[i][left] = count;
+    }
+	// 缩小左边界
+    left++;
+  }
+  return res;
+};
 
- +

+ diff --git a/leetcode/problem/0062.html b/leetcode/problem/0062.html index 1adc241573..3239573f74 100644 --- a/leetcode/problem/0062.html +++ b/leetcode/problem/0062.html @@ -8,7 +8,7 @@ - + @@ -54,7 +54,7 @@ 63. Unique Paths II → -

- +

+ diff --git a/leetcode/problem/0063.html b/leetcode/problem/0063.html index 38eea582ff..d0343cdf9d 100644 --- a/leetcode/problem/0063.html +++ b/leetcode/problem/0063.html @@ -8,7 +8,7 @@ - + @@ -52,7 +52,7 @@ 66. Plus One → -

- +

+ diff --git a/leetcode/problem/0066.html b/leetcode/problem/0066.html index 3831eaeabb..4c79b75a74 100644 --- a/leetcode/problem/0066.html +++ b/leetcode/problem/0066.html @@ -8,7 +8,7 @@ - + @@ -53,7 +53,7 @@ 70. Climbing Stairs → -

- +

+ diff --git a/leetcode/problem/0070.html b/leetcode/problem/0070.html index 8f9de15189..1f4821f390 100644 --- a/leetcode/problem/0070.html +++ b/leetcode/problem/0070.html @@ -8,7 +8,7 @@ - + @@ -36,7 +36,7 @@ 73. Set Matrix Zeroes → -

- +

+ diff --git a/leetcode/problem/0073.html b/leetcode/problem/0073.html index e0db21fa29..6a39200ea7 100644 --- a/leetcode/problem/0073.html +++ b/leetcode/problem/0073.html @@ -8,7 +8,7 @@ - + @@ -16,60 +16,68 @@ Github (opens new window)

# 73. Set Matrix Zeroes (opens new window)

# 题目

Given an *m* x *n* matrix. If an element is 0, set its entire row and column to 0. Do it in-place (opens new window).

Follow up:

  • A straight forward solution using O(mn) space is probably a bad idea.
  • A simple improvement uses O(m + n) space, but still not the best solution.
  • Could you devise a constant space solution?

Example 1:

https://assets.leetcode.com/uploads/2020/08/17/mat1.jpg

Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]

Output: [[1,0,1],[0,0,0],[1,0,1]]

Example 2:

https://assets.leetcode.com/uploads/2020/08/17/mat2.jpg

Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]

Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]

Constraints:

  • m == matrix.length
  • n == matrix[0].length
  • 1 <= m, n <= 200
  • 2^31 <= matrix[i][j] <= 2^31 - 1

# 题目大意

给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0。请使用原地算法。

# 解题思路

  • 此题考查对程序的控制能力,无算法思想。题目要求采用原地的算法,所有修改即在原二维数组上进行。在二维数组中有 2 个特殊位置,一个是第一行,一个是第一列。它们的特殊性在于,它们之间只要有一个 0,它们都会变为全 0 。先用 2 个变量记录这一行和这一列中是否有 0,防止之后的修改覆盖了这 2 个地方。然后除去这一行和这一列以外的部分判断是否有 0,如果有 0,将它们所在的行第一个元素标记为 0,所在列的第一个元素标记为 0 。最后通过标记,将对应的行列置 0 即可。

# 代码

package leetcode
-
-func setZeroes(matrix [][]int) {
-	if len(matrix) == 0 || len(matrix[0]) == 0 {
-		return
-	}
-	isFirstRowExistZero, isFirstColExistZero := false, false
-	for i := 0; i < len(matrix); i++ {
-		if matrix[i][0] == 0 {
-			isFirstColExistZero = true
-			break
-		}
-	}
-	for j := 0; j < len(matrix[0]); j++ {
-		if matrix[0][j] == 0 {
-			isFirstRowExistZero = true
-			break
-		}
-	}
-	for i := 1; i < len(matrix); i++ {
-		for j := 1; j < len(matrix[0]); j++ {
-			if matrix[i][j] == 0 {
-				matrix[i][0] = 0
-				matrix[0][j] = 0
-			}
-		}
-	}
-	// 处理[1:]行全部置 0
-	for i := 1; i < len(matrix); i++ {
-		if matrix[i][0] == 0 {
-			for j := 1; j < len(matrix[0]); j++ {
-				matrix[i][j] = 0
-			}
-		}
-	}
-	// 处理[1:]列全部置 0
-	for j := 1; j < len(matrix[0]); j++ {
-		if matrix[0][j] == 0 {
-			for i := 1; i < len(matrix); i++ {
-				matrix[i][j] = 0
-			}
-		}
-	}
-	if isFirstRowExistZero {
-		for j := 0; j < len(matrix[0]); j++ {
-			matrix[0][j] = 0
-		}
-	}
-	if isFirstColExistZero {
-		for i := 0; i < len(matrix); i++ {
-			matrix[i][0] = 0
-		}
-	}
-}
+     (opens new window)    

# 73. Set Matrix Zeroes (opens new window)

# 题目

Given an *m* x *n* matrix. If an element is 0, set its entire row and column to 0. Do it in-place (opens new window).

Follow up:

  • A straight forward solution using O(mn) space is probably a bad idea.
  • A simple improvement uses O(m + n) space, but still not the best solution.
  • Could you devise a constant space solution?

Example 1:

https://assets.leetcode.com/uploads/2020/08/17/mat1.jpg

Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]

Output: [[1,0,1],[0,0,0],[1,0,1]]

Example 2:

https://assets.leetcode.com/uploads/2020/08/17/mat2.jpg

Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]

Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]

Constraints:

  • m == matrix.length
  • n == matrix[0].length
  • 1 <= m, n <= 200
  • 2^31 <= matrix[i][j] <= 2^31 - 1

# 题目大意

给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0。请使用原地算法。

# 解题思路

  • 此题考查对程序的控制能力,无算法思想;
  • 题目要求采用原地的算法,所有修改即在原二维数组上进行;
  • 在二维数组中有 2 个特殊位置,一个是第一行,一个是第一列,先用 2 个变量记录这一行和这一列中是否有 0,防止之后的修改覆盖了这 2 个地方;
  • 然后除去这一行和这一列以外的部分判断是否有 0,如果有 0,将它们所在的行第一个元素和所在列的第一个元素标记为 0 ;
  • 最后通过标记,将对应的行列置 0 即可。

# 代码

/**
+ * @param {number[][]} matrix
+ * @return {void} Do not return anything, modify matrix in-place instead.
+ */
+var setZeroes = function (matrix) {
+  const m = matrix.length;
+  const n = matrix[0].length;
+  let first_row_has_zero = false;
+  let first_line_has_zero = false;
+  
+  // 第一列是否有 0
+  for (let i = 0; i < m; i++) {
+    if (matrix[i][0] === 0) {
+      first_row_has_zero = true;
+      break;
+    }
+  }
+  // 第一行是否有 0
+  for (let j = 0; j < n; j++) {
+    if (matrix[0][j] === 0) {
+      first_line_has_zero = true;
+      break;
+    }
+  }
+  // 除第一行、第一列外,其他地方有 0,则将列首和行首置为 0
+  for (let i = 1; i < m; i++) {
+    for (let j = 1; j < n; j++) {
+      if (matrix[i][j] === 0) {
+        matrix[i][0] = 0;
+        matrix[0][j] = 0;
+      }
+    }
+  }
+  // 遍历第一列,有 0 则将整行置为 0
+  for (let i = 1; i < m; i++) {
+    if (matrix[i][0] === 0) {
+      for (let j = 1; j < n; j++) {
+        matrix[i][j] = 0;
+      }
+    }
+  }
+  // 遍历第一行,有 0 则将整列置为 0
+  for (let j = 1; j < n; j++) {
+    if (matrix[0][j] === 0) {
+      for (let i = 1; i < m; i++) {
+        matrix[i][j] = 0;
+      }
+    }
+  }
+  // 若第一列原本有 0,则将第一列都置为 0
+  if (first_row_has_zero) {
+    for (let i = 0; i < m; i++) {
+      matrix[i][0] = 0;
+    }
+  }
+  // 若第一行原本有 0,则将第一行都置为 0
+  if (first_line_has_zero) {
+    for (let j = 0; j < n; j++) {
+      matrix[0][j] = 0;
+    }
+  }
+};
 
- +

+ diff --git a/leetcode/problem/0080.html b/leetcode/problem/0080.html index a41f25fd58..016bc9a8a2 100644 --- a/leetcode/problem/0080.html +++ b/leetcode/problem/0080.html @@ -8,7 +8,7 @@ - + @@ -50,7 +50,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/0120.html b/leetcode/problem/0120.html index 91f1959949..253e922976 100644 --- a/leetcode/problem/0120.html +++ b/leetcode/problem/0120.html @@ -8,7 +8,7 @@ - + @@ -67,7 +67,7 @@ 125. Valid Palindrome → -

- +

+ diff --git a/leetcode/problem/0125.html b/leetcode/problem/0125.html index c9217f706d..2116cc5389 100644 --- a/leetcode/problem/0125.html +++ b/leetcode/problem/0125.html @@ -8,7 +8,7 @@ - + @@ -51,7 +51,7 @@ 152. Maximum Product Subarray → -

- +

+ diff --git a/leetcode/problem/0152.html b/leetcode/problem/0152.html index a115c39bd0..aeee7ebcd9 100644 --- a/leetcode/problem/0152.html +++ b/leetcode/problem/0152.html @@ -8,7 +8,7 @@ - + @@ -42,7 +42,7 @@ 167. Two Sum II - Input array is sorted → -

- +

+ diff --git a/leetcode/problem/0167.html b/leetcode/problem/0167.html index 617b323aba..688ef96b81 100644 --- a/leetcode/problem/0167.html +++ b/leetcode/problem/0167.html @@ -8,7 +8,7 @@ - + @@ -61,7 +61,7 @@ 189. Rotate Array → -

- +

+ diff --git a/leetcode/problem/0189.html b/leetcode/problem/0189.html index 7e950be123..ffe1722a83 100644 --- a/leetcode/problem/0189.html +++ b/leetcode/problem/0189.html @@ -8,7 +8,7 @@ - + @@ -67,7 +67,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/0206.html b/leetcode/problem/0206.html index 542b2321e5..fc39b83896 100644 --- a/leetcode/problem/0206.html +++ b/leetcode/problem/0206.html @@ -8,7 +8,7 @@ - + @@ -68,7 +68,7 @@ 227. Basic Calculator II → -

- +

+ diff --git a/leetcode/problem/0227.html b/leetcode/problem/0227.html index 0a356a00c5..481ee9c444 100644 --- a/leetcode/problem/0227.html +++ b/leetcode/problem/0227.html @@ -8,7 +8,7 @@ - + @@ -54,7 +54,7 @@ 279. Product of Array Except Self → -

- +

+ diff --git a/leetcode/problem/0238.html b/leetcode/problem/0238.html index 12c45205be..56ea7e33fc 100644 --- a/leetcode/problem/0238.html +++ b/leetcode/problem/0238.html @@ -8,7 +8,7 @@ - + @@ -48,7 +48,7 @@ 259. 3Sum Smaller → -

- +

+ diff --git a/leetcode/problem/0259.html b/leetcode/problem/0259.html index c669f301b9..2cf6371e5b 100644 --- a/leetcode/problem/0259.html +++ b/leetcode/problem/0259.html @@ -8,7 +8,7 @@ - + @@ -16,7 +16,7 @@ Github (opens new window)

# 259. 3Sum Smaller (opens new window)

# 题目

Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.

Example:

Input: nums = [-2,0,1,3], and target = 2

Output: 2

Explanation:

Because there are two triplets which sums are less than 2: [-2,0,1][-2,0,3]

Follow up: Could you solve it in O(n2) runtime?

# 题目大意

给定一个数组 nums,要求返回三数之和小于一个目标值的情况的个数。

# 解题思路

这道题是 3Sum 问题的一个变形,

# 代码


+     (opens new window)    

# 259. 3Sum Smaller (opens new window)

# 题目

Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.

Example:

Input: nums = [-2,0,1,3], and target = 2

Output: 2

Explanation:

Because there are two triplets which sums are less than 2: [-2,0,1][-2,0,3]

Follow up: Could you solve it in O(n^2) runtime?

# 题目大意

给定一个数组 nums,要求返回三数之和小于一个目标值的情况的个数。

# 解题思路

这道题是 3Sum 问题的一个变形,

# 代码


 
- +

+ diff --git a/leetcode/problem/0279.html b/leetcode/problem/0279.html index 42ffe4da1c..2130ec7ab8 100644 --- a/leetcode/problem/0279.html +++ b/leetcode/problem/0279.html @@ -8,7 +8,7 @@ - + @@ -36,7 +36,7 @@ 283. Move Zeroes → -

- +

+ diff --git a/leetcode/problem/0283.html b/leetcode/problem/0283.html index d62dd034a6..5c2959e878 100644 --- a/leetcode/problem/0283.html +++ b/leetcode/problem/0283.html @@ -8,7 +8,7 @@ - + @@ -42,7 +42,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/0344.html b/leetcode/problem/0344.html index c953887c66..17481637b2 100644 --- a/leetcode/problem/0344.html +++ b/leetcode/problem/0344.html @@ -8,7 +8,7 @@ - + @@ -41,7 +41,7 @@ 345. Reverse Vowels of a String → -

- +

+ diff --git a/leetcode/problem/0345.html b/leetcode/problem/0345.html index e2cff41a50..9f5de3987f 100644 --- a/leetcode/problem/0345.html +++ b/leetcode/problem/0345.html @@ -8,7 +8,7 @@ - + @@ -53,7 +53,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/0485.html b/leetcode/problem/0485.html index fe9597c98b..d341ad5f95 100644 --- a/leetcode/problem/0485.html +++ b/leetcode/problem/0485.html @@ -8,7 +8,7 @@ - + @@ -42,7 +42,7 @@ 498. Diagonal Traverse → -

- +

+ diff --git a/leetcode/problem/0498.html b/leetcode/problem/0498.html index 94d906c8f1..1366a9fb19 100644 --- a/leetcode/problem/0498.html +++ b/leetcode/problem/0498.html @@ -8,7 +8,7 @@ - + @@ -85,7 +85,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/0509.html b/leetcode/problem/0509.html index 294a37aba2..e425cd6eae 100644 --- a/leetcode/problem/0509.html +++ b/leetcode/problem/0509.html @@ -8,7 +8,7 @@ - + @@ -72,7 +72,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/0611.html b/leetcode/problem/0611.html index 1ea0a93f1d..997fc5113e 100644 --- a/leetcode/problem/0611.html +++ b/leetcode/problem/0611.html @@ -8,7 +8,7 @@ - + @@ -47,7 +47,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/0724.html b/leetcode/problem/0724.html index e7cb49d8bd..7a8415031e 100644 --- a/leetcode/problem/0724.html +++ b/leetcode/problem/0724.html @@ -8,7 +8,7 @@ - + @@ -43,7 +43,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/1047.html b/leetcode/problem/1047.html index 5bee749281..269fa2447d 100644 --- a/leetcode/problem/1047.html +++ b/leetcode/problem/1047.html @@ -8,7 +8,7 @@ - + @@ -40,7 +40,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/LCP_53.html b/leetcode/problem/LCP_53.html index 39f775c21a..70e3414cd0 100644 --- a/leetcode/problem/LCP_53.html +++ b/leetcode/problem/LCP_53.html @@ -8,7 +8,7 @@ - + @@ -21,7 +21,7 @@ ←

- +

+ diff --git a/leetcode/problem/i_03.01.html b/leetcode/problem/i_03.01.html index 8603a349b6..13b69f7281 100644 --- a/leetcode/problem/i_03.01.html +++ b/leetcode/problem/i_03.01.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/jz_offer_59_2.html b/leetcode/problem/jz_offer_59_2.html index 15ed8390a0..50e026fbaf 100644 --- a/leetcode/problem/jz_offer_59_2.html +++ b/leetcode/problem/jz_offer_59_2.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 索引 → -

- +

+ diff --git a/leetcode/problem/jz_offer_II_055.html b/leetcode/problem/jz_offer_II_055.html index 7e1e230f97..07837c1f35 100644 --- a/leetcode/problem/jz_offer_II_055.html +++ b/leetcode/problem/jz_offer_II_055.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 索引 → -

- +

+ diff --git a/leetcode/solution/0001-0099.html b/leetcode/solution/0001-0099.html index 044843a7c4..f64e8d2ecd 100644 --- a/leetcode/solution/0001-0099.html +++ b/leetcode/solution/0001-0099.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 1. Two Sum → -

- +

+ diff --git a/leetcode/solution/0100-0199.html b/leetcode/solution/0100-0199.html index 6269196a41..ca28948a34 100644 --- a/leetcode/solution/0100-0199.html +++ b/leetcode/solution/0100-0199.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 120. Triangle → -

- +

+ diff --git a/leetcode/solution/0200-0299.html b/leetcode/solution/0200-0299.html index a6179aceeb..72c70335e0 100644 --- a/leetcode/solution/0200-0299.html +++ b/leetcode/solution/0200-0299.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 206. Reverse Linked List → -

- +

+ diff --git a/leetcode/solution/0300-0399.html b/leetcode/solution/0300-0399.html index 036e14e6f2..5d3a1169ef 100644 --- a/leetcode/solution/0300-0399.html +++ b/leetcode/solution/0300-0399.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 344. Reverse String → -

- +

+ diff --git a/leetcode/solution/0400-0499.html b/leetcode/solution/0400-0499.html index 09266ccb15..5010cc5727 100644 --- a/leetcode/solution/0400-0499.html +++ b/leetcode/solution/0400-0499.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 485. Max Consecutive Ones → -

- +

+ diff --git a/leetcode/solution/0500-0599.html b/leetcode/solution/0500-0599.html index cb35de46fc..c33ff2059e 100644 --- a/leetcode/solution/0500-0599.html +++ b/leetcode/solution/0500-0599.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 509. Fibonacci Number → -

- +

+ diff --git a/leetcode/solution/0600-0699.html b/leetcode/solution/0600-0699.html index 1ff95ebc07..4d518afc89 100644 --- a/leetcode/solution/0600-0699.html +++ b/leetcode/solution/0600-0699.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 611. Valid Triangle Number → -

- +

+ diff --git a/leetcode/solution/0700-0799.html b/leetcode/solution/0700-0799.html index 4edc708431..baaaecd3df 100644 --- a/leetcode/solution/0700-0799.html +++ b/leetcode/solution/0700-0799.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 724. Find Pivot Index → -

- +

+ diff --git a/leetcode/solution/1000-1099.html b/leetcode/solution/1000-1099.html index ac37d80c11..7fb237d509 100644 --- a/leetcode/solution/1000-1099.html +++ b/leetcode/solution/1000-1099.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 1047. Remove All Adjacent Duplicates In String → -

- +

+ diff --git a/leetcode/solution/Interviews.html b/leetcode/solution/Interviews.html index 2d2450f57f..b21985dcc6 100644 --- a/leetcode/solution/Interviews.html +++ b/leetcode/solution/Interviews.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 面试题 03.01. 三合一 → -

- +

+ diff --git a/leetcode/solution/LCP.html b/leetcode/solution/LCP.html index 8c54fe7126..23b4e756d3 100644 --- a/leetcode/solution/LCP.html +++ b/leetcode/solution/LCP.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ LCP 53. 守护太空城 → -

- +

+ diff --git a/leetcode/solution/Offer-II.html b/leetcode/solution/Offer-II.html index 6248250bfd..e4eb7fb7ad 100644 --- a/leetcode/solution/Offer-II.html +++ b/leetcode/solution/Offer-II.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ LCR 055. 二叉搜索树迭代器 → -

- +

+ diff --git a/leetcode/solution/Offer.html b/leetcode/solution/Offer.html index b15ba56b87..c7d41eacf8 100644 --- a/leetcode/solution/Offer.html +++ b/leetcode/solution/Offer.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ LCR 184. 设计自助结算系统 → -

- +

+ diff --git a/magic.html b/magic.html index 337040ada5..9b3a2c25ed 100644 --- a/magic.html +++ b/magic.html @@ -8,7 +8,7 @@ - + @@ -17,7 +17,7 @@ (opens new window)

# 今日咒语


以下内容全部摘录自张潇雨 (opens new window)的微博,感谢涂俊杰 (opens new window)的整理。




「know your game」




一个人无法通过做大多数人都在做的事达到成功。




一个人是 TA 打交道最多的五个人的平均水平。




一个人水平的下限由它学习的最差的五个对象决定。




只向最好的人学习,其他人都不知道自己在干什么。不要理会他们的「建议」。




决策的第一要务是给自己创造足够多的好选项。大多数决策失败来源于在几个都不够好的选择中反复纠结。




寻找「非对称回报」的机会,即那种「失败了损失很低,但一旦成功回报巨大」的机会。




不是生活中的每一个问题都要解决,和问题共处是人生常态。把精力用在重要的事情上。




人境遇的改变往往是非线性的。积累和等待的过程很难熬,这是很多人无法改变的原因之一。




一个人的境遇绝大部分都受运气支配,但运气是可以被影响的。




人很难靠出卖自己的单位时间获得财富。财富来自于对杠杆的使用,常见的杠杆有:互联网、人力、资本、声望、时间等等。




在混沌、开放、随机的系统内,努力「减少错误」要比「追求正确」有效得多。




吃得健康、持续锻炼、保证睡眠,几乎可以带人走出任何困境。




除了一些极端意外情况,大多数困境在之后看都是好事。




每一次困境都是一次探索自我良好的契机,不要浪费它们。




日常中积累小的信心和正反馈,这样在大的选择面前就会更加从容淡定。




意志力这种东西几乎不存在。与其努力提高自己的意志力,不如给自己创造更好的环境于是无需调用意志力。




在解决生存问题之后,人的幸福感主要由身边关系的质量决定。




外面没有别人。




一切都是最好的安排。




自由不是得到你爱的东西,而是爱你得到的东西。Freedom is not getting what you love, is loving what you get.




一个人一旦开始对自己撒谎,就再也不会进步了。




Gradually, then Suddenly.——Ernest Hemingway




芒格的意思大概是:如果你还需要别人的认可和允许来做自己想做的事的话,那么也许你还没想清楚自己要做什么。




想完成一件重要的事,最关键的环节不是什么设立远大目标、学习高效方法或者坚定自身意志,而是把这件事放在一个无可辩驳的最高优先级上——而其他所有事,不管听起来多么正确合理、多么理所应当,都要彻底围绕着这件事来运行,都要进行不可妥协的让步,都要摒弃与自我反复的讨价还价。只有做出这种程度的舍弃与牺牲,重要的结果才有可能到来。




一个人,当真正知道自己为什么而战的时候,知道自己无需再符合这个世界绝大部分人的期待的时候,他就要进入天下无敌的境地了。




道理在初中的时候就学过了:想要打破现有的平衡态,就要对该状态做超出临界点的功。




几乎所有好的转变的开始都来自于一个行动:离开糟糕的人际关系。




恪守自己的行进主线,别让社交媒体设置你每天的思考议题。




你觉得自己应该做但一直不想做的那个事情,在周末、节日、度假、gap year、谈恋爱、度蜜月、分手、离婚、考上理想大学、换个新工作、路边捡到钱、公司 IPO、区块链革命、获诺贝尔奖、经济危机、南极冰融化、小行星撞击地球、宇宙大爆炸......之后很可能还是不会做的。还是向内看看阻碍自己的到底是什么,可能会有一些真正的答案。




这几年愈发感觉到,作品是我们和世界连接的方式,希望大家新一年都可以创造点什么,哪怕只是很小很小的东西。




看到一句西方谚语:当学生准备好了,老师就会出现。




一个人做的事情,时效性越强,起作用的时间就越短;反过来,所谓「没有时效性」的事情,其实是「在你余生中都会起作用」的事情。怎么选不是很显然吗。




如果你总是认可自己,那么余生皆是假期。




喜欢做一件事,和做一件事能让你暂时逃避真实的焦虑和烦恼,是两个不同的东西。




你对抗的东西就会持续,因为你让一个假的东西成真了。




在文学、艺术中,一心想有独创性的人绝不会有任何的独创性,但是,如果你只想讲出真理(一点也不在意这个真理以前怎样频繁地被人讲述),十有八九在无意之中,你就已经有了独创性。这个原则贯穿整个生活的始终。放弃自我,你就会找到真正的自我,丧失生命,你就会得到生命。每天顺服于死亡,顺服于自己的抱负、挚爱的心愿的死亡,最终顺服于整个身体的死亡,全心全意地顺服,你就会发现永恒的生命。




春节是你「think big, think deep, think long」的最好时机。花一些功夫,在没有外界催促的情况下好好整理一下自己的生活。虽然陪家人串亲戚吃吃喝喝也很重要,但千万别忘了把一些时间留给自己。




比起那种「一路披荆斩棘」的 game,我更喜欢的是「全靠同行衬托」。




做播客的真正初心不是教人怎么造船,而是告诉你:大海是个好东西。




把每个词说得准确还能带来一个隐性的好处,就是这实际上是一种诚实面对自我的日常练习。一句一词用得越准确,自己的内心就会越清晰,这即是我深信不疑的(不知道有没有科学研究支撑的)语言对意识的反向塑造了。




我总说,如果有一个事老是回到你的生活,你忘掉它一阵它又回来了,你说我要去干一些所谓的正事,然后那东西过一阵又回来了,可能没准那件事就是你应该去干的一件事。




很多重大问题的解决往往不是它「被解决了」,而是它「不需要再被问了」。




如果,你也会感觉到,假如自己把一些事情做得更好,就无法避免要与现在身边的人与环境分离,会让更多人不理解你,也可能会变得更孤独一点的话,我可以告诉你,没关系的,大胆去做吧。在更高处、在更远处、在更深处,你还会遇到很多人很多事,但最重要的是,你会遇到真正的自己。这也是我们一生唯一重要的旅程。新一年,敢于伟大。Dare to be Great.




吃好、睡好、锻炼身体、做自己喜欢的事,人生才刚刚开始。




我一直认为个人成长与人生选择过程中有三个悖论:16-18 岁在对学科与知识一无所知的时候就被要求选择自己的专业;22-25 岁在对商业世界运行规则毫无概念的时候就被要求选择工作方向;25-28 岁在对自己和人际关系一知半解的情况下就被要求确定长期伴侣;这样想来,其实人生出问题是一个大概率事件。




成长就像米开朗基罗的雕塑一样,当你把一块大理石里多余和不该有的东西去掉,大卫就诞生了。




我一直觉得对钱的理解——也就是基本的「财商」教育——应该被纳入一个国家的通识教育体系,就像数学、哲学、逻辑学、伦理学、社会学、沟通与表达和写作课等等一样。




能找到一些有理有据的、总能挑战你认知的、让你有点不舒服的人或物,可能更应该感激,而不是抵触。这也是为什么我总坚持在自己的时间线里放一些和我看法总不一样的人,尽管每次看到还是会有点难受。我也鼓励你这么做。因为学会克服「认知失调」带来的不适感,是人进步的一个关键。




好的信心往往不是来自于觉得一件事不难,而是不觉得一件事难。对事情不带主观评判之心,把能量用在思考促成它发生的条件是什么、怎样可以做到、具体问题如何解决或者绕过......不但过程中内心没有对抗,结果也会自然而然地发生。




要做那种看起来特别 tm 难、特别需要时间的事。因为一旦你打算做一件又难又慢的事,环顾四周你就会发现,咦根本没人和我竞争啊——因为大部份人都挤去做那些看起来简单又快速的东西了。




我一直认为大多数人工作 3-7 年之后都值得有一个 self-caring gap year。也有了一定的积蓄。不妨离开常规的职场工作一年,然后:- 学习 1-2 种可以受益终身的基础技能。- 研究 2-3 个自己感兴趣或当今世界重要的议题。利用学习的基础技能,为自己感兴趣的话题或者活动制作 3–4 个「作品」,任何形式的都可以。做一次全面的体检,不只是器官类的,还有体能上的和心理上的。试着重新梳理一下自己和他人的关系。不论是家人、伴侣还是朋友、甚至陌生人。最后,如果有机缘的话,感受一些神秘体验。大多数人都是沿着惯性在向前走的,停下来——哪怕仅仅是短暂地停下来——对他们来说都简直无法想象。但如果你真的愿意花一年时间做好这些事,相信我,这会是你人生中最难忘的一个选择。




我觉得我性格里大部分的乐观和感恩都来自一个简单的事实,就是生活本可以更差更差,甚至是差到非常黑暗的。别以为你现在一切看着挺好就逃过一劫了,其实随便发生一个意外,随便做错一个选择,都可能让一个人的生活质量大幅退步,甚至一步退到黑暗边缘。




保证长期成功(不败)的一个重要方法就是在每一个关键事件周边制造选择冗余。




很多时候,别人问你一个问题背后隐含的意思是:我其实也知道这个问题的答案,但那么做太辛苦太累了,我嫌麻烦。所以到你这儿看看有没有什么捷径。




经常有人问我什么是自由,我觉得这可能是个好的角度:别让任何人拥有对你的最终解释权。自己的生活,就自己过。




如果你的年龄在 25 岁以上,那么根据我这一两年(非专业)的研究,你的父母或者上一辈的家人已经有不小的概率出现癌前病变甚至是早期癌症了。带他们去做个全面的体检吧。最好是专业的早癌筛查。最重要的是,把这件事置于最高优先级上,不要给自己任何借口来逃避问题或者蒙混过关。人生完全不可逆的巨大风险就那么几种,不要做出让自己余生都会后悔的选择。




一年一般只能完成 1.5 件事。这里的「事」大概等同于生活主线上要做的那种相对比较大的项目或目标。0.5 约等于思考和筹备,或者想明白正好开始动手做了。如果安排得再多,精力和思考深度都达不到要求,结果也不会太好。




最近的行动策略是这样的:想象一下自己 5-8 年以后的主业会是什么,不准确也没关系,但现在先以一个小 10-100 倍规模的方式用业余时间做起来。




最近尽量只观察问题和陈述问题,不追求一定要提供解决方案。一是自己并不通透,说多了可能会误导他人;二是,一旦立刻去「寻找答案」,就又陷入了「我有问题--我不够好--我要改变」的递归式自责里了。




科学可能是一个我们妥协的产物,我们只能按照目前我们掌握的东西来理解世界,以后我们可能会颠覆很多想法,会补充很多理论,但此刻不要停止怀疑。




不要让曾经平庸的教育系统和糟糕的学校老师破坏了你对学习的本能热爱。日复一日地多懂一些东西,甚至有一天在没有考试和求职的压力下再回到学校,单纯地和知识们在一起。你会发现,这样的生活其实是无比幸福的。




很多时候,我们觉得好像外面有很多人在看着自己,在要求自己。其实外面谁也没有,只有你和你的观念,每天在相处与纠缠。如果把那些限制性的信念拿掉,一念之转,整个世界可能就从此不同了。




事实证明,看似再不可能的事情都有可能发生,这也正是尾部风险的定义。And you’d better have a plan for it(你最好有个计划)。




长大之后觉得「买椟还珠」还挺好的。自己觉得什么有意思什么有价值就去追求,不用管别人眼中什么是重要的,什么又是「不合理」或者「不务正业」的。我就喜欢那个盒子怎么了,珍珠留给追求它的人吧,反正我也用不着。




一段关系是滋养你还是消耗你,你心里其实非常清楚,并不需要我或者任何人给你答案。人没法欺骗自己太久,所以决定你也早做好了,就放在那里,无非是现在让它实现还是以后让它实现而已——当然这也都没关系。




年底又想起《师父》:「每日挥刀五百下,这个数管住了我。」




比起获得你所嫉妒的人的嫉妒,更好的人生 KPI 是,赢得你所敬佩的人的敬佩。




如果成年之后学会不用酒精就能在当下放松下来的方法,你就等于发现了人生游戏的作弊码。




对于一个复杂系统,解决问题短期我们要靠「打补丁」,但长期应该多思考如何「降复杂度」和「去耦合」。如果反映在生活上,大概可能是,要先积累一个长长的行动清单,再慢慢把它变成两三条最重要的做事准则。




通常最重要的决定不是问不问、问什么、怎么问,而是问谁。




在混沌、开放、随机的系统内,建立一个「减少错误」的思维框架要比建立一个「追求正确」的思维框架重要得多。




人啊,兜兜转转,最终还是会回到自己最擅长、最喜欢、最没有内心摩擦阻力的事情上来。当然,之前所有那些不甘心的探索也都是必需的功课。




猫的伟大与神性在于它们可以心安理得地接受别人的爱,而不会觉得惶恐。而人总是反过来,得到了爱也不敢相信,总是反反复复试探来证明自己是值得的。




自从全然接受了「人生充满错误和意外才是常态」的底层哲学,每当生活各方面都进展顺利的时候,我都觉得这是宇宙在给我下一个考验之前的存档点。




最好的方法是你能坚持下去的那个方法。




外界可以干扰到我的,都是我身体里那些还没有对自己诚实的部分。




我决定不 worry about 受众是谁,我就做我觉得对的事。接收到这种感召的人自然会找到我的。




人的蜕变,总是在一个不经意的瞬间发生的。或许在清风明月,或许是树影婆娑,你环顾四周,心里突然涌出了一些无法形容的东西。在那一刻,世界安静了下来,只能听得几声蝉叫,也就在这个刹那,你突然知道,自己再也不是从前那个人了。




你的孩子是怎么样就能定义你是什么样的人吗?不一定。你播客做差了你就是一个混蛋吗?就是一个糟糕的人吗?没关系。重要的是 make it happen(让它发生)。




找到一份满意的新工作的最佳方法可能是,在不需要找工作的时候就开始做一些会让新工作主动来找你的事。




一般爱说「A 的本质就是 B」的人,既不懂 A,也不懂 B,更不懂什么叫「本质」。比如:我觉得人生的本质就是成长。




用他人生活的高光时刻(highlight)来对比自己生活的日常甚至挫败往往是感到不幸福的重要原因。要知道,那些闪光的瞬间只是生活偶尔恩赐予我们的喘息之机而已,苦才是人生的常态。这对(几乎)所有人来说都不例外。




只要你努力成长,不断地超越自我,最终就一定会做上一份超出自己能力水平的工作。




没有信息过载,只有过滤失败。




长期来看,他人会不断观察我对待自己的方式,并最终用同等的方式来对待我。




这个世界上爱自己、尊重自己、认为自己配得上好的事情、应该让自己和好东西站在一起的人实在是太少太少了。这么多年每当想到这个事实,我都觉得人生实在是太残酷了。




以前我选择 A,是因为只知道有选项 A。现在我知道了世界上有 A 和 B,但我最后还是选了 A。我觉得我长大了。




如果任何理念——哪怕是听起来很好的态度和理念——搭配着的是卖给你什么东西的话,那么它就不是一种理念,而是一套粉饰了的广告词。




年纪越长越能体会到一个朴素而有力量的真理:人生中绝大多数事情,不管当时的感受如何,不到最后真的很难判断是好事还是坏事。




随着年纪见长越来越觉得,真正的自控力不是面临诱惑的时候岿然不动,而是让(不好的)诱惑根本不要出现在自己的选项里。人哪有什么意志力这种东西,短期努力一下还能勉强骗骗自己,长期来看我们都只是欲望的奴隶。




要想真正地对人群产生一点积极的影响,就要找到 1 个你想传达的核心 message(信息),然后不断重复地说上 10 年。重点在这两个数字。




整个宇宙其实无时无刻不在跟你对话。你需要做的事是安静下来,然后真正的 listen to it(倾听),然后很多 voices(声音) 就会在你的心中浮现,最终你会发现人生就是四个字,心想,事成。




任何成功法则、人生指南、神学要义就像 E=mc^2 这个相对论公式一样。表达出来当然可以是简单清晰优雅的,每个字母看起来也都认识。但如果自己没从头推导过一遍,光知道结论毫无意义。哦不对有一个意义,就是可以不懂装懂,最终害了自己。




我时常觉得,在这个信息过于丰富的时代,人的注意力往往会被很多东西转移。每个人都在关注潮流、关注变化、关注这一刻又有什么新闻、关注其他人在谈论什么。但实际上,把精力花在那些可知的、能掌控的、永恒的东西上,可能才是更好的策略。人生短暂,还是不要去管那些噪音,去做自己觉得真正重要的事吧。




在一件无需此刻决定的事情上消耗太多心力,其实是不相信未来那个内心更加清晰、也获得了更多信息的自己会做出更好的选择。我永远都相信未来的自己。




我心甘情愿地选择了某一两个镣铐,没有它们,我无法时时刻刻感知到自己有多自由。——学霸猫




向外界的攻击越频繁,向自我的攻击就越熟练。




四处叫得喧天响的东西通常躲着点儿走就没错。




每当感到匮乏时,就可以用给予的方式,让自己重新体会到富足与丰盛。




你在犹豫什么?




对于我很重要的一个投资(做事)理念:要以各种方式(不一定是单纯买入),持续地,double down winners(加注赢家)。




一个破幻与重建自我的重要方法:(在遵守法律法规的前提下)什么事情让你负罪感越多,就越去多做什么事。




实现看似最远的那个理想的最好方式就是直接做。




「别人很好,我也很棒」是一种可以时时练习的心态,如果总敢于认可自己,奇迹就会变成日常。




「潜移默化」是最重要的人生密码。你会是你精神交往最密切的 5 个人的平均水平。




人无法进步的最核心原因之一就是偏见。




在遇到困难、疑惑、挑战的时候,我们总倾向于看到自身的劣势、问题、局限性,总会看到自己「资源不足」的那一方面。但实际上,优势与劣势完全是硬币的两面,完全是可以相互转化的,关键在于你怎么看待和使用它们。




做一个耀眼的人,不是为了灼伤别人,而是为了给周围以明亮。




你最想买的股票从不需要问别人该不该买,就像你最爱的人从不需要问你到底爱不爱 TA。




如果可以的话,我猜巴菲特会愿意以他 99% 的身价来购买我 20 年的寿命(当然这样人家也还剩 8 亿多美元可支配,我也必然不会卖)。但从这个角度来说,我们所拥有的时间是另一些人愿意倾尽所有而换来的,我们是 time billionaire,是真正的亿万富翁。可惜大多数人都不会这么想问题吧。




你是在模拟谁的声音来打压自己的?




人生会永恒地面临孤独问题。不仅是终极的孤独,还有很多日常性的孤独。所以在朋友之间,建立起某种「互助会」一样的组织,大家在没有太多功利性的情况下,彼此交流、分享、相互帮扶,其实会快乐很多。




总习惯寻找 silver bullet(银弹) 了,但有些问题可能就是需要用笨方法解决。




不要用一种学科观看世界。如果你热爱文学,就多去了解一下商业;如果你擅长体育,就去学习一下哲学;如果你的职业是投资,就多跑跑艺术博物馆。通信领域和拓扑学里有个词叫「triangulation」,指的是我们要准确定位一个信号来源往往需要三个角度方向的共同作用。所以我们怎么可以以为仅仅通过一种维度就能正确地认知世界呢?




没有人希望自己的墓志铭上写着「我这一生最大的成就是说服了三百个笨蛋」。时刻想一想你到底希望那块墓碑上写着什么东西。




做了一个好选择的感觉可能是,时常不敢想象自己居然还考虑过另外一个选项。




一个很简单的道理:如果你总是病怏怏的,就说明现在做的事情哪里有些不对,整个人都在对抗它。生病是一种自己与自己的沟通,身体什么都知道。




战争以一方失去战斗意志为结束。




理解世界的一个有效方法是,在人生的某个阶段,把任何之前视为理所当然的事情全都重新研究与思考一遍,并弄清楚它们运行的真正起源与机理。在这个过程中,自问的问题越基础、越显得不需要去质疑,收获往往就会越多——人为什么要每天吃三顿饭、买东西为什么要花钱、书籍和文章为什么会存在——真理通常就藏在这些大多数人想都不会想的事情里。




和正处在事业困惑期的朋友说:如果现在从零开始,不考虑任何过往经历、同时拥有无限选择的话,自己最该选择的职业方向是什么?




几乎对身边所有确实聪明的朋友都提过一个建议:灭掉理论与逻辑,学会用直觉和身体与世界交互。




在工作中少去预测一件事会什么时候发生,而多去关注一件事会不会发生,以及发生的时候自己能获得多大的回报。




伟大的东西和好东西的区别往往是,好东西看起来工整完美,而伟大的东西缺点鲜明。




我个人觉得,总体来说任何需要对外界出现的新信息做出快速反应的工作都是减寿的。我会尽量在自己的工作中把这类内容去除掉。




现在我不认为「人是其经历的总和」了。现在我觉得,人是其信念的总和。




大概能给年轻盆友们的一个建议是,应该把「亲密关系」视为所有「关系」的一个子类去学习、探索与体验,而不要将爱情当成某种神奇的、魔法般的、超然物外的、不受客观规律所约束的东西。毕竟,最终人所有的关系都是和自己的关系。




人们总爱告诉自己达到某种状态之后就可以去做某些事了,殊不知想到要达到这种状态,最好的方法就是现在直接开始做这些事。




今天有比昨天了解自己更多一些么?如果有,那就是没有被浪费的一天了。




快速地得到想要的东西是一个诅咒,缓慢地得到想要的东西是一种恩赐。




十年挥一剑的前提是一剑磨十年。




兴趣技能类的东西,带专业人士反馈的认真练习 100 小时、200 小时 和 400 小时后会出现三次水平飞跃。




人的生命力就体现在一些特别简单的地方:能大口吃饭,能好好睡觉,运动起来活蹦乱跳的,日常敢于表达自己的身体,爱开玩笑和插科打诨,说话的时候会盯着对方的眼睛……反正都是一些说起来很简单的事,但朴素的生命力就是特别有魅力的。




越想甩开的,就越甩不掉;越想留住的,就越留不住。




一个人做一件事的方式,就是 TA 做所有事的方式。




现在朋友想要做点什么事的时候,我都会上来就提示一大堆风险,说得夸张点甚至是以给对方泼冷水和打击积极性为主。当然,这样做的真正原因是,我知道如果我这么说 TA 还是想去做这件事的时候,那 TA 就是真的想去做了,不论结果如何都会很有收获。反过来说,如果我这么一说就成功劝阻了对方,那么这个事情做不做也就无所谓了。




人生的绝大部分时候,不做什么比做什么重要、避免失败比取得胜利重要、忽略噪音比接受信号重要、不把一个问题视作问题,比拼命解决这个问题重要。




在人这件事上,如果 A 不对,那么答案从来不是 A 的反面。




每次去香港穿梭在巨大的商场里都是很开心的,因为你一下就能意识到,原来世界上有这么多东西自己都不需要。




「用魔法打败魔法」这句话背后有一层很重要的含义是,很多问题就不是靠逻辑解决的。




哪有那么多神奇的方法,把功课先重复一千遍再说吧。




痛苦的一个主要来源就是「凡事都要和可能发生的最好情况比」。




不管想做好什么事,停止讨厌自己都是不错的第一步。




问:请问我爱好太多怎么办?感觉什么都有点兴趣。答:不好意思我说过好多遍了——爱好不是你享受的东西,是你即使付出代价和做出牺牲也愿意做,并且还乐在其中的东西。海滩上躺着那不叫爱好,那叫屈服于懒的基因。




只要你探索自我,表达自我,你就是艺术家了。




最近看到的一些在风险管理方面比较失败的例子——商业/组织层面的和个人生活层面的都有——共通之处基本能总结成一句话:在情绪最焦灼的时候做了一个不可逆的大决定。




现在和年轻时一个很大的不同是,学会了更少地去「做」事情,而多「让事情发生」。




不去尝试一件事情有一个很大的好处,就是只要不去尝试,我们就总可以用「不是我做不到,只是我不想」来自我安慰,从而保持那种对自己的良好感觉。绝大多数人都要靠这个东西才能活下去。




需要的东西越少,人的富足感就越高;人的富足感越高,能分享给别人的东西就越多。分享他人的东西越多,生活给予你的也就更多。最后,你需要的越少,得到的东西就越多。




提高人生长期成功概率的一个简单小技巧是,不要在夜里两点之后做重要决策。先睡一觉再说。




信心很足但仓位很小是毫无意义的。




你累了,就休息。谁能让你不休息?人活到某个阶段,你得意识到,没有人能真的逼你做你不愿意做的事。父母、朋友、同事、投资人,谁都不行。你的生活永远是自己说了算。




年轻的时候,由于认知有限经验缺乏,死守一些(正确的)教条是相当有意义的;年纪大了,视野更开阔了,也探索过各种规则的边界,重要的就变成了打破俗知俗见与自己的分别心,多往「飞花摘叶,皆可伤人」那个路数走走。反正最终目的都是从心所欲不逾矩,运用之妙存乎一心么。




《禅与摩托车维修艺术》,这本书里边有一句话我觉得特别有意思,他说你做事不要着急,如果你特别着急做一件事的时候,说明你不喜欢做这件事,你想赶快做完以后做别的事。




我允许父母和家人对我失望,这并没有关系。




可以诚实地表达自我,以及在不想被找到的时候可以不被找到,应该是衡量生活自由程度的其中两个指标。




试着对大部分情况和人 say no。感觉是掌控自己人生的重要方法。




把眼前这个看起来还不错的选项放掉,心中那个最想要的东西就会浮现出来。




用半生的力气,反复学习着抛弃一个念头:「等我怎么怎么样了,就能去做什么和什么了。」




世界上不想上班的人非常多,但不爱工作的人极其少。




世界上没有不知行合一的人,每个人都是 100% 知行合一的。




每天快要结束的时候都想一下,这一天有哪些事是本可以不做的。




相信大数定律。一件事哪怕只有 10% 的把握,连试 20 次之后成功率也有九成。




如果你想让 TA 快乐,因为这样你就会快乐,那么不如跳过这个中间步骤,现在就让自己开始快乐起来吧。




在整个世界都转向宏大叙事的时候,你还是可以选择先照顾好自己的微观生活。




我做过的好的投资:简单、具体、无聊、枯燥,每天按部就班、没太多额外的事做,仿佛一个废物。我做过的差的投资:精彩、刺激、颠覆、革命,每天废寝忘食、上蹿下跳,仿佛全人类的命运就靠我了。




很多时候最好的竞争优势就是「别人觉得麻烦而你不觉得」。




帮助你身边最想帮助那个人的唯一方法就是用心用力地帮助自己。除此之外,别无他法。




很多人可能没意识到,我们有时候讨厌一个自己并不特别了解的人,常常是讨厌对方身上那些自己也有的、但不太喜欢的东西。




在日常和人的交互中,我反复见到最多的人类偏误是这么四个:1. 小样本归因;2. 用结果质量判断决策质量;3. 把分歧等同于冲突;4. 确认性偏见。




偏执地强求自己保持某种健康的生活习惯即是最不健康的生活习惯。




其实大部分的人生真理幼儿园都讲过了——待人真诚、与人为善、遵守秩序、帮助弱者、按时睡觉、好好吃饭。做到的有几个呢?




对的物品,对的工作,对的关系,对的际遇,带来的结果都是同一个:生命的舒展。




「这件事为什么会发生在我身上?」的另一个版本可以是「这件事是来教会我点儿什么的?」




「谨慎地选择你的竞争对手,因为最后你们很可能变得很像。」




保持和好玩儿的、值得交往的好朋友的关系的最好方法,就是多把时间花在自己身上。




在没达到信息收集量的门槛之前,不轻易做判断和决策。多对自己和他人说「我不知道」。




靠大量堆时间而获得的东西是最牢靠的,谁也拿不走。




起初,我想拯救世界;后来,我只想改变自己;最后,我发现它们就是一件事。




实际上我们一生不论想做什么,都不需要任何人的允许和批准——家长、朋友、伴侣、老板、同事、陌生人都没有这个资格,只有你自己可以决定自己是谁、想做什么、去往哪里。而当我们真正地承担起这种对自己生活全然负责的使命之后,宇宙就会奖励我们一个最珍贵的,叫做自由的东西。




只需要一个很好的人,一个就行。一个很好的人来了,就会带来一连串很好的人。当身边聚集的都是很好的人,局面也就自然打开了。




一个不错的成长速度是从生下来第一天开始,每三年积累的认知大致等于之前所有积累的总和。




当你准备好了,你就准备好了。




「机场比婚礼现场见证了更多真挚的亲吻,医院墙壁比教堂聆听了更多诚恳的祷告。」




我们成长中得到的真正裨益,往往不是作为目标直接出现的。一个人在漫长的学生时代所看的书、记忆的知识,并没有那么重要,而经由此磨砺了性格、获得了面对挫败的勇气,则重要得多。




大四面临毕业就业。请问有什么忠告或者建议吗?以你能想象的各种方式,和最好最好最好的人和事在一起。




在大事上给自己增加选项,在小事上给自己减少选项。太多人都给搞反了。




这世界上大部分人根本不知道自己在干什么。不要听他们的话,他们的人生非常可怜。只去找最好的人学,我说的是 the best of the best,找不到生活中的人就看最好的书,坚持下去。别浪费时间了,做自己吧。




定义我们的从来不是我们消费了什么,而是我们创造了什么。




那天和朋友聊到应该和什么样的人一起工作的时候,我说我有一个简单的标准:在找合伙人的时候,我觉得即使让 TA 当我的老板我也不介意,那这就是一个好的合伙人;在找下属的时候,你想象一下两年以后 TA 有没有可能和你平起平坐,能当你的合伙人了。如果可以的话 TA 就是一个好同事。当然这个标准更适用于小团队和公司的初创期。




更新了一下我对自己工作水平高低的评价方法,目前主要是两个指标:1. 有多少人不会拒绝花时间和我随便聊聊天;2. 日常时间有多大程度需要和自己不喜欢的人一起工作;差不多就是这样。




这可能是我们学习很多东西的最好方法:提出假设、充分地获取信息、实地的考察、得出结论,再用自己的实际行动(比如真金白银)来验证自己的结论——所谓的 skin in the game。




完美就是再也无法去掉任何东西。




做出好决策的秘诀往往不是让自己变得多聪明,而是尽可能收集到足够多的正确信息,使得即使是一个笨蛋来做这个决策都出不了什么大问题。




玩的时候就要玩儿透。玩儿痛快了,玩儿开心了,玩儿尽兴了,你就会特别想念干活,一工作起来简直不要太开心,写邮件看报告的时候嘴角都是上扬的。结果玩得也开心,工作效率也很高,回头一看什么也没耽误。最怕的是,玩的时候想着工作难受,工作的时候不甘心又惦记着去玩,最后啥也没干好,两头都得不偿失。人啊,得允许自己大玩特玩,然后工作就会同样顺利起来了。




持续学习与努力工作,有一天你就可能来到这么一个位置,这个位置就是当你发现对方什么都不懂还非要胡扯的时候,你是可以选择站起来直接就走的。




当面临选择与困惑时,也许记住一个原则就足够了——永远向更宽阔之处去。




你永远不需要为真实的自己感到抱歉。




工作上的那些,明明没有必要做,但还是做了,甚至尽最大的诚心做了的事情,会带你走得很远很远。




一个人的价码不是由 TA 拥有多少钱来衡量的,而是由 TA 拒绝了多少钱来衡量的。




每当我听到有人说「我不知道怎么才能系统地学习这个东西」的时候,我在心里都把它翻译成「如果没人帮我整理好总结好并且手把手教我怎么做还得立刻看到效果的话,我就不打算花时间学它了」。




做不到可以有一万个理由解释为什么做不到,做得到大概只有一个理由,就是想做到。




如何在 6 个月内完成你十年后的目标?在这个问题下,线性的职业规划路径已经失效,你必须跳出目前的思考框架,回归到问题本质,然后给出一个自己都觉得有点天方夜谭似的答案。




当我们在做一项相对长期的工作时,一个困扰可能是没有短周期的结果反馈,于是比较难衡量自己是否走在了正确的路上。这时,我通常会关注三个我认为比较重要的指标:第一个,是自己在一段时间内的摄入信息质量是否有提高;第二个,是世界上是否有了更多的人,在我「想和对方见面聊聊」的时候,会选择接受而不是拒绝;第三个,是自己的睡眠质量有没有维持在好的水平。




我想从对方身上获得一些东西的时候,往往就是我说话最不诚恳的时候。




这两年「解救」了我很多,也让我生活更加顺畅的一句话叫做:I have nothing to prove。既然我没什么可证明自己的,那就把手头的事情正正常常地做完就行了。




均值回归才是人生之恒常法则。我期待着下一个自己决策错误、运气不佳、怀疑自我的时期的到来。




如果你现在做的事让所有人都满意,那就说明你什么有价值的事都没有做。




「只要一件事感觉像是冒险,我就会一直做;当它感觉像是工作,我就停下来。」——尼尔·盖曼




生活中绝大部分问题都可以靠成为一个阅读机器来解决。




我会问自己说如果有一天我打网球这件事再也不能发朋友圈或者发微博了,我还会不会打?我还是会打的。所以它对我来说更纯粹。




拉长时间、放大视野,并通过做成一点小事情增加成就感和自信,可以解决人生中几乎所有问题。




当我决定投资自己的时间、资源和资本在他人身上时我一贯和自己确认的三件事:1)这个人是否每次见面都能教我很多的东西;2)想到未来的 5-10 年要和 TA 比较频繁地打交道,自己是觉得麻烦还是会觉得愉悦;3)TA 是不是有理性的野心。




「道理都明白,但就是做不到」的可能性只有一个,就是道理根本没明白。




人真的是教不了的,你只能「教」一些即使没有你最终自己也能学明白的人。




下一个冒险的定论。人生的很多终极秘密就藏在一句简单的话里:你能否在 10 分钟之内,保持脑子里一个念头都没有。如果未来十年里每年回来看看这句话都能有不同的体会,那可能就真的在接近那个最本质的东西了。




你不停找事做,是不是为了逃避做重要的事情?




宇宙只会给你你已经有了的东西,而不是苦苦追逐的东西。如果你感到富裕,宇宙就会给你更多的金钱;如果你觉得自己很健康,宇宙就会让你变得更健康。




你真心给出的,宇宙就会变着花样几倍地给回来。




事业由高光与巅峰所定义,由低谷与挫败所构成。




越复杂,越脆弱。




用 100% 的力气做一件事是比用 80% 的力气做一件事更省力气的。




人如果总是要和自己谈判的话,心就会变得越来越紧绷起来。比如,不需要说什么「忙完这个任务就奖励自己去玩」,我们可以「嗯下面就把这个项目认真做好吧!」,或者「算了不想干活我就要开心去玩耍嘿嘿」——怎样其实都很好,唯一重要的只是给予自己允许。这样很多事就会顺利起来啦。




不要在输入不足的时候强行领悟。




在人生需要具备的各种能力里,哪个不及格,优先练哪个。都及格之后,哪个最喜欢,优先练哪个。




比起提前付出一些努力把事情做对,人们更喜欢先省点事,等出了问题再默默承受它的长久代价。




任何形式的谈判的第一要义都是,随时能够 walk away。合作、买卖、投资、甚至感情都一样。




没那么多为什么和怎么办啊,就是量堆得不够。




在逆境中的领悟要在顺境的时候应用,否则那就是一个假的领悟。




当你紧握着一个东西的时候,那个东西也在以一种「被你紧握着」的方式和你一起存在着。所以当我放过了一件东西的时候,那个东西也就放过了我。




我对你的看法说明不了你是谁,而只说明了我是谁。




每一年里,读 1000 万字,想 100 万字,写 10 万字,听 1 万字,说 1000 个字,信 100 个字,做 10 个字,就差不多了。




很多时候,别人不允许你做一件事,以及在你做的时候还要大加评判与指责的真正原因是:他们心底里很想做这件事,但这些人既不能允许自己去做,也无法接受有的人居然就勇敢——甚至毫不费力——地把这个事情给做了。于是他们唯一能做的,只有通过攻击你,来回避与自己无法和解的那个部分,其实这就是在攻击自己了。




职业生涯前十年的主要任务之一就是找出接下来五十年你想和谁以及什么样的人一起工作。




一个 gap year (period) 更好的利用方式不是思考自己接下来打算做什么,而是在日常持续思考这些问题之后,等 gap 的时候已经可以开始探索和执行了。




只要你想,你就可以高兴、愉悦、狂喜、得意,没有什么东西能阻拦你。所谓的「失态」,也不过是一种世俗的规范。真人眼中是没有「态」这种东西的,只有恣意和纵情本身。




我现在更喜欢的一种讨论方式是这样的:遇到问题的时候,就扔给自己比较信任的几个朋友。然后大家针对同一件事,各自思考、各自调研、各自形成结论——然后一起碰的时候,不管意见相不相同,都把论证过程摆出来给大家看。基于这些独立思考的结果再进行讨论,效果会好得多。如果还得不出什么结论,就各自回去再琢磨。




很多时候,让好的信息与美的事物冲刷你、穿过你、流经你,就已经是一种最好的「学习」了。只是我们的大脑总觉得非要掌握点儿具体的知识点才叫学习,于是就会一闲下来,好像没干什么「正事」的时候就开始焦虑,然后赶紧拿一些东西来填补自己的空虚。这和宇宙运行的真正法则正好是反过来的。




对于生活,我们追求朴素,一切从简:我们赚钱,靠的是记住浅显的,而不是掌握深奥的。




一个正确原则最重要的应用场景不是特别适合应用这个原则的那些场景,而恰恰是看起来并不适合、显得多余和「感觉没必要」的那些场景。只有这种情况下仍然坚持了原则,原则才得以成为真正的原则,而不是一句随喜好、心情和「我们具体情况具体分析」的空洞表达。




感觉打网球、看咨询师和写作都是不论生活状况如何可以坚持到 60 岁的事。能找到这样的东西会让人平静。




我思考过的最蠢的问题之一可能就是到底早上跑步好还是晚上跑步好,和我小时候操心自己是上清华好还是上北大好感觉差不多。




所有事都可以反过来想。想要投资成功,先学习有哪些最容易让投资失败的错误;想有好的人际关系,先去琢磨糟糕的关系有什么特点;想获得理想的生活,先弄明白自己最不想要的生活是长什么样的。然后尽全力地避免它。




外面没有别人,我们在每个人身上看到的都只是自己。




想要从 A 点最快地抵达 B 点,不是要在两者之间划一条直线,而是将整个地图折叠起来,直接让 A 点与 B 点相遇。用三维的视角解决二维的问题其实是无比轻松的。遇到问题永远跳到更高维度思考,是一个可以终身受益的好习惯。




我相信,每个人都能也都应该去找到自己的那个小小领域,做出一些属于自己的,也只有自己能做的作品。而更有意思的是,当你不去追求太多结果,只是享受这个过程的时候,生活就会奖励你一些意想不到的东西了。




一个坏的决策要远远好于迟迟没有决策。




制定过于严密的计划,是不相信自己的心在每个当下都能做出最好的选择。




实际上,在大多数情况下,当你和别人说「别哭、别紧张、别难过、别不开心了」的时候,你试图安慰的不是对方的情绪,而是自己的情绪。




这两年学到的一个人生经验是,如果真的想要一个东西,就不要为了节省成本选择它的某种低配版或者替代品。好东西的价值几乎总是被低估的,而看起来七八十分好像也说得过去的东西其实价值为零。




金钱总是从紧抓着它不放的人流向愿意让它继续去流动的人。




虽然我总被教导(且也常不识趣地教导别人)做事情的最佳驱动力是爱与创造之心,但实际上大部分情况下我做一件事的主要原因还是「这帮人做的是什么垃圾啊算了还是我来吧」。亲测挺有效。




自卑是:我这么对你,是因为我想你也这么对我。否则我会觉得很受伤害。自爱是:我这么对你,是因为我想这么对你,以及你也值得被这么对待。




这是霸猫老师的那个比喻:亲密关系不是我饿了,希望有人给我做顿好吃的;而是我有一桌子好菜,自己吃着很开心,但是有个人来一起吃就更开心了,那么我就高高兴兴地添一双筷子。




人的一生大概就是在给予自己一种允许。允许自己可以感到轻松和愉快而不会觉得惶恐,允许自己可以无所事事而并不感到愧疚,允许自己接受别人的喜欢而不会觉得不配,允许自己变得卓越而不怕体会孤独,也允许自己受到伤害但并不感到这就是末日。给予自己允许,然后改变才能真正地发生。这大概就是我们一生都在追求的东西吧。




世界上有两种人。一种是我受过这么多苦痛,所以要努力让别人少受到这样的苦痛;另一种是我受过这么多苦痛,所以要加倍把苦痛施加给别人。




做自己有个很棒的附加好处,就是别人会因为真实的你而喜欢你,而不喜欢你的人也会自动消失在你的生活里。长期来看这买卖也太划算了。




多做让自己开心的事,而不是让自己能逃避痛苦的事。这两个是完全不同的东西。




每当走了一些弯路的时候,我都会想:哇,我离最终目标又近了一点。




如今在生活中每当遇到一道选择题的时候,我都会把所有选项拿掉,把它变成一道填空题。




如果你不读书也不结交有质量的社交关系,那你每天摄入的所有信息可就只剩你那破工作、想方设法卖给你东西的微信公众号、网上的娱乐节目和天天自己也不知道在干嘛的「朋友」教给你的东西了。想想这样长期下去脑子能不出问题么。




人要想在一件事上做到非常好,重要的是早点放弃那些自己做得「还挺好」的事情。




追求模糊的正确,而不是精确的错误。




大多数对未来变化趋势的「视而不见」不是「没有看见」,而是「看见了但不觉得应该做些什么」。




很多事情,有过一次,你就信了。「信」是最重要的,哪怕只有过那么一次。




我曾非常希望发生的事情,常常在我觉得发生不发生已经都没关系的时候,就自然地发生了。




知道一件事会不会发生,比知道一件事什么时候发生要容易得多。把精力用在准备那些必定会发生的事情上,而不去在意它发生的时刻。




看《Inner Game of Tennis》的时候我学到一句话,叫「表扬是隐藏的批评」。因为当你接受了别人的夸奖,本质上就是把评价自己的权力让渡给了他人。人们今天可以称赞你,另一天也可以诋毁你。所以我总提醒自己,不用在意(几乎)任何人的认可或是否定,也不用扮演任何人期待你出演的角色,就做好自己的事,打好每一个回球,就行。




财富来自于对杠杆的使用,常见的杠杆有:互联网、人力、资本、声望、时间等等。




每天回到家的时候都想想:我的护城河是什么,今天做的事儿有没有加宽这个护城河。




一年有一个好决策就足够了。或者换个角度说,一年里多花点心思做一个好决策。




把自己领域的事情做到最顶级,那么不管其他领域发生了什么,你也其实什么都没错过。因为在最上面那个地方,人与人之间是不分具体领域的,他们都归属于一个统一的名字,叫做「把事情做到了最 NB 水平的人」领域。




感觉带不动别人的时候,不是要向外使更大的力气,而是要把能量收回到自己身上。




我们各自保持优秀,看看宇宙安排如何。




别给自己加戏太多,我做这些事都是为了我自己开心。




反正不管做什么,永远记着「穷则独善其身,达则兼济天下」就行。大方向没问题,人生就错不了。




我的大部分(虽然也不多)的人生智慧都来自于长期反复地观察那些已经拥有了无数资源的人是怎么把自己的生活搞砸的。




我总认为,人的重要成长标志之一就是经历一次精神弑父。这个「父」大部分时候都不是生理上的父亲。如果要大成,甚至可能需要两次。




别的我不知道,但我知道你今年信誓旦旦觉得自己已经知道了、体会了、学到了的东西,明年还会再忘掉、再怀疑和再出错的。And that’s ok.




谁包容谁,谁服务谁,谁就领导谁。




一个人,在并不真正了解你、甚至只在比特世界和你交流过,如果对你表达出过度的、甚至有时近乎偏执的认可、喜爱甚至仰慕的话,那么有极大概率 TA 喜欢的只是一个自己幻想出来的东西。你对于 TA 而言,只不过是满足幻觉的一个载体,而你到底是谁其实一点也不重要。长这么大才慢慢学会不把他人当成承载自己欲望的工具,反过来道理也是完全一样的。




多花时间思考怎么做好手上的事,少花时间幻想走了多少进度条。




不在互联网上说那些你不敢当着那个人的面说的话。一个自我约束。




永远不要用「小透明」这样的词来称呼自己,在每一个很小的事情上,练习用自然、平和、赞美的眼光看待自己。人对自己的称谓,都是说多了就自然灵验的咒语。




「清晰地描述出自己具体的恐惧以及其背后的成因路径」是做生活重大选择和决策之前的一个必备步骤,但是有意愿且有能力这么做的人非常之少。




当你开始做一件事的时候,它会诞生出很多你之前规划的时候想不到的一些东西,一些新的生命力,一些沿途的风景变成了一些新的果实等等。




「正直善良+强烈的个性与价值主张」是作为朋友的一组很好的性格特质。




根器一般,基本功又不牢,如果碰巧拿到顶尖的秘籍,就是最容易走火入魔的。




这世上大多数事情,居然只要耐心地等就可以了。




今日网球教我的事:一切实质性的提高都是在真正地上强度之后发生的。那种自己之前从来没完成过,甚至不敢想的强度。




不要去优化一个本不该存在的东西。




问别人的时候说明你不够懂。




坚定勇敢地照顾好自己、力所能及地传递善意、全局优化自己的长期目标、在能力更大时担负起更多的责任、保持长远的视角和理性乐观的态度......如果能这样生活,就应该不算是个太差劲的人了。




就像我总说的,没听《得意忘形》、忘记听《得意忘形》,就是听《得意忘形》的一部分,甚至可能是更重要的那个部分。大家节日快乐。




「拒绝」这个动作本身就是带来力量感的,尤其是拒绝一些看起来还不错的东西的时候。




最近觉得,和好朋友闹一些小的矛盾(当然不是刻意的),然后等双方气消了再重新谈谈各自当时的状态和感受,之后反而感情和相互的信任都会更好。以后尽量都能这么做吧。




如果真的允许我提点倡议,我特别鼓励和呼吁大家,能善待我们生活中的小动物,最好能用领养代替购买。我知道有些品种的猫啊狗啊就是很萌、也确实很好玩,花钱去买也没什么不对的。但是相信我,一个动物不管长得好看难看,是不是威风凛凛或者甜软可人,时间长了都不那么重要。真正重要的,是那种你和它一起成长,相互信赖,彼此依靠的生命体验。这种东西是世界上最最宝贵最最稀有的,远胜过可以拿钱买来的任何东西。所以如果你真的有心养个宠物,试着去领养一个或者是帮助一个流浪的小动物吧,它们真的也需要一个家。




也许是从小的教育和整个社会性格的原因,我一直觉得我们日常跳舞太少了。哪种跳舞呢?就是那种不管在家里还是在外面,正好听到一段不错的音乐,然后就随性跳一段,甚至就点点头、挥舞一下手臂、摆动一下身体。另一个常见的场景是下了班走路回家,耳机里放着喜欢的歌,那就不用管路人的目光,自顾自地跳一跳蹦一蹦,同样也非常好。




「这个世界不会好了」这种说法更准确的翻译方式是「我决定带着『这个世界不会好了』的信念生活下去了」。




好东西通常是聪明人下笨功夫做出来的,未来想和这样的人一起做点事情。




不用老想什么如何才能变聪明和有智慧,这些都是错的问题。对的问题是:How to be a great evidence-based decision maker(如何成为一个优秀的循证决策人)。




如果离开学校的时间足够长,你就会发现一个真理,那就是对于你和你当时绝绝绝大多数所谓的同学来说,你们之间唯一的共性就是在某段时间出现在了地球的同一个经纬度位置上课,除此之外就没有任何共同点了,甚至有一天你还会庆幸这件事。所以既然如此,此刻就不用太纠结那些微不足道的人际关系了,去做自己觉得正确的事情吧。




作为一个比较相信自己、有很强的信念感、底层性格乐观、也取得过一些小成绩的人,我每周都会有至少几十次自我怀疑和畏惧不前的时刻。这太正常了,let it pass。




反复给学习投资的朋友和刚入行的年轻人强调一个基础概念:一个资产的价格是由愿意出钱买它的人群之间相互交易而决定的,而不是由旁边站着看和指指点点的人群决定的。区别信号与噪音。




人生在世,犯错实乃注定。重要的还是自己始终知道自己希望远离什么、可以承受什么,并由此做每一个清醒的选择。




和很多东西不同,身体是一个你花时间照顾它它就会变好的东西。




如果在一个领域里想表现出色,可以多去研究那些看似特别努力但实际上越努力成绩越差的人都在怎么玩这个 game,然后和他们反着做就行了。




我常苛责别人的,就是我最不喜欢自己也有的。




我以自己所有的人生经验下一个结论:无论遇到多么大的困难,Eat Healthy(吃得健康)、Keep Working Out(保持锻炼)、Sleep Well(好好睡觉)都是让你走出困境的最基本、也是最重要的方法。越是处在困境,就越需要好的精力和创造力去面对它。好的身体和好的状态会自己带你走出困境,要信任它们。这一条也送给我的朋友。




你现在的生活处境基本上是你 24-36 个月之前的决策质量决定的,所以现在你花大部分精力想的也应该是能影响你两三年之后人生状态的事情。




只要你持续保持创造,迟早都会迎来那个意识到「原来自己此前的所有经历,都是为了这个作品」的时刻。




很多时候我宁肯渴着也要等一口冰可乐,感觉这种人生态度也可以多用在别的地方。




其实三年进步 100% 比一年进步 300% 要困难得多。




哪个方法更好是假问题,哪个方法自己更能坚持才是真问题。




真正的快乐,或者说持久的满足感和专注的快乐是来自于创造。




长期来看,在一个领域内保持稳定、持续的输出才是最重要的,而不是每次都意图获取远超平均值的发挥。




互联网最大的问题之一大概是,懂得说「我没有足够的信息使得我可以拥有一个观点」的人实在是太少了。




多做那种,你做的时候感觉好好对待了自己,做完以后会想做更多好好对待自己的事情的事。




成长大概就是这么一个兜兜转转又回到原点的过程。




还记得上一次无忧无虑地和人一起看星星是什么时候么。




凡是我不接受的,我就没法改变。




当我说长线思考的时候,不只是说要想之后一百年的事,而是要想自己死后一百年的事。实际上,对死后想的事情越多,对此生的决策帮助也就越大。




可能是慢慢领会的一个小型人生真谛:你觉得不是问题的东西,就真的不是问题。




有一件事最好是不做的,就是你刚解决了一个问题、克服了一样困难、脱离了一种境况之后,就回过头来指责、嘲笑或者打击仍然处在这种境况里的人。人类有时候希望用这种行为「证明自己真的不一样了」,但它底层的驱动力还是恐惧。不要这么做。




只和自己喜欢和敬佩的人一起工作真的是人生幸福感之巨大来源。




人生的终极母题应该是「如何对抗死亡」。现在我能想到的就是两种方法:1. 将自我与某种更高或宏大的意义连接起来,以达成一种「不朽」的状态。比如为了共产主义而奋斗......或者写一部传世的作品。最终的目的,应该是成为人类文明的一部分;2. 过好每一天、每一分钟、每一秒。当你死时回忆整个人生,觉得没什么可后悔的,就算是成功和死亡和解了。可能佛学说的「当下」也有这个意思。




当他人对你产生期望而你没有达到的时候,是他们预测失败了,而不是你执行失败了。




一般我只让如果死后 20-5000 年之内还会有人提起的人来指导我的生活。




我经常想象的一个画面是,在七八十岁的时候我和我的好朋友们还能一起坐下来吃吃喝喝、聊聊天、散散步、打打游戏甚至录录播客,身边还有猫啊狗啊乌龟啊什么的。人生很苦,身边有一些真正懂你爱你的人,大家相互支持和理解,还是非常非常重要的。




对于我,这几年好像也是个「叛逆期」。循规蹈矩了二十几年,才学着不去隐隐地满足社会和他人的期待,而是按照自己的意愿展开生命。




做决定的意思不一定就是「做决定」。不做决定就是一个决定,决定随便做个决定也没什么影响也是一个决定,决定什么时候再做一个重要决定同样是一个决定。很多时候,这几种决定比起我们常说的「做决定」,是更重要的决定。




看似两个观点分歧巨大的人,其实他们彼此同意的部分,往往要比他们互相不认同的部分多得多。换种方式讲,很多时候两方其实对一件事 95% 的看法都一致,但吵的时候就很容易聚焦在那 5% 的地方来回拉扯。




达成假想目标之后的那句「然后呢?」可能是世界上最有价值的问题之一。




最近使用的一个购物方法:在买东西之前问自己,如果现在可以免费获得这个东西,或者可以获得同等价值的现金,我会更想要哪个。只有当答案是前者的时候才考虑把东西买下来。




双十一好物推荐:脑子。




做好的内容的确是普通人撞上正面黑天鹅最好的方法了。




不要吝惜去传递人与人之间哪怕最微小的一点善意。在如今这个时代,爱可能是我们唯一真正拥有的东西了。




遇到「这个很好,但是我不喜欢」的东西是很幸运的,因为在这个过程中,我们再一次接近了自己。




元目标,大决策,真问题。




我一直提倡一个读书原则叫「始乱终弃」...其实就是说别把读书弄的太严肃。看一半不想看就扔,今天看这本明天就换也没事儿。最重要的是自在。




目标这个东西最大的问题是,当你达到它的时候,它就消失了。




余生做两件事大概就不会出错:分配资源资本以塑造物理世界,写作讲话以改变观念世界。The rest will take care of itself.(其余的会自己处理的。)




很多时候我们希望把自己做的东西弄到最完美才愿意拿出来,不是因为我们的自尊心太高了,而是因为自尊心太低了。




我知道所有这些弯路都是必须的。




承言者丧,滞句者迷。由艺入道,借假修真。宠辱不惊,昭然自在。如果能始终怀抱着这些信念,想必可以让我们如秉烛达旦一般,度过此生了吧。




什么是你的优势,什么就是你成长中最坚固的障碍。




年底的时候除了自我总结以外还很适合做一件事,就是去感谢一下这一年里带给你启发或感动的,一直在坚持创造好内容的人们。不管是留言鼓励、私信感谢、现金赞赏、或者去买点他们的作品送给朋友都可以——形式其实无所谓,重要的是让微小的善意流动起来。




多和「真、善、美」的东西在一起。它们的珍贵程度也正是这个顺序。




语言的边界即是思维的边界。其实不是你的表达能力不好,是那件事你还没有真正想明白。




一件事情好转过程的最大特点就是它会反复,正如一时的退步是长期进步的必要组成部分一样。甚至可以说,如果一个人在某件事上一往无前从没受到挫折,TA 这条路很可能是走错了。




人吧,有的时候,一没忍住,做了那个 75 分的事情,就把某个 120 分的事情挡在大门之外了。




对于几乎所有事情,我们都可以大胆去争取,也敢于被拒绝。




人们总说。小时候觉得这是说哪怕一个人日子也要过得充实,自己能安排好各种活动——看书、运动、娱乐、写作、旅行......不管在哪儿都能玩得很好。后来长大了才明白,真正的「独处能力」是,哪怕什么都不做,内心也是充盈和平静的,并不需要什么外物来填充自己的时间。




绝大多数的 2022 年市场展望:把 2021 年最后两个月发生的事情,按照一种最浅显的线性逻辑推演一下,然后在来年春天就被彻底抛弃的一种青少年智力水平的幻想文学。




想要一个长期计划成功,就要允许它时不时就失败。




写不出稿来的时候一般怎么办?我一般的方法是读读读、看看看,素材都熟了以后,我就出去买个咖啡遛个弯,在心里像讲故事一样讲一讲,想象一下李安想拍这个电影,找你聊聊故事梗概,你们俩在马路上遛弯,你怎么给他讲,不用太添油加醋,但是该讲的都讲出来,理顺,让他觉得东西能拍,回来一写就差不多了。




和一位年轻小朋友说:很多人在人生的某个时刻,都要接受自己其实只是个普通人,并没有什么特别之处的事实。而对你来说,你的功课就是要接受自己并不是个平凡人,是的的确确与众不同的。你越早意识到这一点,越早习惯于他人的审视、猜忌和指摘,就能越早地利用这种不同做些真正有意义的事情。最终你会知道,这才是最重要的。




年轻的时候觉得奋斗和努力是最重要的,整天想着怎么「精进」,长大以后没想到能够无所事事、敢于无所事事才是特别宝贵的。




Not giving a fuck(毫不在意) 是需要练习的,这也是人生最值得的练习的技能之一。




语言(和文字)往往只是思维(思想、思路等等)的一个降维映射。在「用语言把思维说出来」的过程中,所有那些「无法被语言描述」的东西就被有意无意的忽略了。但这些东西往往更加重要。




很多时候,说「我不理解,但是我愿意听」比说「我理解,我明白」要更有意义得多。




不管做什么,永远选择自己最心动的,其他的都不用管,纠结就会减少很多很多,甚至一切都开始变得顺利起来。如果还没看到很心动的,或是特别心动的暂时没法得到,那就继续做现在的事情就好,哪里也不用去。属于你的东西,宇宙总会再次发来信号的。当然,心越澄澈,信号就会接收得越准确哈。




想起巴菲特说,如果回头看看活过的八十几年里,除了生病和爱的人去世以外,所有他当时以为是天大的坏事的东西,最后其实都变成了好事。我现在也越来越觉得是这样。就把这句话送给我的一些朋友。




假设你公司给你一个不停薪留职,给你一年时间去浪,每月给你发工资,你想干吗?大部分人是回答不出来的。




假设你有一定的经济基础,可以资助你身边某个(或某些)朋友一年合理的生活开销让 TA 专心创作,然后换取 TA 最终作品所带来所有收入的 10% 的话,你会怎么选?你的标准是什么?




如果想维护一个长期的比较好的伴侣或者朋友关系,那么赞赏与给对方提意见的比率最好在 4:1 -- 5:1 左右。这里面有两个小事:一是比率不能太低,如果 1:1 可能就...药丸;二是那个「1」也不可或缺,只一味地赞同对方,关系慢慢就会变得虚伪;该批评的时候批评,帮助对方不断变好也是很重要的。




仔细想想,无论你的日子是什么样的,无论你满意还是不满意,它可能都是地球上另外一些人的梦想中的生活了。




你要想跑步得第一名你就自创一条赛道,那你就是第一名了。




绝大部分时候,最好的选项都是那个可以带来更多选项的选项,同时也是那个可以让你随时终止这个选项的选项。




为了逃避一些重要问题而进行的努力,可能比不努力的危害还要更大一点儿。




如果一个事情重要且不容易,那么不自信的人根本不会开始做,能力不行的人做一两年就做不下去了,聪明人第三四年通常会放弃因为选择太多,五六年要没起色很多任劳任怨的人也会坚持不下去。所以如果真的能把一件事持续地做个十年、十五年、二十年,你就会环顾四周发现自己怎么突然就赢了。




其实人们常渴望的那种「内心强大」是不存在的。因为「强大」的潜台词好像是,遇到什么困难和问题都可以不当回事或者能轻松搞定——但真实的人生告诉我们,「强大」更多意味着在遇到困难、疑惑和恐惧的时候,能够继续前进、保持乐观、努力地生活下去。所以,从来没有什么「无所畏惧」,有的只是我们在感到害怕的时候,最终做出的选择。




预测的主要危害之处不在于预测错误,而是让人们认为有些事情是可以预测的。




为什么非要下个定义?因为只有把一件事定义清楚了,我们才能明确它、理解它、靠近它。以及,把一件事写下来的动作本身就是一个内化(internalize)它的过程。




忽视自己的真实感受,急于摆脱当下的境况,制定不理性的目标和计划,无法做到时产生羞耻与自责的情绪,消沉之后仍然否认自己当下的状态,继续制定不理性的目标和计划,再次无法做到时加深羞耻与自责——这即是当代人习得性无助式生活的永恒怪圈了。




瞄准月亮,即使失败了,也能落在星星上。




比喻是语言里最超越文字逻辑和局限的东西。在生活中要做一个好的比喻家。




我知道,有些事情我之所以还没去做,和我的能力、时间、甚至意愿几乎没有什么关系,而是因为有一些东西拦在那里,阻挡了我向前的路。这些东西可能是某种羞耻感、可能是某种罪恶感、可能是害怕别人的评价和眼光、可能是对需要支付代价的恐惧......总之,它和我的能力无关,而只和我自己的执念有关。找到它们,面对它们,消除它们,才是最最重要的。




人还是要勇敢地走自己的路,至少不要让那些一辈子什么也没做出来的平庸的笨蛋,来指导你的生活了。




想要一个东西就大胆去要,但别包装成别的东西去要。越复杂的东西就越脆弱,而最简单的东西如一把光剑划破虚空,生出奇迹。




鼓励大家多给好的内容创作者付费,但最好能找到不被大平台剥削太多的渠道(比如创作者的个人网站、个人支付账号等等)。这才是对 TA 们的更好的保护和支持。




少年得志可喜,大器晚成可贺。但起点就高、日后还能不断突破自己的,可能更加弥足珍贵一些。




人生是一个自我实现的预言。




要一直做那种,如果赢了,就可以特别幸福和开心、如果输了,就可以收获一个可以讲一辈子的故事,的事情。




允许奇迹发生。




任何「达到这种状态就永远没问题了」的想象都是幻觉——不管这种状态是拥有很多钱、获得完美的伴侣,还是达到开悟的境界。实际上,如果真的有「完美」,达到这一刻的时候,整个宇宙都会再次大爆炸(可能是比喻,也可能不是)。因为到了完美,世界就「没有地方可去了」,只能归零与重启。无需追求完美的自洽。那一天只会在宇宙的尽头到来。




人生中大多数事情你都不用做什么,居然只要等待就可以了。




人生中绝大部分问题就像一块绢布上的褶皱,你把其他地方展平了,这个褶皱也就自然消失了。而花时间去研究褶皱的颜色、形状和材料学结构,反而是缘木求鱼的。 如果再换一个层级想,褶皱能被称作是一个「问题」么?其实并不能。它只是一个特定时间和空间下,由各种动因与机缘产生的一个现象罢了。绢布上总是要有褶皱的,但绢布永远还是绢布,从来没有变过。




最近我在练习更加直接地和别人表达好感和善意。很多时候真诚地说一句「今天见到你好开心啊」或者「虽然刚认识但是我们应该找时间多一起玩」就是最合适最美好的表达了。现代人的确爱含混不清地发射各种模糊信号,在不跨越太多边界的情况下,简单直接一点,诚实地说出心中所想,不去忧虑对方是否可以对等地回应,会让你收获意想不到的真挚友谊。




当我和别人交流,遇到那种对方很简洁地就把一件我一直在思考的事情准确地解释清楚的情况时,我会知道这不是因为我们的想法多么一致,而是大家水平相差太远,于是对方可以有足够多的空间,向下跨越好几个认知的阶梯,把事情翻译成我能听懂的样子罢了。 ​​​




要给自己设立一个有野心的认知水平成长速度,比如如果每过两三年你没把大部分曾经以为是「老师」的人都抛弃,说明你的速度还不够快(但也不用心急,知道这个事情就好)。因为相信我,大部分人的格局上限其实非常低,那点儿小聪明用个三五年还行,越往后就越只能重复自己,没什么突破然后就自然就停止生长了。我这些年见过太多初看惊艳但是过两年发现仍然在原地踏步的人。Don’t be one of them.




很多时候人不是对对方生气,而是对自己怎么还需要和这样的人打交道而生气。




对手是最好的老师,因为 TA 总是无情地指出你的问题,并在反复针对你的过程中,帮助你成为一个更好的人。记得时时感谢他们的存在,然后找一天,把比赛赢回去。




判断在一件事上应该坚持还是放弃的其中一个维度可能是:有没有更好的选项可以服务自己的长期目标,如果有,那么放弃这件事也就没什么的。换个角度讲,「坚持」这个品质更适合于服务全局目标,而「灵活」更适于使用在具体任务上。




比起以前,现在更愿意看着朋友去犯错误,而不是非要跳进去阻止它。给予尊重和陪伴,不去剥夺对方在困境中觉醒的机会,让每个人完成自我成长的功课。




其实很多年后我才明白,「叶公好龙」是绝大多数人生活的真实状态。很多时候我们并不是真的想要一个东西,我们要的是「想要一个东西的感觉」。




好的决策者身边的每一个人都可以做决策,而你存在的任务就只有两个:只做哪些只有你能做的决策,并帮助你身边的人成为一个更好的决策者。




成年人法则:Agree to disagree。




问题往往不是被解决的,而是被消除的。




你永远只能看到别人怎么做,而无法知道别人怎么想。




时常忘记也反复提醒自己的人生准则:You just can’t have it all




我现在工作层面所有大决策的底层逻辑都是:这件事如果失败了我会有10% 的进步,但是万一成功了应该会带来 10 倍的回报。




宇宙只会给你已经有了的东西,而不是苦苦追逐的东西。如果你感到富裕,宇宙就会给你更多的金钱;如果你觉得自己很健康,宇宙就会让你变得更健康;




宇宙法则在每一件小事,每一个瞬间起作用。如果你一边说自己很富裕,一边又为鸡毛蒜皮的小东西斤斤计较,宇宙就知道你仍然感到匮乏,于是它可能把你有的东西拿走,来配合你把匮乏感这个戏码演完。




宇宙只会给你真正需要的东西,而不是你说自己需要,但其实并不需要的东西。




想象一下自己5-8 年以后的主业会是什么,不准确也没关系,但现在先以一个小 10-100 倍规模的方式用业余时间做起来 。




最近试着在把日常语言系统里的一些「应该」替换成「值得」。比如「你应该换个工作」变成「你值得换个工作」,「你应该去运动和健身」变成「你值得去运动和健身」。当然还有指向自己的,比如「我应该放松一下享受生活」变成「我值得去放松一下享受生活」。感觉这样说久了是会带来一些潜移默化的改变的。




「什么是聪明」?一是信息量的问题,足够多的量很重要;二是从信息点跳跃到邻近多个信息点的能力(越远越好);三是抽象能力,能把事物具象化解后抽离本质(和第二点有重叠);最后的聪明是「智慧」,可能是世界观的一种达练 。




所谓缺点,应该是那些如果你彻底改掉之后,并不会有另外一些好的东西随之也消失的特质。否则那不能叫做一个缺点,而是一个硬币的两面 。




什么是「发自内心」地喜欢呢?就是你不对结果患得患失,只是单纯地想实现这个过程的时候。换句话说,宇宙在你不需要它的帮助也一样会去做这件事的时候,就会来帮助你了




什么是「平常心」?一个阶段性的答案是:把简单、正确的事情,重复做,不相信也不追求快速而一劳永逸的必胜之法。




当别人发表某种「观点」或是告诉你某种「建议」的时候,想一想 TA 的人生至此,可曾真正做好了任何一件事情,以证明 TA 对这个世界是有着超出常人的认知的?




风格是一种结果而不是一种能力。我们不是有了某种风格之后再去做相对应的事情,而是在长期坚持做自己认为对的事情之后,慢慢形成了某种风格。




不定期地检视一下你的核心信息来源是什么,它到底是不是足够好。我是说,每个人都需要摄入那些娱乐、轻松、看完就忘的东西,这些都没关系——但你究竟「允许」哪些信息一点一点改变了你,改变了你的认知、观念、格局,它们到底是滋养还是消耗了你的生命。这些你的人生真正倚仗的、最核心的东西,它们真的足够好吗?




产生高质量谈话的一个简单技巧:不要和我说结论,和我说推导过程。




当你进行各种各样的创作的时候,比如坚持写微博、坚持拍好的照片、坚持录播客、坚持让一些人持续的听到你的想法和声音......都是在给自己增加一种「意外好事发生」的概率。当你的作品被传播出去了,可能就会碰到一些志同道合的人,甚至某一天被某个重要的人听到,而他们就有可能给你带来新的视野、新的感受、新的机会,也许机缘巧合你就打开了一个新的世界。

- +
作者:2xiao
+ diff --git a/react/1.1.html b/react/1.1.html index 78443cdc07..eb12bf07a9 100644 --- a/react/1.1.html +++ b/react/1.1.html @@ -8,7 +8,7 @@ - + @@ -132,7 +132,7 @@ 2.1 实现 JSX → -

- +

+ diff --git a/react/2.1.html b/react/2.1.html index c2c8ea9d23..33f92a6806 100644 --- a/react/2.1.html +++ b/react/2.1.html @@ -8,7 +8,7 @@ - + @@ -23,7 +23,7 @@ ←

- +

+ diff --git a/react/index.html b/react/index.html index 2f5e3649ec..ada60930d5 100644 --- a/react/index.html +++ b/react/index.html @@ -8,7 +8,7 @@ - + @@ -21,7 +21,7 @@ 1.1 项目框架搭建 → -

- +

+ diff --git a/run/blog/before_quit.html b/run/blog/before_quit.html index 017afec289..ba3f005cf2 100644 --- a/run/blog/before_quit.html +++ b/run/blog/before_quit.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 回到小镇的一些感受 → -

- +

+ diff --git a/run/blog/go_home.html b/run/blog/go_home.html index 43d34a76c8..bba676a878 100644 --- a/run/blog/go_home.html +++ b/run/blog/go_home.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 我和金钱的关系 → -

- +

+ diff --git a/run/blog/grandma.html b/run/blog/grandma.html index b632d54e61..62554cedd4 100644 --- a/run/blog/grandma.html +++ b/run/blog/grandma.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 裸辞前要做的五件事 → -

- +

+ diff --git a/run/blog/miss_bj.html b/run/blog/miss_bj.html index 0e27c98a02..58609815b3 100644 --- a/run/blog/miss_bj.html +++ b/run/blog/miss_bj.html @@ -8,7 +8,7 @@ - + @@ -26,7 +26,7 @@ 新年的一件小事 → -

- +

+ diff --git a/run/blog/money.html b/run/blog/money.html index ea70689f46..0943000339 100644 --- a/run/blog/money.html +++ b/run/blog/money.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 一个改变人生的选择 → -

- +

+ diff --git a/run/blog/new_year.html b/run/blog/new_year.html index cc0dc5011e..4717b57448 100644 --- a/run/blog/new_year.html +++ b/run/blog/new_year.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 外婆和她的房子 → -

- +

+ diff --git a/run/blog/principle.html b/run/blog/principle.html index 2c446f2636..fe4a2d3bbf 100644 --- a/run/blog/principle.html +++ b/run/blog/principle.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 未来三年的计划 → -

- +

+ diff --git a/run/blog/three_years_plan.html b/run/blog/three_years_plan.html index 3665b34026..626709a400 100644 --- a/run/blog/three_years_plan.html +++ b/run/blog/three_years_plan.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 关于加班 → -

- +

+ diff --git a/run/blog/work_overtime.html b/run/blog/work_overtime.html index 09c06a6103..5784567c01 100644 --- a/run/blog/work_overtime.html +++ b/run/blog/work_overtime.html @@ -8,7 +8,7 @@ - + @@ -21,7 +21,7 @@ ←

- +

+ diff --git a/run/europe/0_why.html b/run/europe/0_why.html index 2f2de6df36..19629b05ad 100644 --- a/run/europe/0_why.html +++ b/run/europe/0_why.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 肉翻欧洲基础科普 → -

- +

+ diff --git a/run/europe/1_intro.html b/run/europe/1_intro.html index 0b3baf7a66..ccc5719dd5 100644 --- a/run/europe/1_intro.html +++ b/run/europe/1_intro.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 偶尔还是会想念北京 → -

- +

+ diff --git a/run/index.html b/run/index.html index 5db2ddebbd..9dc8c78857 100644 --- a/run/index.html +++ b/run/index.html @@ -8,7 +8,7 @@ - + @@ -17,7 +17,7 @@ (opens new window)

# 肉身翻墙

本部分内容与肉身翻墙相关,分享包括美国生活体验、欧洲找工作经验等。

开始阅读 ->

- +
作者:2xiao
+ diff --git a/run/usa/10043.html b/run/usa/10043.html index ab4d8910d0..3704edbb1c 100644 --- a/run/usa/10043.html +++ b/run/usa/10043.html @@ -8,7 +8,7 @@ - + @@ -28,7 +28,7 @@ 为什么肉翻欧洲 → -

- +

+ diff --git a/run/usa/digital_nomad.html b/run/usa/digital_nomad.html index 2e96141dff..9707d63edf 100644 --- a/run/usa/digital_nomad.html +++ b/run/usa/digital_nomad.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 帮美国邻居搬家 → -

- +

+ diff --git a/run/usa/indian.html b/run/usa/indian.html index 7541c4ca47..ad620a0610 100644 --- a/run/usa/indian.html +++ b/run/usa/indian.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 密西西比自驾游 → -

- +

+ diff --git a/run/usa/live_in_us.html b/run/usa/live_in_us.html index bb615343d3..dfef5c7171 100644 --- a/run/usa/live_in_us.html +++ b/run/usa/live_in_us.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 做数字游民是一种怎样的体验 → -

- +

+ diff --git a/run/usa/mississippi.html b/run/usa/mississippi.html index e1ce28d4e3..4c347a11a3 100644 --- a/run/usa/mississippi.html +++ b/run/usa/mississippi.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 如何拿到美国十年B签 → -

- +

+ diff --git a/run/usa/neighbor.html b/run/usa/neighbor.html index fc2210e3f3..aaba760499 100644 --- a/run/usa/neighbor.html +++ b/run/usa/neighbor.html @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ 黑下来的印度老哥 → -

- +

+ diff --git a/run/usa/quit.html b/run/usa/quit.html index a51c889c08..33794b30e0 100644 --- a/run/usa/quit.html +++ b/run/usa/quit.html @@ -8,7 +8,7 @@ - + @@ -17,7 +17,7 @@ (opens new window)

# 大厂裸辞的心路历程

  • 在大厂工作的好处
  • 存多少钱才能辞职
  • 父母对于辞职的看法
  • 辞职了还能找到工作吗
  • 辞职的原因
- +
作者:2xiao
+ diff --git a/run/usa/transfer.html b/run/usa/transfer.html index 5adf8de409..1dcf21e6f7 100644 --- a/run/usa/transfer.html +++ b/run/usa/transfer.html @@ -8,7 +8,7 @@ - + @@ -17,7 +17,7 @@ (opens new window)

# 什么人适合润到美国

Last updated on 2023-10-28

更新时间: 2023-10-28
- +
作者:2xiao
+ diff --git a/run/usa/visa.html b/run/usa/visa.html index 6f12243326..813287dc7e 100644 --- a/run/usa/visa.html +++ b/run/usa/visa.html @@ -8,7 +8,7 @@ - + @@ -72,7 +72,7 @@ 10043润美方法 → -

- +

+ diff --git a/run/usa/where_to_go.html b/run/usa/where_to_go.html index 48d0c67a51..63fcce01ea 100644 --- a/run/usa/where_to_go.html +++ b/run/usa/where_to_go.html @@ -8,7 +8,7 @@ - + @@ -22,7 +22,7 @@ 在美国生活的一些感受 → -

- +

+