这个符号在 JavaScript 中意味着什么?

这是什么?

这是一个关于 JavaScript 语法的时不时出现的问题集合。这也是一个社区维基,所以每个人都被邀请参与维护这份名单。

为什么会这样?

堆栈溢出不允许搜索特定字符。因此,在搜索运算符和其他语法标记时,很难找到关于它们的许多问题。这也使得结束副本更加困难。下面的列表可以帮助解决这个问题。

其主要思想是提供指向 Stack Overflow 上现有问题的链接,这样我们可以更容易地引用它们,而不是复制来自 ECMAScript Spec 的内容。

此外,这是 PHP符号引用的明显副本。我们需要一个 JS 的。


请帮帮我。编辑并添加指向其他操作符/语法引用的链接,或者如果您无法找到关于特定语法的好问题/答案,请添加此问题的答案并链接它

337371 次浏览

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)

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

[], [ value ], Array()  —  Square brackets: array notation

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 }, { [key]: value }  —  Curly brackets: object literal syntax (not to be confused with blocks)

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

//  —  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

::  —  Double colon: bind operator

new operator

...iter  —  Three dots: spread syntax; rest parameters


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

|, &, ^, ~  —  Single pipe, ampersand, circumflex, tilde: bitwise OR, AND, XOR, & NOT operators

%  —  Percent sign: remainder operator

&&, ||, !  —  Double ampersand, double pipe, exclamation point: logical operators

??  —  Double question mark: nullish-coalescing operator

**  —  Double star: power operator (exponentiation)


Equality operators

==, ===  —  Equal signs: equality operators

!=, !==  —  Exclamation point and equal signs: inequality operators


Bit shift operators

<<, >>, >>>  —  Two or three angle brackets: bit shift operators


Conditional operator

?:…  —  Question mark and colon: conditional (ternary) operator


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

<<=, >>=, >>>=, &=, ^=, |= — Double less than, double greater than, triple greater than, ampersand, caret, or pipe followed by equal sign: bitwise assignments

Destructuring


Comma operator

,  —  Comma operator (not to be confused with the comma used in variable declarations)


Control flow

{}  — Curly brackets: blocks (not to be confused with object literal syntax)

Declarations

var, let, const  —  Declaring variables


Label

label:  —  Colon: labels


Other

123n  —  n after integer: BigInt

#  —  Hash (number sign): Private methods or private fields

_  —  Underscore: separator in numeric literals