Expressões e operadores

Este capítulo documenta todos os operadores, expressões e palavras-chave da linguagem JavaScript.

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.

this (en-US)
The this keyword refers to a special property of an execution context.
function
The function keyword defines a function expression.
class (en-US)
The class keyword defines a class expression.
function* (en-US)
The function* keyword defines a generator function expression.
yield (en-US)
Pause and resume a generator function.
yield* (en-US)
Delegate to another generator function or iterable object.
async function (en-US)
The async function defines an async function expression.
await (en-US)
Pause and resume an async function and wait for the promise's resolution/rejection.
[]
Array initializer/literal syntax.
{} (en-US)
Object initializer/literal syntax.
/ab+c/i (en-US)
Regular expression literal syntax.
( ) (en-US)
Grouping operator.

Expressões "Left-hand-side"

Left values are the destination of an assignment.

Property accessors (en-US)
Member operators provide access to a property or method of an object
(object.property and object["property"]).
new (en-US)
The new operator creates an instance of a constructor.
new.target
In constructors, new.target refers to the constructor that was invoked by new (en-US).
super (en-US)
The super keyword calls the parent constructor.
...obj (en-US)
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.

A++ (en-US)
Postfix increment operator.
A-- (en-US)
Postfix decrement operator.
++A (en-US)
Prefix increment operator.
--A (en-US)
Prefix decrement operator.

Operadores unários

A unary operation is operation with only one operand.

delete (en-US)
The delete operator deletes a property from an object.
void (en-US)
The void operator discards an expression's return value.
typeof (en-US)
The typeof operator determines the type of a given object.
+ (en-US)
The unary plus operator converts its operand to Number type.
- (en-US)
The unary negation operator converts its operand to Number type and then negates it.
~ (en-US)
Bitwise NOT operator.
! (en-US)
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.

+ (en-US)
Addition operator.
- (en-US)
Subtraction operator.
/ (en-US)
Division operator.
* (en-US)
Multiplication operator.
% (en-US)
Remainder operator.
** (en-US)
Exponentiation operator.

Operadores relacionais

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

in (en-US)
The in operator determines whether an object has a given property.
instanceof (en-US)
The instanceof operator determines whether an object is an instance of another object.
< (en-US)
Less than operator.
> (en-US)
Greater than operator.
<= (en-US)
Less than or equal operator.
>= (en-US)
Greater than or equal operator.

Nota: => não é um operador, mas a notação para funções seta (arrow).

Operadores de equality

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

== (en-US)
Equality operator.
!= (en-US)
Inequality operator.
=== (en-US)
Identity operator.
!== (en-US)
Nonidentity operator.

Bitwise shift operators

Operations to shift all bits of the operand.

<< (en-US)
Bitwise left shift operator.
>> (en-US)
Bitwise right shift operator.
>>> (en-US)
Bitwise unsigned right shift operator.

Operadores de binário bitwise

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

& (en-US)
Bitwise AND.
| (en-US)
Bitwise OR.
^ (en-US)
Bitwise XOR.

Operadores de binário logical

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

&& (en-US)
Logical AND.
|| (en-US)
Logical OR.

Operdor condicional (ternário)

(condition ? ifTrue : ifFalse) (en-US)

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

Operadores de Assignment

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

= (en-US)
Assignment operator.
*= (en-US)
Multiplication assignment.
/= (en-US)
Division assignment.
%= (en-US)
Remainder assignment.
+= (en-US)
Addition assignment.
-= (en-US)
Subtraction assignment
<<= (en-US)
Left shift assignment.
>>= (en-US)
Right shift assignment.
>>>= (en-US)
Unsigned right shift assignment.
&= (en-US)
Bitwise AND assignment.
^= (en-US)
Bitwise XOR assignment.
|= (en-US)
Bitwise OR assignment.
[a, b] = [1, 2] (en-US)
{a, b} = {a:1, b:2} (en-US)

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

This API has not been standardized. 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 (en-US) expression.
This API has not been standardized. Expression closures
The expression closure syntax is a shorthand for writing simple function.
This API has not been standardized. [for (x of y) x]
Array comprehensions.
This API has not been standardized. (for (x of y) y)
Generator comprehensions.

Especificações

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.
Standard
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'ECMAScript Language: Expressions' in that specification.
Standard New: Spread operator, destructuring assignment, super keyword.
ECMAScript (ECMA-262)
The definition of 'ECMAScript Language: Expressions' in that specification.
Living Standard

Compatibilidade de navegador

BCD tables only load in the browser

Consulte também