Operatory
This chapter documents all the JavaScript language operators, expressions and keywords.
Wyrażenia i operatory w podziale na kategorie
Lista operatorów w kolejności alfabetycznej znajduje sie w pasku bocznym po lewej stronie.
Wyrażenia podstawowe
Podstawowe słowa kluczowe i wyrażenia w JavaScript.
this
- Słowo
this
odnosi się do kontekstu wywołania. function
- Słowo
function
umożliwia zdefniowanie wyrażenia funkcji . -
Experimental
class
- Słowo
class
definiuje wyrażenie klasy. -
Experimental
function*
- The
function*
keyword defines a generator function expression. -
Experimental
yield
- Pause and resume a generator function
-
Experimental
yield*
- Delegate to another generator function or iterable object.
[]
- Array initializer/literal syntax.
{}
- Object initializer/literal syntax.
/ab+c/i
- Regular expression literal syntax.
-
Experimental
[for (x of y) x]
- Array comprehensions.
-
Experimental
(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. -
Experimental
super
- The
super
keyword calls the parent constructor. -
Experimental
...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
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.
Operatory arytmetyczne
Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.
Operatory porównania
Operator porównania, jak nazwa wskazuje, porównuje operandy i zwraca wartość logiczną zależną od tego, czy wartość porównania jest prawdziwa.
Equality operators
Bitwise shift operators
Binary bitwise operators
Binary logical operators
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.
>>>=
(en-US)- Unsigned right shift assignment.
&=
- Bitwise AND assignment.
^=
- Bitwise XOR assignment.
|=
- Bitwise OR assignment.
-
Experimental
[a, b] = [1, 2]
Experimental{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
- Non-Standard 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. - Non-Standard 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 |