Expressões e Operadores

Esta tradução não está completa. Por favor ajude a traduzir este artigo a partir do Inglês.

This chapter documents all the JavaScript language operators, expressions and keywords.

Expressões e operadores por categoria

For an alphabetical listing see the sidebar on the left.

Expressões primárias

Basic keywords and general expressions in JavaScript.

The this keyword refers to the function's execution context.
The function keyword defines a function expression.
The class keyword defines a class expression.
The function* keyword defines a generator function expression.
Pause and resume a generator function.
Delegate to another generator function or iterable object.
Array initializer/literal syntax.
Object initializer/literal syntax.
Regular expression literal syntax.
( )
Grouping operator.

Expressões "Left-hand-side"

Left values are the destination of an assignment.

Property accessors
Member operators provide access to a property or method of an object
( and object["property"]).
The new operator creates an instance of a constructor.
In constructors, refers to the constructor that was invoked by new.
The super keyword calls the parent constructor.
The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.

Aumento e diminuição

Postfix/prefix increment and postfix/prefix decrement operators.

Postfix increment operator.
Postfix decrement operator.
Prefix increment operator.
Prefix decrement operator.

Operadores unário

A unary operation is operation with only one operand.

The delete operator deletes a property from an object.
The void operator discards an expression's return value.
The typeof operator determines the type of a given object.
The unary plus operator converts its operand to Number type.
The unary negation operator converts its operand to Number type and then negates it.
Bitwise NOT operator.
Logical NOT operator.

Operadores de aritmética

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.

Addition operator.
Subtraction operator.
Division operator.
Multiplication operator.
Remainder operator.
Exponentiation operator.

Operadores relacionais

A comparison operator compares its operands and returns a Boolean value based on whether the comparison is true.

The in operator determines whether an object has a given property.
The instanceof operator determines whether an object is an instance of another object.
Less than operator.
Greater than operator.
Less than or equal operator.
Greater than or equal operator.

Note: => is not an operator, but the notation for Arrow functions.

Operadores de igualdade

The result of evaluating an equality operator is always of type Boolean based on whether the comparison is true.

Equality operator.
Inequality operator.
Identity operator.
Nonidentity operator.

Bitwise shift operators

Operations to shift all bits of the operand.

Bitwise left shift operator.
Bitwise right shift operator.
Bitwise unsigned right shift operator.

Binary bitwise operators

Bitwise operators treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values.

Bitwise AND.
Bitwise OR.
Bitwise XOR.

Operadores lógicos binários

Logical operators are typically used with boolean (logical) values, and when they are, they return a boolean value.

Logical AND.
Logical OR.

Operdor Condicional (ternário)

(condition ? ifTrue : ifFalse)

The conditional operator returns one of two values based on the logical value of the condition.

Operadores de atribuição

An assignment operator assigns a value to its left operand based on the value of its right operand.

Assignment operator.
Multiplication assignment.
Division assignment.
Remainder assignment.
Addition assignment.
Subtraction assignment
Left shift assignment.
Right shift assignment.
Unsigned right shift assignment.
Bitwise AND assignment.
Bitwise XOR assignment.
Bitwise OR assignment.
[a, b] = [1, 2]
{a, b} = {a:1, b:2}

Destructuring assignment allows you to assign the properties of an array or object to variables using syntax that looks similar to array or object literals.

Operador de aspas

The comma operator allows multiple expressions to be evaluated in a single statement and returns the result of the last expression.

Funcionalidades não padrão

Legacy generator function
The function keyword can be used to define a legacy generator function inside an expression. To make the function a legacy generator, the function body should contains at least one yield expression.
Expression closures
The expression closure syntax is a shorthand for writing simple function.
[for (x of y) x]
Array comprehensions.
(for (x of y) y)
Generator comprehensions.


Especificação Estado Comentário
ECMAScript 1st Edition (ECMA-262)
The definition of 'Expressions' in that specification.
Standard Initial definition
ECMAScript 5.1 (ECMA-262)
The definition of 'Expressions' in that specification.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'ECMAScript Language: Expressions' in that specification.
Standard New: Spread operator, destructuring assignment, super keyword.
ECMAScript 2017 Draft (ECMA-262)
The definition of 'ECMAScript Language: Expressions' in that specification.

Consultar também

Etiquetas do documento e contribuidores

 Contribuidores para esta página: mansil
 Última atualização por: mansil,