mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-09 23:44:06 +08:00
35 lines
1.6 KiB
HTML
35 lines
1.6 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<h2 id="Message">Message</h2>
|
||
<pre><code class="language-javascript">ReferenceError: invalid assignment left-hand side
|
||
</code></pre>
|
||
<h2 id="Error_type">Error type</h2>
|
||
<p><a href="Reference/Global_Objects/ReferenceError" title="ReferenceError(引用错误) 对象代表当一个不存在的变量被引用时发生的错误。"><code>ReferenceError</code></a>.</p>
|
||
<h2 id="What_went_wrong">What went wrong?</h2>
|
||
<p>有时会出现不可预料的赋值情况。这可能是因为<a href="Reference/Operators/Assignment_Operators">赋值运算符</a>或<a href="Reference/Operators/Comparison_Operators">比较运算符</a>不匹配的缘故。正确的是,使用“=”号将值赋给一个变量,使用“==”或者“===”来比较一个值。</p>
|
||
<h2 id="Examples">Examples</h2>
|
||
<pre><code class="language-js example-bad">if (Math.PI = 3 || Math.PI = 4) {
|
||
console.log('no way!');
|
||
}
|
||
// ReferenceError: invalid assignment left-hand side
|
||
|
||
var str = 'Hello, '
|
||
+= 'is it me '
|
||
+= 'you\'re looking for?';
|
||
// ReferenceError: invalid assignment left-hand side
|
||
</code></pre>
|
||
<p>在 <code>if</code> 语句中,你要使用比较运算符("=="),而在字符串连接中,使用加号运算符("+")。</p>
|
||
<pre><code class="language-js example-good">if (Math.PI == 3 || Math.PI == 4) {
|
||
console.log('no way!');
|
||
}
|
||
|
||
var str = 'Hello, '
|
||
+ 'from the '
|
||
+ 'other side!';
|
||
</code></pre>
|
||
<h2 id="See_also">See also</h2>
|
||
<ul>
|
||
<li><a href="Reference/Operators/Assignment_Operators">赋值运算符</a></li>
|
||
<li><a href="Reference/Operators/Comparison_Operators">比较运算符</a></li>
|
||
</ul>
|
||
</article> |