2022年你需要了解的 13 种 JavaScript 代码技巧
分类专栏: Javascript&
简介 分享一些我常用的代码优化技巧,希望对你有帮助。
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">1. 多表达式多 if 判断</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">我们可以在数组中存储多个值,并且可以使用数组include方法。</p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 236px; list-style-type: none; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="javascript"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> (x === <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">'abc'</span> || x === <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">'def'</span> || x === <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">'ghi'</span> || x ===<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">'jkl'</span>) {</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">//logic</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">}</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> (['abc','def','jkl'].includes(x)) {</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">//logic</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">}</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">2. 简写 if else</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">如果 if-else 的逻辑比较降低,可以使用下面这种方式镜像简写,当然也可以使用三元运算符来实现。</p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 314px; list-style-type: none; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; visibility: visible; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="bash"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> <span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">test</span>: boolean;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> (x > 100) {</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">test</span> = <span class="code-snippet__literal" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">true</span>;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">} <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">else</span> {</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">test</span> = <span class="code-snippet__literal" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">false</span>;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">}</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> <span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">test</span> = (x > 10) ? <span class="code-snippet__literal" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">true</span> : <span class="code-snippet__literal" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">false</span>;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 也可以直接这样</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> <span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">test</span> = x > 10;</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">3. 合并变量声明</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;">当我们声明多个同类型的变量时,可以像下面这样简写。</p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 158px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="javascript"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长 </span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> test1;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> test2 = <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span>;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短 </span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> test1, test2 = <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span>;</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">4. 合并变量赋值</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;">当我们处理多个变量并将不同的值分配给不同的变量时,这种方式非常有用。</p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 210px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="makefile"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长 </span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">let test1, test2, test3;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">test1 = 1;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">test2 = 2;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">test3 = 3;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短 </span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">let [test1, test2, test3] = [1, 2, 3];</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">5. 运算符</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;">如果仅在变量值为 true 的情况下才调用函数,则可以使用 运算符。</p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 184px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="cpp"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长 </span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> (test1) {</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> callMethod(); </span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">} </span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短 </span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__function" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">test1 <span class="code-snippet__title" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">callMethod</span><span class="code-snippet__params" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">()</span></span>;</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">6. 箭头函数</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 184px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="javascript"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长 </span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__function" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">function</span> <span class="code-snippet__title" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">add</span>(<span class="code-snippet__params" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">a, b</span>) </span>{ </span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> a + b; </span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">} </span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短 </span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">const</span> add = <span class="code-snippet__function" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">(<span class="code-snippet__params" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">a, b</span>) =></span> a + b;</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">7. 短函数调用</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;">可以使用三元运算符来实现这些功能。</p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 314px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="javascript"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">const</span> fun1 = <span class="code-snippet__function" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__params" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">()</span> =></span> <span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">console</span>.log(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'fun1'</span>);</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">const</span> fun2 = <span class="code-snippet__function" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__params" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">()</span> =></span> <span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">console</span>.log(<span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'fun2'</span>);</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> test = <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span>;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> (test == <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span>) {</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> fun1();</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">} <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">else</span>{</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> fun2();</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">}</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">(test === <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span>? fun1:fun2)();</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">8. Switch 简记法</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;">我们可以将条件保存在键值对象中,并可以根据条件使用。</p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 652px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="markdown"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">switch (data) {</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> case 1:</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__code" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> test1();</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> break;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> case 2:</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__code" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> test2();</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> break;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> case 3:</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__code" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> test();</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> break;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> // And so on...</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">}</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">const data = {</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> 1: test1,</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> 2: test2,</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> 3: test</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">};<br /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="color: #333333;">data[something] data[something]();</span></span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">9. 默认参数值</strong></span></p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 288px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="javascript"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__function" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">function</span> <span class="code-snippet__title" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">add</span>(<span class="code-snippet__params" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">test1, test2</span>) </span>{</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> (test1 === <span class="code-snippet__literal" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">undefined</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> test1 = <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span>;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">if</span> (test2 === <span class="code-snippet__literal" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">undefined</span>)</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> test2 = <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">2</span>;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"> <span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">return</span> test1 + test2;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">}</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">const</span> add = <span class="code-snippet__function" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">(<span class="code-snippet__params" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">test1 = <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">1</span>, test2 = <span class="code-snippet__number" style="outline: 0px; max-width: 1000%; color: #0e9ce5; box-sizing: border-box !important; overflow-wrap: break-word !important;">2</span></span>) =></span> (test1 + test2);</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">10. 扩展运算符</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 392px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="kotlin"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长-合并数组</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">const data = [1,2,3];<br /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">const test = [4,5,6].concat(data);<br /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短-合并数组</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">const data = [1,2,3];<br /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">const test = [4,5,6, ...data];<br /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><br style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;" /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长-拷贝数组</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="color: #333333; font-family: Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="font-size: 14px; letter-spacing: 0.544px;">const test1 = [1,2,3];</span></span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">const test2 = test1.slice()<br /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短-拷贝数组</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="color: #333333; font-family: Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="font-size: 14px; letter-spacing: 0.544px;">const test1 = [1,2,3];</span></span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="color: #333333; font-family: Consolas, Liberation Mono, Menlo, Courier, monospace;"><span style="font-size: 14px; letter-spacing: 0.544px;">const test2 = [...test1];</span></span></span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">11. 模版字符串</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 132px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="javascript"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">const</span> welcome = <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'Hi '</span> + test1 + <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">' '</span> + test2 + <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'.'</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">const</span> welcome = <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">`Hi <span class="code-snippet__subst" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">${test1}</span> <span class="code-snippet__subst" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">${test2}</span>`</span>;</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">12. 简写对象</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 184px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="javascript"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> test1 = <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'a'</span>; </span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> test2 = <span class="code-snippet__string" style="outline: 0px; max-width: 1000%; color: #dd1144; box-sizing: border-box !important; overflow-wrap: break-word !important;">'b'</span>;</span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 长 </span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> obj = {<span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">test1</span>: test1, <span class="code-snippet__attr" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">test2</span>: test2}; </span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 短 </span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__keyword" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">let</span> obj = {test1, test2};</span></code></pre>
</section>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span style="outline: 0px; max-width: 100%; font-size: 18px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><strong style="outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">13. 在数组中查找最大值和最小值</strong></span></p>
<p style="outline: 0px; max-width: 100%; clear: both; min-height: 1em; color: #222222; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; font-size: 17px; letter-spacing: 0.544px; text-align: justify; background-color: #ffffff; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </p>
<section class="code-snippet__fix code-snippet__js" style="margin-top: 10px; margin-bottom: 10px; outline: 0px; max-width: 1000%; font-size: 14px; color: #333333; position: relative; background-color: rgba(0, 0, 0, 0.03); border: 1px solid #f0f0f0; border-radius: 2px; display: flex; line-height: 26px; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', Arial, sans-serif; letter-spacing: 0.544px; text-align: justify; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<ul class="code-snippet__line-index code-snippet__js" style="padding: 1em; outline: 0px; max-width: 1000%; counter-reset: line 0; flex-shrink: 0; height: 106px; list-style-type: none; box-sizing: border-box !important; overflow-wrap: break-word !important;">
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
<li style="outline: 0px; max-width: 1000%; list-style-type: none; text-align: right; box-sizing: border-box !important; overflow-wrap: break-word !important;"> </li>
</ul>
<pre class="code-snippet__js" style="padding-top: 1em; padding-right: 1em; padding-bottom: 1em; outline: 0px; max-width: 1000%; overflow-x: auto; white-space: normal; flex: 1 1 0%; box-sizing: border-box !important; overflow-wrap: break-word !important;" data-lang="javascript"><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;">const arr = [1,2,3];<br /></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">Math</span>.max(…arr); <span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 3</span></span></code><code style="padding: 0px; outline: 0px; max-width: 1000%; text-align: left; font-size: 14px; white-space: pre; display: flex; position: relative; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet_outer" style="outline: 0px; max-width: 1000%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><span class="code-snippet__built_in" style="outline: 0px; max-width: 1000%; color: #ca7d37; box-sizing: border-box !important; overflow-wrap: break-word !important;">Math</span>.min(…arr); <span class="code-snippet__comment" style="outline: 0px; max-width: 1000%; color: #afafaf; font-style: italic; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 1</span></span></code></pre>
</section>
分享到:
转载:
https://mp.weixin.qq.com/s/l5ya7Kagm_xpFFX4EWvKTA
喜欢 0
收藏
暂无评论信息
- 文章推荐
-
亚马逊推出“无需收银员”的新技术,以此帮助品牌和广告商提高销量
北京时间 6 月 30 日早间消息,据报道,亚马逊发明了一种无需收银员的技术,可以加快人们去杂货店或便利店的速度。现在,该公司希望利用这个跟踪系统来帮助品牌和广告商提高销量。&
-
docker搭建jenkins环境执行宿主机的docker无权限的解决方法
初次搭建jenkins持续集成工具的时候,在运行项目阶段出现 permission denied的情况
-
jQuery 3.0正式发布
jQuery 基金会刚刚发布了该 Java 框架的 3.0 版本,并且首次抛弃了对老旧的 IE 浏览器的支持。jQuery 3.0 的工作始于 2014 年 10 月,其最初目标是在 2.0 版本之上进行完善,并和遥远的 1.0 版代码说再见——因为要兼容 IE 的缘故,其已经臃肿不堪。jQuery 2.0 已经与 1.0 版本完全不兼容,而 3.0 也将继续这一路线。
-
Docker 常用命令
docker目前代替虚拟机使用的一个容器,灵活好用。
- 点击排行
- 站长推荐
- 猜你喜欢
- 网站信息
- 站内问答:12篇
- 站内文章:213篇
- 建站时间:已运行1217天
- 备案号: 浙ICP备2022018799号
- 语言:
- English(USA)
- French(FR)
- Chinese(ZH)
无数据