What does this symbol mean in JavaScript?
JavascriptJavascript Problem Overview
What is this?
This is a collection of questions that come up every now and then about syntax in JavaScript. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
Why is this?
Stack Overflow does not allow searching for particular characters. As a consequence, many questions about operators and other syntax tokens are not found easily when searching for them. This also makes closing duplicates more difficult. The list below is to help with this issue.
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from the ECMAScript Spec.
Additionally, this is a blatant copy of the PHP symbol reference. We needed a JS one.
Please help. Edit and add links to other operators/syntax references, or if you can't find good questions/answers on a particular piece of syntax, add an answer to this question and link it
Javascript Solutions
Solution 1 - Javascript
See the documentation on MDN about expressions and operators and statements.
Basic keywords and general expressions
this
keyword:
var x = function()
vs. function x()
— Function declaration syntax
(function(){
…})()
— IIFE (Immediately Invoked Function Expression)
- What is the purpose?, How is it called?
- Why does
(function(){…})();
work butfunction(){…}();
doesn't? (function(){…})();
vs(function(){…}());
- shorter alternatives:
!function(){…}();
- https://stackoverflow.com/q/3755606/1048572+function(){…}();
- https://stackoverflow.com/q/13341698/1048572- https://stackoverflow.com/q/8305915/1048572,
!
vs leading semicolon
(function(window, undefined){…}(window));
someFunction()()
— Functions which return other functions
=>
— Equal sign, greater than: arrow function expression syntax
|>
— Pipe, greater than: Pipeline operator
function*
, yield
, yield*
— Star after function
or yield
: generator functions
- https://stackoverflow.com/q/9620586/1529630
- https://stackoverflow.com/q/2282140/1529630
- https://stackoverflow.com/q/17491779/1529630
[]
, Array()
— Square brackets: array notation
- https://stackoverflow.com/questions/931872/whats-the-difference-between-array-and-while-declaring-a-javascript-ar
- https://stackoverflow.com/questions/1094723/what-is-array-literal-notation-in-javascript-and-when-should-you-use-it
If the square brackets appear on the left side of an assignment ([a] = ...
), or inside a function's parameters, it's a destructuring assignment.
{key: value}
— Curly brackets: object literal syntax (not to be confused with blocks)
- https://stackoverflow.com/questions/9699064/what-do-curly-braces-in-javascript-mean
- https://stackoverflow.com/questions/34414766/javascript-or-json-what-exactly-is-a-b-c
- https://stackoverflow.com/questions/34831262/what-do-square-brackets-around-a-property-name-in-an-object-literal-mean
- https://stackoverflow.com/questions/32404617/how-does-this-object-method-definition-work-without-the-function-keyword (ES2015 Method definitions)
If the curly brackets appear on the left side of an assignment ({ a } = ...
) or inside a function's parameters, it's a destructuring assignment.
`
…${
…}
…`
— Backticks, dollar sign with curly brackets: template literals
- What does this
`…${…}…`
code from the node docs mean? - Usage of the backtick character (`) in JavaScript?
- What is the purpose of template literals (backticks) following a function in ES6?
/
…/
— Slashes: regular expression literals
$
— Dollar sign in regex replace patterns: $$
, $&
, $`
, $'
, $n
()
— Parentheses: grouping operator
Property-related expressions
obj.prop
, obj[prop]
, obj["prop"]
— Square brackets or dot: property accessors
?.
, ?.[]
, ?.()
— Question mark, dot: optional chaining operator
- Question mark after parameter
- https://stackoverflow.com/questions/32139078/null-safe-property-access-and-conditional-assignment-in-es6-2015
- https://stackoverflow.com/questions/26183944/optional-chaining-in-javascript
- https://stackoverflow.com/questions/6613952/is-there-a-null-coalescing-elvis-operator-or-safe-navigation-operator-in-javas
- https://stackoverflow.com/questions/476436/is-there-a-null-coalescing-operator-in-javascript
::
— Double colon: bind operator
new
operator
...iter
— Three dots: spread syntax; rest parameters
(...rest) => {}
— What is the meaning of “…args” (three dots) in a function definition?fn(...args)
— What is the meaning of “foo(…arg)” (three dots in a function call)?[...iter]
— javascript es6 array feature […data, 0] “spread operator”{...props}
— Javascript Property with three dots (…), What does the '…rest' stand for in this object destructuring?
Increment and decrement
++
, --
— Double plus or minus: pre- / post-increment / -decrement operators
Unary and binary (arithmetic, logical, bitwise) operators
delete
operator
void
operator
+
, -
— Plus and minus: addition or concatenation, and subtraction operators; unary sign operators
- https://stackoverflow.com/q/15129137/1048572, https://stackoverflow.com/q/14470973/1048572
- https://stackoverflow.com/q/5450076/1048572
- https://stackoverflow.com/questions/7124884/why-is-1-2-3-4-1-23-4-in-javascript
- https://stackoverflow.com/questions/24383788/1048572
|
, &
, ^
, ~
— Single pipe, ampersand, circumflex, tilde: bitwise OR, AND, XOR, & NOT operators
- https://stackoverflow.com/questions/4535328/what-do-these-operators-do
- https://stackoverflow.com/q/6260475/1048572
- https://stackoverflow.com/q/3374811/1048572
- https://stackoverflow.com/q/6194950/1048572
- https://stackoverflow.com/q/12854644/1048572
- https://stackoverflow.com/q/3618340/1048572
- https://stackoverflow.com/questions/7487977/using-bitwise-or-0-to-floor-a-number, https://stackoverflow.com/questions/9049677/how-does-x0-floor-the-number-in-javascript
- Why does
~1
equal-2
? - https://stackoverflow.com/q/4055633/1048572
- https://stackoverflow.com/q/9316612/1048572 (also here and here)
%
— Percent sign: remainder operator
&&
, ||
, !
— Double ampersand, double pipe, exclamation point: logical operators
- https://stackoverflow.com/questions/4535647/logical-operators-in-javascript-how-do-you-use-them
- https://stackoverflow.com/questions/9579262/logical-operator-in-javascript-0-stands-for-boolean-false
- https://stackoverflow.com/questions/6439579/what-does-var-foo-foo-mean-in-javascript, https://stackoverflow.com/q/2100758/1048572, https://stackoverflow.com/q/2802055/1048572
- https://stackoverflow.com/q/3163407/1048572
- https://stackoverflow.com/q/6970346/1048572 (also here and here)
- https://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript
- https://stackoverflow.com/questions/8012003/what-is-an-exclamation-point-in-javascript
??
— Double question mark: nullish-coalescing operator
- How is the nullish coalescing operator (??) different from the logical OR operator (||) in ECMAScript?
- https://stackoverflow.com/questions/6613952/is-there-a-null-coalescing-elvis-operator-or-safe-navigation-operator-in-javas
- https://stackoverflow.com/questions/476436/is-there-a-null-coalescing-operator-in-javascript
**
— Double star: power operator (exponentiation)
x ** 2
is equivalent toMath.pow(x, 2)
- Is the double asterisk ** a valid JavaScript operator?
- MDN documentation
Equality operators
==
, ===
— Equal signs: equality operators
- https://stackoverflow.com/questions/359494/javascript-vs-does-it-matter-which-equal-operator-i-use
- https://stackoverflow.com/questions/27523765/how-does-js-type-coercion-work
- https://stackoverflow.com/questions/664886/in-javascript-int-value-int-value-evaluates-to-true-why-is-it-so
- https://stackoverflow.com/questions/38662231
- https://stackoverflow.com/questions/19277458/why-does-undefined-equals-false-return-false/19277873
- https://stackoverflow.com/questions/8695341/why-does-new-booleanfalse-equals-false-in-javascript
- https://stackoverflow.com/questions/25190495/javascript-0-0-explain-this-example
- https://stackoverflow.com/questions/38814212/why-false-false-is-false
!=
, !==
— Exclamation point and equal signs: inequality operators
Bit shift operators
<<
, >>
, >>>
— Two or three angle brackets: bit shift operators
- https://stackoverflow.com/questions/4535328/what-do-these-operators-do
- Double more-than symbol in JavaScript
- https://stackoverflow.com/q/1822350/1048572
Conditional operator
?
…:
… — Question mark and colon: conditional (ternary) operator
…- https://stackoverflow.com/q/1771786/1048572
- https://stackoverflow.com/q/1788917/1048572
- https://stackoverflow.com/q/6259982/1106925
Assignment operators
=
— Equal sign: assignment operator
This symbol is also used for default parameters or default values in a destructuring assignment:
%=
— Percent equals: remainder assignment
+=
— Plus equals: addition assignment operator
&&=
, ||=
, ??=
— Double ampersand, pipe, or question mark, followed by equal sign: logical assignments
- What purpose do &&=, ||= and ??= serve?
- Replace a value if null or undefined in JavaScript
- Set a variable if undefined
- Ruby’s
||=
(or equals) in JavaScript? - Original proposal
- Specification
Destructuring
- of function parameters: https://stackoverflow.com/q/10804982/1048572
- of arrays: https://stackoverflow.com/q/3986348/1048572
- of objects/imports: https://stackoverflow.com/q/26999820/1048572
Comma operator
,
— Comma operator (not to be confused with the comma used in variable declarations)
- https://stackoverflow.com/questions/3561043/javascript-syntax-what-comma-means
- https://stackoverflow.com/questions/5580596/javascript-comma-operator
- https://stackoverflow.com/questions/9579546/comma-operator-where-it-can-really-be-useful
Control flow
{
…}
— Curly brackets: blocks (not to be confused with object literal syntax)
Declarations
var
, let
, const
— Declaring variables
- https://stackoverflow.com/q/762011/1529630
- https://stackoverflow.com/q/130396/1529630
- https://stackoverflow.com/q/33198849/1529630
var a, b;
— Comma used in variable declarations (not to be confused with the comma operator): JavaScript variable definition: Commas vs. Semicolons