Operators

  • 版本网址缩略名: JavaScript/Reference/Operators
  • 版本标题: Operators
  • 版本 id: 37436
  • 创建于:
  • 创建者: ziyunfei
  • 是否是当前版本?
  • 评论 264 words added, 16 words removed

修订内容

算术运算符

(+, -, *, /, %, ++, --, unary -, unary +)

算数运算符将多个类数字值(字面量或者变量)当成操作数,并计算出运算结果.

赋值运算符

(=, *=, /=, %=, +=, -=, <<=, >>=, >>>=, &=, ^=, |=)

赋值运算符将右边表达式的值赋值给左边的变量.

位运算符

(&, |, ^, ~, <<, >>, >>>)

位运算符将它的操作数看成二进制数,并计算出10进制数字的结果.

比较运算符

(==, !=, ===, !==, >, >=, <, <=)

比较运算符通过比较它的操作数返回一个布尔值.

逻辑运算符

(&&, ||, !)

逻辑运算符操作布尔值,并且返回计算后的布尔值.

字符串运算符

(+ and +=)

字符串运算符连接两个字符串,返回一个新的字符串.

成员运算符

(object.propertyobject["property"])

通过成员运算符可以访问一个对象的属性.

特殊运算符
下面这些特殊的运算符不适合放到上面的分类中.
条件运算符

(condition ? ifTrue : ifFalse)

条件运算符根据condition的真假返回后面两个表达式其中的一个.

逗号运算符

(,)

逗号运算符允许在一个语句内执行多个表达式.并且返回最右边表达式的计算结果.

删除操作符

(delete)

删除操作符删除一个对象的属性.

function 操作符

(function)

function 操作符定义一个对象.

get 操作符

(get)

get 操作符定义一个属性的 getter.

in 操作符

(in)

in 操作符检查一个对象是否有指定的属性.

instanceof 操作符

(instanceof)

instanceof 操作符检查一个对象是否是另一个对象的实例.

let 操作符

(let)

let 操作符创建一个临时变量,有效作用域仅为当前表达式.

new 操作符

(new)

new 操作符创建一个构造器的实例.

set 操作符

(set)

set 操作符定义一个属性的 setter.

this 操作符

(this)

this 操作符指向当前的执行上下文.

typeof 操作符

(typeof)

typeof 操作符返回指定对象的类型.

void 操作符

(void)

void 操作符丢弃一个表达式的返回值.

yield 操作符

(yield)

yield 操作符可以构造一个生成器.

运算符优先级
定义了语句执行时运算符的执行顺序.

{{ languages( { "en": "en/JavaScript/Reference/Operators" } ) }}

修订版来源

