aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript')
-rw-r--r--files/zh-cn/web/javascript/guide/grammar_and_types/index.html4
-rw-r--r--files/zh-cn/web/javascript/guide/text_formatting/index.html12
-rw-r--r--files/zh-cn/web/javascript/reference/statements/import/index.html16
-rw-r--r--files/zh-cn/web/javascript/reference/statements/return/index.html8
4 files changed, 20 insertions, 20 deletions
diff --git a/files/zh-cn/web/javascript/guide/grammar_and_types/index.html b/files/zh-cn/web/javascript/guide/grammar_and_types/index.html
index 0ea7538a96..8b00401fcc 100644
--- a/files/zh-cn/web/javascript/guide/grammar_and_types/index.html
+++ b/files/zh-cn/web/javascript/guide/grammar_and_types/index.html
@@ -447,8 +447,8 @@ console.log(a[0]); // 3</pre>
<pre class="brush: js notranslate">3.14
-.2345789 // -0.23456789
--3.12e+12 // -3.12*10<sup>12</sup>
-.1e-23 // 0.1*10<sup>-23</sup>=10<sup>-24</sup>=1e-24
+-3.12e+12 // -3.12*10^12
+.1e-23 // 0.1*10^(-23)=10^(-24)=1e-24
</pre>
<h3 id="对象字面量_Object_literals">对象字面量 (Object literals)</h3>
diff --git a/files/zh-cn/web/javascript/guide/text_formatting/index.html b/files/zh-cn/web/javascript/guide/text_formatting/index.html
index 71d93dfe78..522b3ed362 100644
--- a/files/zh-cn/web/javascript/guide/text_formatting/index.html
+++ b/files/zh-cn/web/javascript/guide/text_formatting/index.html
@@ -51,7 +51,7 @@ translation_of: Web/JavaScript/Guide/Text_formatting
<p>{{jsxref("String")}} 对象是对原始string类型的封装 .</p>
-<pre class="notranslate">const foo = new String('foo'); // 创建一个 String 对象
+<pre class="brush: js notranslate">const foo = new String('foo'); // 创建一个 String 对象
console.log(foo); // 输出: [String: 'foo']
typeof foo; // 返回 'object'</pre>
@@ -59,14 +59,14 @@ typeof foo; // 返回 'object'</pre>
<p>除非必要, 应该尽量使用 String 字面值,因为String对象的某些行为可能并不与直觉一致。举例:</p>
-<pre class="notranslate">const firstString = '2 + 2'; //创建一个字符串字面量
+<pre class="brush: js notranslate">const firstString = '2 + 2'; //创建一个字符串字面量
const secondString = new String('2 + 2'); // 创建一个字符串对象
eval(firstString); // 返回数字 4
eval(secondString); // 返回字符串 "2 + 2"</pre>
<p><code>String</code> 对象有一个属性 <code>length</code>,标识了字符串中 UTF-16 的码点个数。举例,下面的代码把 13 赋值给了<code>helloLength</code>,因为 "Hello, World!" 包含 13 个字符,每个字符用一个 UTF-16 码点表示。你可以通过数组的方式访问每一个码点,但你不能修改每个字符,因为字符串是不变的类数组对象: </p>
-<pre class="notranslate">const hello = 'Hello, World!';
+<pre class="brush: js notranslate">const hello = 'Hello, World!';
const helloLength = hello.length;
hello[0] = 'L'; // 无效,因为字符串是不变的
hello[0]; // 返回 "H"</pre>
@@ -171,19 +171,19 @@ string text line 2`);
<p>为了在一般的字符串中嵌入表达式, 需要使用如下语法:</p>
-<pre class="notranslate">const five = 5;
+<pre class="brush: js notranslate">const five = 5;
const ten = 10;
console.log('Fifteen is ' + (five + ten) + ' and not ' + (2 * five + ten) + '.');
// "Fifteen is 15 and not 20."</pre>
<p>现在, 使用模板字符串, 可以使用语法糖让类似功能的实现代码更具可读性:</p>
-<pre class="notranslate">const five = 5;
+<pre class="brush: js notranslate">const five = 5;
const ten = 10;
console.log(`Fifteen is ${five + ten} and not ${2 * five + ten}.`);
// "Fifteen is 15 and not 20."</pre>
-<p>更多信息, 请阅读 <a href="/en-US/docs/Web/JavaScript/Reference">JavaScript reference</a> 中的 <a href="/en-US/docs/Web/JavaScript/Reference/template_strings">Template strings</a>。</p>
+<p>更多信息, 请阅读 <a href="/en-US/docs/Web/JavaScript/Reference">JavaScript reference</a> 中的 <a href="/en-US/docs/Web/JavaScript/Reference/Template_literals">Template literals</a>。</p>
<h2 id="国际化">国际化</h2>
diff --git a/files/zh-cn/web/javascript/reference/statements/import/index.html b/files/zh-cn/web/javascript/reference/statements/import/index.html
index b7634d9cef..203ce9b8cc 100644
--- a/files/zh-cn/web/javascript/reference/statements/import/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/import/index.html
@@ -21,7 +21,7 @@ translation_of: Web/JavaScript/Reference/Statements/import
<p>语法</p>
-<pre class="syntaxbox notranslate">import <em>defaultExport</em> from "<em>module-name</em>";
+<pre class="syntaxbox brush: js notranslate">import <em>defaultExport</em> from "<em>module-name</em>";
import * as <em>name</em> from "<em>module-name</em>";
import { <em>export </em>} from "<em>module-name</em>";
import { <em>export</em> as <em>alias </em>} from "<em>module-name</em>";
@@ -95,7 +95,7 @@ var promise = import("module-name");//这是一个处于第三阶段的提案。
<p>整个模块仅为副作用(中性词,无贬义含义)而导入,而不导入模块中的任何内容(接口)。 这将运行模块中的全局代码, 但实际上不导入任何值。</p>
-<pre class="notranslate"><code>import '/modules/my-module.js';</code></pre>
+<pre class="brush: js notranslate">import '/modules/my-module.js';</pre>
<h3 id="导入默认值">导入默认值</h3>
@@ -116,9 +116,9 @@ var promise = import("module-name");//这是一个处于第三阶段的提案。
// specific, named imports
</pre>
-<p>When importing a default export with {{anch("Dynamic Imports", "dynamic imports")}}, it works a bit differently. You need to destructure and rename the "default" key from the returned object.</p>
+<p>当用{{anch("动态导入")}}的方式导入默认导出时,其工作方式有所不同。你需要从返回的对象中解构并重命名 "default" 键。</p>
-<pre class="notranslate">(async () =&gt; {
+<pre class="brush: js notranslate">(async () =&gt; {
if (somethingIsTrue) {
  const { default: myDefault, foo, bar } = await import('/modules/my-module.js');
}
@@ -140,15 +140,15 @@ var promise = import("module-name");//这是一个处于第三阶段的提案。
<p>关键字import可以像调用函数一样来动态的导入模块。以这种方式调用,将返回一个 <code>promise</code>。</p>
-<pre class="brush: js notranslate"><code>import('/modules/my-module.js')
+<pre class="brush: js notranslate">import('/modules/my-module.js')
.then((module) =&gt; {
// Do something with the module.
- });</code>
+ });
</pre>
<p>这种使用方式也支持 <code>await</code> 关键字。</p>
-<pre class="brush: js notranslate"><code>let module = await import('/modules/my-module.js');</code></pre>
+<pre class="brush: js notranslate">let module = await import('/modules/my-module.js');</pre>
<h2 id="示例">示例</h2>
@@ -227,6 +227,6 @@ for (const link of document.querySelectorAll("nav &gt; a")) {
<li>Limin Zhu, Brian Terlson and Microsoft Edge Team: <a href="https://blogs.windows.com/msedgedev/2016/05/17/es6-modules-and-beyond/">Previewing ES6 Modules and more from ES2015, ES2016 and beyond</a></li>
<li>Hacks blog post by Jason Orendorff: <a href="https://hacks.mozilla.org/2015/08/es6-in-depth-modules/">ES6 in Depth: Modules</a></li>
<li>Hacks blog post by Lin Clark: <a href="https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/">ES modules: A cartoon deep-dive</a></li>
- <li>Axel Rauschmayer's book: <a class="external" href="http://exploringjs.com/es6/ch_modules.html">"Exploring JS: Modules"</a></li>
+ <li>Axel Rauschmayer's book: <a class="external" href="https://exploringjs.com/es6/ch_modules.html">"Exploring JS: Modules"</a></li>
<li>The Modern JavaScript Tutorial(javascript.info): <a class="external" href="https://javascript.info/import-export">Export and Import</a></li>
</ul>
diff --git a/files/zh-cn/web/javascript/reference/statements/return/index.html b/files/zh-cn/web/javascript/reference/statements/return/index.html
index 9debeab7af..8c82917d96 100644
--- a/files/zh-cn/web/javascript/reference/statements/return/index.html
+++ b/files/zh-cn/web/javascript/reference/statements/return/index.html
@@ -69,11 +69,11 @@ a + b;</pre>
<pre class="brush: js">function counter() {
for (var count = 1; ; count++) { // 无限循环
console.log(count + "A"); // 执行5次
- if (count === 5) {
- return;
- }
- console.log(count + "B"); // 执行4次
+ if (count === 5) {
+ return;
}
+ console.log(count + "B"); // 执行4次
+ }
console.log(count + "C"); // 永远不会执行
}