aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/errors/illegal_character
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/errors/illegal_character
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/errors/illegal_character')
-rw-r--r--files/zh-cn/web/javascript/reference/errors/illegal_character/index.html73
1 files changed, 73 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/errors/illegal_character/index.html b/files/zh-cn/web/javascript/reference/errors/illegal_character/index.html
new file mode 100644
index 0000000000..16367c43a2
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/errors/illegal_character/index.html
@@ -0,0 +1,73 @@
+---
+title: 'SyntaxError: illegal character'
+slug: Web/JavaScript/Reference/Errors/Illegal_character
+tags:
+ - JavaScript
+ - 语法错误
+translation_of: Web/JavaScript/Reference/Errors/Illegal_character
+---
+<div>{{jsSidebar("Errors")}}</div>
+
+<h2 id="错误提示">错误提示</h2>
+
+<pre class="syntaxbox">SyntaxError: illegal character (Firefox)
+SyntaxError: Invalid or unexpected token (Chrome)
+</pre>
+
+<h2 id="错误类型">错误类型</h2>
+
+<p>{{jsxref("SyntaxError")}}</p>
+
+<h2 id="哪里出错了?">哪里出错了?</h2>
+
+<p>在代码中有非法的或者不期望出现的标记符号出现在不该出现的位置。请使用支持语法高亮功能的编辑器仔细检查你的代码,看看是否存在张冠李戴的情况,比如减号 (<code> - </code>) 与连接符 (<code> – </code>) ,或者是英文双引号 (<code> " </code>) 与中文双引号 (<code> “ </code>)。</p>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="错配字符">错配字符</h3>
+
+<p>一些字符看起来会很相像,但是会导致于语法解析器解析代码失败。</p>
+
+<pre class="brush: js example-bad">“This looks like a string”;
+// SyntaxError: illegal character
+
+42 – 13;
+// SyntaxError: illegal character
+</pre>
+
+<p>下面这样是可以正常运行的:</p>
+
+<pre class="brush: js example-good">"This is actually a string";
+
+42 - 13;
+</pre>
+
+<h3 id="遗漏的字符">遗漏的字符</h3>
+
+<p>很容易就会在这里或那里遗漏一些字符。</p>
+
+<pre class="brush: js example-bad">var colors = ['#000', #333', '#666'];
+// SyntaxError: illegal character
+</pre>
+
+<p>把遗漏的引号给 '#333' 添加上。</p>
+
+<pre class="brush: js example-good">var colors = ['#000', '#333', '#666'];</pre>
+
+<h3 id="隐藏字符">隐藏字符</h3>
+
+<p>当从外部复制粘贴代码的时候,有可能就有非法的隐藏字符的存在,需要引起注意!</p>
+
+<pre class="brush: js example-bad">var foo = 'bar';​
+// SyntaxError: illegal character
+</pre>
+
+<p>当使用文本编辑器如VIM进行探测的时候,可以发现这里存在一个零宽空格<a href="https://en.wikipedia.org/wiki/Zero-width_space"> (ZWSP) (U+200B)</a> 。</p>
+
+<pre class="brush: js">var foo = 'bar';​&lt;200b&gt;</pre>
+
+<h2 id="相关内容">相关内容</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar">Lexical grammar</a></li>
+</ul>