<dl> <dt><a href="../../../en/JavaScript/Reference/Operators/Arithmetic_Operators" rel="internal" title="en/JavaScript/Reference/Operators/Arithmetic_Operators"><span class="short_text" id="result_box" lang="zh-CN"><span>算术运算符</span></span></a></dt> <dd> <p>(<code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code>, <code>++</code>, <code>--</code>, unary <code>-, unary +</code>)</p> <p>算数运算符将多个类数字值(字面量或者变量)当成操作数,并计算出运算结果.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/Assignment_Operators" rel="internal" title="en/JavaScript/Reference/Operators/Assignment_Operators">赋值运算符</a></dt> <dd> <p>(<code><span style="font-family: Verdana,Tahoma,sans-serif;">=, *=, /=, %=, +=, -=, &lt;&lt;=, &gt;&gt;=, &gt;&gt;&gt;=, &amp;=, ^=, |=</span></code>)</p> <p>赋值运算符将右边表达式的值赋值给左边的变量.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/Bitwise_Operators" rel="internal" title="en/JavaScript/Reference/Operators/Bitwise_Operators">位运算符</a></dt> <dd> <p>(<code>&amp;</code>, <code>|</code>, <code>^</code>, <code>~</code>, <code>&lt;&lt;</code>, <code>&gt;&gt;</code>, <code>&gt;&gt;&gt;</code>)</p> <p>位运算符将它的操作数看成二进制数,并计算出10进制数字的结果.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/Comparison_Operators" rel="internal" title="en/JavaScript/Reference/Operators/Comparison_Operators">比较运算符</a></dt> <dd> <p>(<code>==</code>, <code>!=</code>, <code>===</code>, <code>!==</code>, <code>&gt;</code>, <code>&gt;=</code>, <code>&lt;</code>, <code>&lt;=</code>)</p> <p>比较运算符通过比较它的操作数返回一个布尔值.</p> </dd> <dt><span style="text-decoration: underline;">逻辑运算符</span></dt> <dd> <p>(<code>&amp;&amp;</code>, <code>||</code>, <code>!</code>)</p> <p>逻辑运算符操作布尔值,并且返回计算后的布尔值.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/String_Operators" rel="internal" title="en/JavaScript/Reference/Operators/String_Operators">字符串运算符</a></dt> <dd> <p>(<code>+</code> and <code>+=</code>)</p> <p>字符串运算符连接两个字符串,返回一个新的字符串.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/Member_Operators" rel="internal" title="en/JavaScript/Reference/Operators/Member_Operators">成员运算符</a></dt> <dd> <p>(<code>object.property</code> 和 <code>object["property"]</code>)</p> <p>通过成员运算符可以访问一个对象的属性.</p> </dd> <dt>特殊运算符</dt> <dd>下面这些特殊的运算符不适合放到上面的分类中.</dd> <dd> <dl> <dt><a href="../../../en/JavaScript/Reference/Operators/Conditional_Operator" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/Conditional_Operator">条件运算符</a></dt> <dd> <p>(<code><em>condition</em> ? <em>ifTrue</em> : <em>ifFalse</em></code>)</p> <p>条件运算符根据<code><em>condition</em></code>的真假返回后面两个表达式其中的一个.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/Comma_Operator" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/Comma_Operator">逗号运算符</a></dt> <dd> <p>(<code>,</code>)</p> <p>逗号运算符允许在一个语句内执行多个表达式.并且返回最右边表达式的计算结果.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/delete" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/delete_Operator">删除操作符</a></dt> <dd> <p>(<code>delete</code>)</p> <p>删除操作符删除一个对象的属性.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/function" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/function_Operator">function 操作符</a></dt> <dd> <p>(<code>function</code>)</p> <p>function 操作符定义一个对象.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/get" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/get_Operator">get 操作符</a></dt> <dd> <p>(<code>get</code>)</p> <p>get 操作符定义一个属性的 getter.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/in" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/in_Operator">in 操作符</a></dt> <dd> <p>(<code>in</code>)</p> <p>in 操作符检查一个对象是否有指定的属性.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/instanceof" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/instanceof_Operator">instanceof 操作符</a></dt> <dd> <p>(<code>instanceof</code>)</p> <p>instanceof 操作符检查一个对象是否是另一个对象的实例.</p> </dd> <dt><a class="new " href="../../../en/JavaScript/Reference/Operators/Special_Operators/let_Operator" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/let_Operator">let 操作符</a></dt> <dd> <p>(<code>let</code>)</p> <p>let 操作符创建一个临时变量,有效作用域仅为当前表达式.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/new" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/new_Operator">new 操作符</a></dt> <dd> <p>(<code>new</code>)</p> <p>new 操作符创建一个构造器的实例.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/set" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/set_Operator">set 操作符</a></dt> <dd> <p>(<code>set</code>)</p> <p>set 操作符定义一个属性的 setter.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/this" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/this_Operator">this 操作符</a></dt> <dd> <p>(<code>this</code>)</p> <p>this 操作符指向当前的执行上下文.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/typeof" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/typeof_Operator">typeof 操作符</a></dt> <dd> <p>(<code>typeof</code>)</p> <p>typeof 操作符返回指定对象的类型.</p> </dd> <dt><a href="../../../en/JavaScript/Reference/Operators/void" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/void_Operator">void 操作符</a></dt> <dd> <p>(<code>void</code>)</p> <p>void 操作符丢弃一个表达式的返回值.</p> </dd> <dt><a class="new " href="../../../en/JavaScript/Reference/Operators/Special_Operators/yield_Operator" rel="internal" title="en/JavaScript/Reference/Operators/Special_Operators/yield_Operator">yield 操作符</a></dt> <dd> <p>(<code>yield</code>)</p> <p>yield 操作符可以构造一个生成器.</p> </dd> </dl> </dd> <dt>运算符优先级</dt> <dd>定义了语句执行时运算符的执行顺序.</dd>
</dl>
<p>{{ languages( { "en": "en/JavaScript/Reference/Operators" } ) }}</p>
恢复到这个版本