Sobre essa Referência
O JavaScript é uma linguagem interpretada que se destina a ser utilizado dentro de algum ambiente maior, seja ele um script de um navegador, do lado do servidor, ou algo similar. Para a maior parte, esta referência se distinta à um ambiente agnóstico, e não somente ao ambiente de um navegador.
Onde encontrar mais informações sobre JavaScript ?
Você pode verificar a documentação do core da linguagem e seus novos recursos ( ECMAScript puro em sua maior parte), incluindo também :
Se você é novo com JavaScript, recomendamos à você começar com o guia. Uma vez que você já tenha uma base sobre os fundamentos da linguagem, você pode usar a referência para obter mais detalhes sobre objetos individuais e construtores da linguagem.
Estrutura da referência
Na referência do JavaScript você poderá encontrar os seguintes seções :
- Padrões de objetos internos (built-in objects)
- Esta seção documenta todos o padrão JavaScript de objetos internos, juntamente com seus métodos e propriedades.
- Instruções e Declarações (Statements)
- As aplicações em JavaScript consistem em declarações com uma sintaxe apropriada. Uma única declaração pode abranger várias linhas de código. Várias instruções podem ocorrer em uma única linha também, se cada declaração for devidamente separada por ponto e virgula. Instrução não é uma palavra-chave, mas sim, um grupo de palavras-chave.
- Expressões e operadores
- Esta seção documenta todos os operadores da linguagem JavaScript, expressões e palavras-chave.
- Funções
- Esta seção é referente as funções existentes no JavaScript.
- Novo no JavaScript
- Esta seção é sobre as versões do JavaScript, contendo o histórico de versões e o que há de novo nas proximas versões.
Mais paginas de referências
Objetos Globais
Funções e escopo de função
Declarações
- JavaScript
- Tutorials:
- JavaScript Guide
- Introduction
- Grammar and types
- Control flow and error handling
- Loops and iteration
- Functions
- Expressions and operators
- Numbers and dates
- Text formatting
- Regular expressions
- Indexed collections
- Keyed collections
- Working with objects
- Details of the object model
- Iterators and generators
- Meta programming
- Introductory
- Intermediate
- Advanced
- References:
- Built-in objects
- Objetos Globais
- Array
- ArrayBuffer
- Boolean [Translate]
- DataView [Translate]
- Date
- Error [Translate]
- EvalError [Translate]
- Float32Array [Translate]
- Float64Array [Translate]
- Function
- Generator [Translate]
- GeneratorFunction [Translate]
- Infinity
- Int16Array [Translate]
- Int32Array [Translate]
- Int8Array [Translate]
- InternalError [Translate]
- Intl [Translate]
- Intl.Collator [Translate]
- Intl.DateTimeFormat [Translate]
- Intl.NumberFormat [Translate]
- Iterator [Translate]
- JSON
- Map [Translate]
- Math
- NaN
- Number
- Object
- ParallelArray [Translate]
- Promise
- Proxy [Translate]
- RangeError [Translate]
- ReferenceError [Translate]
- Reflect [Translate]
- RegExp
- SIMD [Translate]
- Set
- StopIteration [Translate]
- String
- Symbol
- SyntaxError [Translate]
- TypeError [Translate]
- TypedArray [Translate]
- URIError [Translate]
- Uint16Array [Translate]
- Uint32Array [Translate]
- Uint8Array [Translate]
- Uint8ClampedArray [Translate]
- WeakMap
- WeakSet [Translate]
- decodeURI() [Translate]
- decodeURIComponent() [Translate]
- encodeURI() [Translate]
- encodeURIComponent() [Translate]
- escape() [Translate]
- eval()
- isFinite() [Translate]
- isNaN()
- null
- parseFloat() [Translate]
- parseInt()
- undefined
- unescape() [Translate]
- uneval() [Translate]
- Expressions & operators
- Operators
- Arithmetic operators [Translate]
- Array comprehensions
- Assignment operators [Translate]
- Bitwise operators [Translate]
- Operador Vírgula
- Comparison operators [Translate]
- Operador Condicional Ternário
- Destructuring assignment [Translate]
- Expression closures [Translate]
- Generator comprehensions [Translate]
- Operador de Agrupamento
- Legacy generator function expression [Translate]
- Operadores Lógicos
- Object initializer [Translate]
- Precedência de Operadores
- Property accessors [Translate]
- Spread operator [Translate]
- class expression [Translate]
- delete operator [Translate]
- function expression [Translate]
- function* expression [Translate]
- in operator [Translate]
- instanceof
- new operator [Translate]
- super [Translate]
- this [Translate]
- typeof
- void operator [Translate]
- yield [Translate]
- yield* [Translate]
- Statements & declarations
- Statements
- Legacy generator function [Translate]
- block [Translate]
- break
- class [Translate]
- const
- continue [Translate]
- debugger [Translate]
- do...while
- empty [Translate]
- export [Translate]
- for [Translate]
- for each...in [Translate]
- for...in [Translate]
- for...of [Translate]
- function [Translate]
- function*
- if...else [Translate]
- import [Translate]
- label (Etiqueta)
- let
- return [Translate]
- switch
- throw [Translate]
- try...catch
- var
- while [Translate]
- with [Translate]
- Functions
- Classes
- Misc
- New in JavaScript
- New in JavaScript [Translate]
- ECMAScript 5 support in Mozilla [Translate]
- Suporte ao ECMAScript 6 na Mozilla
- ECMAScript 7 support in Mozilla [Translate]
- Firefox JavaScript changelog [Translate]
- New in JavaScript 1.1 [Translate]
- New in JavaScript 1.2 [Translate]
- New in JavaScript 1.3 [Translate]
- New in JavaScript 1.4 [Translate]
- New in JavaScript 1.5 [Translate]
- New in JavaScript 1.6 [Translate]
- New in JavaScript 1.7 [Translate]
- New in JavaScript 1.8 [Translate]
- New in JavaScript 1.8.1 [Translate]
- New in JavaScript 1.8.5 [Translate]
- Documentation:
- Useful lists
- Contribute
JavaScript applications consist of statements with an appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semicolon. This isn't a keyword, but a group of keywords.
Statements and declarations by category
For an alphabetical listing see the sidebar on the left.
Control flow
Block
- A block statement is used to group zero or more statements. The block is delimited by a pair of curly brackets.
break
- Terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement.
continue
- Terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration.
Empty
- An empty statement is used to provide no statement, although the JavaScript syntax would expect one.
if...else
- Executes a statement if a specified condition is true. If the condition is false, another statement can be executed.
switch
- Evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.
throw
- Throws a user-defined exception.
try...catch
- Marks a block of statements to try, and specifies a response, should an exception be thrown.
Declarations
var
- Declares a variable, optionally initializing it to a value.
-
let
- Declares a block scope local variable, optionally initializing it to a value.
-
const
- Declares a read-only named constant.
Functions and classes
function
- Declares a function with the specified parameters.
-
function*
- Generators functions enable writing iterators more easily.
return
- Specifies the value to be returned by a function.
-
class
- Declares a class.
Iterations
do...while
- Creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.
for
- Creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement executed in the loop.
-
for each...in
- Iterates a specified variable over all values of object's properties. For each distinct property, a specified statement is executed.
for...in
- Iterates over the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed.
-
for...of
- Iterates over iterable objects (including arrays, array-like objects, iterators and generators), invoking a custom iteration hook with statements to be executed for the value of each distinct property.
while
- Creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.
Others
debugger
- Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect.
-
export
- Used to export functions to make them available for imports in external modules, another scripts.
-
import
- Used to import functions exported from an external module, another script.
label
- Provides a statement with an identifier that you can refer to using a
break
orcontinue
statement.
-
with
- Extends the scope chain for a statement.
Specifications
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition. | Standard | Initial definition. |
ECMAScript 5.1 (ECMA-262) The definition of 'Statements' in that specification. |
Standard | |
ECMAScript 6 (ECMA-262) The definition of 'ECMAScript Language: Statements and Declarations' in that specification. |
Release Candidate | New: function*, let, for...of, yield, class |
See also
Operadores e outras palavras-chave
- JavaScript
- Tutorials:
- JavaScript Guide
- Introduction
- Grammar and types
- Control flow and error handling
- Loops and iteration
- Functions
- Expressions and operators
- Numbers and dates
- Text formatting
- Regular expressions
- Indexed collections
- Keyed collections
- Working with objects
- Details of the object model
- Iterators and generators
- Meta programming
- Introductory
- Intermediate
- Advanced
- References:
- Built-in objects
- Objetos Globais
- Array
- ArrayBuffer
- Atomics
- Boolean
- DataView [Translate]
- Date
- Error
- EvalError [Translate]
- Float32Array [Translate]
- Float64Array [Translate]
- Function
- Generator
- GeneratorFunction [Translate]
- Infinity
- Int16Array [Translate]
- Int32Array [Translate]
- Int8Array [Translate]
- InternalError [Translate]
- Intl [Translate]
- Intl.Collator [Translate]
- Intl.DateTimeFormat [Translate]
- Intl.NumberFormat [Translate]
- Iterator
- JSON
- Map
- Math
- NaN
- Number
- Object
- ParallelArray [Translate]
- Promise
- Proxy [Translate]
- RangeError [Translate]
- ReferenceError [Translate]
- Reflect [Translate]
- RegExp
- SIMD [Translate]
- SIMD.Bool16x8 [Translate]
- SIMD.Bool32x4 [Translate]
- SIMD.Bool64x2 [Translate]
- SIMD.Bool8x16 [Translate]
- SIMD.Float32x4 [Translate]
- SIMD.Float64x2 [Translate]
- SIMD.Int16x8 [Translate]
- SIMD.Int32x4 [Translate]
- SIMD.Int8x16 [Translate]
- SIMD.Uint16x8 [Translate]
- SIMD.Uint32x4 [Translate]
- SIMD.Uint8x16 [Translate]
- Set
- SharedArrayBuffer [Translate]
- StopIteration [Translate]
- String
- Símbolo
- SyntaxError
- TypeError
- TypedArray [Translate]
- URIError [Translate]
- Uint16Array [Translate]
- Uint32Array [Translate]
- Uint8Array [Translate]
- Uint8ClampedArray [Translate]
- WeakMap
- WeakSet [Translate]
- decodeURI() [Translate]
- decodeURIComponent()
- encodeURI() [Translate]
- encodeURIComponent()
- escape()
- eval()
- isFinite()
- isNaN()
- null
- parseFloat()
- parseInt()
- undefined
- unescape() [Translate]
- uneval()
- Expressions & operators
- Operadores
- Arithmetic operators
- Array comprehensions
- Operadores de Atribuição
- Bitwise operators [Translate]
- Operador Vírgula
- Comparison operators [Translate]
- Operador Condicional Ternário
- Destructuring assignment [Translate]
- Expression closures [Translate]
- Generator comprehensions [Translate]
- Operador de Agrupamento
- Legacy generator function expression [Translate]
- Operadores Lógicos
- Object initializer [Translate]
- Precedência de Operadores
- Property accessors [Translate]
- Spread operator
- class expression [Translate]
- delete operator [Translate]
- Expressão de função (function expression)
- function* expression [Translate]
- in operator [Translate]
- instanceof
- new operator [Translate]
- new.target [Translate]
- super
- this
- typeof
- void operator
- yield [Translate]
- yield* [Translate]
- Statements & declarations
- Statements
- Legacy generator function [Translate]
- block [Translate]
- break
- class
- const
- continue [Translate]
- debugger
- default [Translate]
- do...while
- empty
- export [Translate]
- for
- for each...in
- for...in
- for...of
- function
- function*
- if...else
- import
- label (Etiqueta)
- let
- return [Translate]
- switch
- throw [Translate]
- try...catch
- var
- while
- with [Translate]
- Functions
- Classes
- Errors
- JavaScript error reference [Translate]
- Error: Permission denied to access property "x" [Translate]
- InternalError: too much recursion [Translate]
- RangeError: argument is not a valid code point [Translate]
- RangeError: invalid array length [Translate]
- RangeError: precision is out of range [Translate]
- RangeError: radix must be an integer [Translate]
- RangeError: repeat count must be less than infinity [Translate]
- RangeError: repeat count must be non-negative [Translate]
- ReferenceError: "x" is not defined [Translate]
- ReferenceError: assignment to undeclared variable "x" [Translate]
- ReferenceError: deprecated caller or arguments usage [Translate]
- ReferenceError: invalid assignment left-hand side [Translate]
- ReferenceError: reference to undefined property "x" [Translate]
- SyntaxError: "x" is not a legal ECMA-262 octal constant [Translate]
- SyntaxError: JSON.parse: bad parsing [Translate]
- SyntaxError: Malformed formal parameter [Translate]
- SyntaxError: Unexpected token [Translate]
- SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead [Translate]
- SyntaxError: missing ) after argument list [Translate]
- SyntaxError: missing ; before statement [Translate]
- SyntaxError: missing ] after element list [Translate]
- SyntaxError: missing } after property list [Translate]
- SyntaxError: redeclaration of formal parameter "x" [Translate]
- SyntaxError: return not in function [Translate]
- SyntaxError: test for equality (==) mistyped as assignment (=)? [Translate]
- SyntaxError: unterminated string literal [Translate]
- TypeError: "x" has no properties [Translate]
- TypeError: "x" is (not) "y" [Translate]
- TypeError: "x" is not a constructor [Translate]
- TypeError: "x" is not a function [Translate]
- TypeError: "x" is read-only [Translate]
- TypeError: More arguments needed [Translate]
- TypeError: invalid Array.prototype.sort argument [Translate]
- TypeError: property "x" is non-configurable and can't be deleted [Translate]
- TypeError: variable "x" redeclares argument [Translate]
- Warning: -file- is being assigned a //# sourceMappingURL, but already has one [Translate]
- Warning: unreachable code after return statement [Translate]
- Misc
- New in JavaScript
- New in JavaScript
- Suporte ao ECMAScript 5 no Mozilla
- Suporte ao ECMAScript 6 na Mozilla
- Suporte ao ECMAScript 7 no Mozilla
- Firefox JavaScript changelog [Translate]
- New in JavaScript 1.1 [Translate]
- New in JavaScript 1.2 [Translate]
- New in JavaScript 1.3 [Translate]
- New in JavaScript 1.4 [Translate]
- New in JavaScript 1.5 [Translate]
- New in JavaScript 1.6 [Translate]
- JavaScript 1.7
- New in JavaScript 1.8 [Translate]
- New in JavaScript 1.8.1 [Translate]
- New in JavaScript 1.8.5 [Translate]
- Documentation:
- Useful lists
- Contribute
Este capítulo documenta todos os operadores, expressões e keywords da linguagem JavaScript .
Expressões e operadores por categoria
Para uma lista alfabética ver a barra lateral à esquerda.
Expressões primárias
Palavras-chave e expressões básicas em JavaScript.
this
- A palavra-chave
this
refere-se ao contexto de execução da função. function
- A palavra-chave
function
define uma função. -
class
- A palavra-chave
class
define uma classe. -
function*
- A palavra-chave
function*
define um gerador de função. -
yield
- Pausa e retorma uma função de gerador
-
yield*
- Delegar a outra função gerador ou objeto iterável.
[]
- Array initializer/literal syntax.
{}
- Object initializer/literal syntax.
/ab+c/i
- Regular expression literal syntax.
-
[for (x of y) x]
- Array comprehensions.
-
(for (x of y) y)
- Generator comprehensions.
( )
- Grouping operator.
Left-hand-side expressions
Left values are the destination of an assignment.
- Property accessors
- Member operators provide access to a property or method of an object
(object.property
andobject["property"]
). new
- The
new
operator creates an instance of a constructor. -
super
- The
super
keyword calls the parent constructor. -
...obj
- 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.
Increment and decrement
Postfix/prefix increment and postfix/prefix decrement operators.
A++
- Postfix increment operator.
A--
- Postfix decrement operator.
++A
- Prefix increment operator.
--A
- Prefix decrement operator.
Unary operators
A unary operation is operation with only one operand.
delete
- The
delete
operator deletes a property from an object. void
- The
void
operator discards an expression's return value. typeof
- 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.
Arithmetic operators
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.
Relational operators
A comparison operator compares its operands and returns a Boolean
value based on whether the comparison is true.
in
- The
in
operator determines whether an object has a given property. instanceof
- 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.
Equality operators
The result of evaluating an equality operator is always of type Boolean
based on whether the comparison is true.
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.
Operadores Lógicos Binários
Operadores lógicos são normalmente usados com boolean (logical) valores, e quando eles são, eles retornam um valor Boolean.
Conditional (ternary) operator
(condition ? ifTrue : ifFalse)
-
The conditional operator returns one of two values based on the logical value of the condition.
Assignment operators
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.
Comma operator
,
- The comma operator allows multiple expressions to be evaluated in a single statement and returns the result of the last expression.
Non-standard features
- 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 oneyield
expression. - Expression closures
- The expression closure syntax is a shorthand for writing simple function.
Specifications
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition. | 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, Array comprehensions, Generator comprehensions |
See also
Comentários
- Comentários de código (
//
and/* */
)
E4X (extensão)
Declarações Globais:
Funções Globais:
Construtores Globais: