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.
这是一个关于JavaScript语法的问题集合。这也是一个社区维基,所以每个人都被邀请来维护这个列表。
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.
主要思想是在Stack Overflow上有对现有问题的链接,所以我们更容易引用它们,而不是从ECMAScript规范中复制内容。
Additionally, this is a blatant copy of the PHP symbol reference. We needed a JS one.
此外,这是PHP符号引用的公然拷贝。我们需要一个JS。
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
请帮助。编辑并添加到其他操作符/语法引用的链接,或者如果您在特定的语法上找不到好的问题/答案,请在这个问题上添加一个答案并链接它。
1 个解决方案
#1
112
MDN参考运营商
The List
==
, ===
Equality Operators
= = = = =平等运营商
- Which equals operator (== vs ===) should be used in JavaScript comparisons?
- 在JavaScript比较中应该使用哪个=运算符(== vs ==) ?
- How does JS type coercion work?
- JS类型强制如何工作?
- In Javascript, <int-value> == "<int-value>" evaluates to true. Why is it so?
-
在Javascript中,
= " "计算为true。为什么如此? - [] == ![] evaluates to true
- [] ==
- Why does "undefined equals false" return false?
- 为什么“undefined = false”返回false?
- Why does !new Boolean(false) equals false in JavaScript?
- 为什么?新的布尔(false)在JavaScript中等于false ?
- Javascript 0 == '0'. Explain this example
- Javascript 0 = = ' 0 '。解释这个例子
- Why false == "false" is false?
- 为什么false = "false"是假的?
!=
, !==
Inequality Operators
=、! = =不平等
- != vs. !==
- =和! = =
- Javascript operator !==
- Javascript操作符! = =
&&
, ||
, !
Logical Operators
& &,| |,!逻辑运算符
- Logical operators in JavaScript — how do you use them?
- JavaScript中的逻辑运算符——如何使用它们?
- Logical operator || in javascript, 0 stands for Boolean false?
- 逻辑运算符||在javascript中,0代表布尔错误?
- What does "var FOO = FOO || {}" (assign a variable or an empty object to that variable) mean in Javascript?, JavaScript OR (||) variable assignment explanation, What does the construct x = x || y mean?
- 在Javascript中,“var FOO = FOO ||{}”(为该变量分配一个变量或一个空对象)是什么意思?, JavaScript或(||)变量赋值说明,构造x = x || y是什么意思?
- Javascript AND operator within assignment
- Javascript和赋值操作符
- What is "x && foo()"? (also here and here)
- 什么是“x && foo()”?(这里和这里)
- What is the !! (not not) operator in JavaScript?
- 是什么! !(不是)JavaScript中的操作符?
- What is an exclamation point in JavaScript?
- 什么是JavaScript的感叹号?
,
Comma Operator
,逗号操作符
- What does a comma do in JavaScript expressions?
- 在JavaScript表达式中,逗号的作用是什么?
- Comma operator returns first value instead of second in argument list?
- 逗号操作符在参数列表中返回第一个值而不是第二个值?
- When is the comma operator useful?
- 逗号运算符什么时候有用?
?…:
Conditional (ternary) Operator
?…:条件(三元)操作符
- Question mark and colon in JavaScript
- JavaScript中的问号和冒号
- Operator precedence with Javascript Ternary operator
- 运算符优先与Javascript三元运算符
- How do you use the ? : (conditional) operator in JavaScript?
- 如何使用?:(条件)JavaScript中的操作符?
|
, &
, ^
, ~
Bitwise OR, AND, XOR & NOT operators
&,|,^ ~位,或者,XOR和运营商
- What do these JavaScript bitwise operators do?
- 这些JavaScript位操作符做什么?
- How to: The ~ operator?
- 如何:~操作员?
- Is there a & logical operator in Javascript
- Javascript中是否有&逻辑运算符
- What does the "|" (single pipe) do in JavaScript?
- “|”(单个管道)在JavaScript中做什么?
- What does the operator |= do in JavaScript?
- 操作符|=在JavaScript中做什么?
- Javascript, What does the ^ (caret) operator do?
- Javascript,^(脱字符号)运营商做什么?
- Using bitwise OR 0 to floor a number, How does x|0 floor the number in JavaScript?
- 用bitwise或0来表示一个数字,x|是如何在JavaScript中使用这个数字的?
- Why does
~1
equal-2
? - 为什么~1 = -2?
- What does ~~ ("double tilde") do in Javascript?
- 在Javascript中~(“double tilde”)做什么?
- How does !!~ (not not tilde/bang bang tilde) alter the result of a 'contains/included' Array method call? (also here and here)
- 如何! !~(不是tilde/bang tilde)修改'contains/include ' Array方法调用的结果?(这里和这里)
<<
, >>
, >>>
Bit shift operators
<<, >>, >>>位移位算子
- What do these JavaScript bitwise operators do?
- 这些JavaScript位操作符做什么?
- What is the JavaScript >>> operator and how do you use it?
- 什么是JavaScript >>>操作符?如何使用它?
+
, -
operators
+、-运营商
- What does = +_ mean in JavaScript, Single plus operator in javascript
- 在JavaScript中= +_是什么意思
- What's the significant use of unary plus and minus operators?
- 一元正负运算符的重要用途是什么?
++
, --
pre/post-increment/decrement operators
+ +,——pre / post-increment /递减运算符
++someVariable
vssomeVariable++
in Javascript- +someVariable与someVariable++在Javascript中
void
operator
空白符
- What does `void 0` mean?
- “void 0”是什么意思?
var x = function()
vs function x()
Function Declaration Syntax
var x = function() vs函数x()函数声明语法。
- var functionName = function() {} vs function functionName() {}
- var functionName = function() {} vs函数functionName() {}
=>
Arrow function expression syntax
=>箭头函数表达式语法
- What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript?
- 在JavaScript中,“=>”(由等号和大于组成的箭头)的含义是什么?
(function(){...})()
IIFE (Immediately Invoked Function Expression)
(function(){…})()IIFE(立即调用函数表达式)
- What is the purpose?, How is it called?
- 的目的是什么?,如何称呼?
- Why does
(function(){…})();
work butfunction(){…}();
doesn't? - 为什么(函数(){…})();工作,但函数(){…}();不?
(function(){…})();
vs(function(){…}());
- (函数(){…})();vs(函数(){…}());
-
shorter alternatives:
-
!function(){…}();
- What does the exclamation mark do before the function? - !(){…}()函数;-感叹号在函数之前做什么?
-
+function(){…}();
- JavaScript plus sign in front of function name - +(){…}()函数;-在函数名前面加上JavaScript符号
-
!function(){ }() vs (function(){ })(),
!
vs leading semicolon - !函数(){}()vs(函数(){})()!与领先的分号
-
- 短的替代品:!函数(){…}();-感叹号在函数之前做什么?+(){…}()函数;-在函数名前面加上JavaScript加符号!函数(){}()vs(函数(){})()!与领先的分号
(function(window, undefined){…}(window));
- (函数(窗口,定义){…}(窗口));
[]
, Array()
Array Notation
[]数组()数组表示法
- What’s the difference between "Array()" and "[]" while declaring a JavaScript array?
- 在声明JavaScript数组时,“Array()”和“[]”的区别是什么?
- What is array literal notation in javascript and when should you use it?
- javascript中什么是数组文字符号,什么时候应该使用它?
$
in regex replace patterns: $$
, $&
, $`
, $'
, $n
$ in regex替换模式:$$ $$ $$,$n。
- JavaScript replace() method dollar signs
- JavaScript替换()方法元符号
{key: value}
Object literal syntax:
{key: value}对象文字语法:
- What do curly braces in JavaScript mean?
- JavaScript中的花括号是什么意思?
- Javascript object literal: what exactly is {a, b, c}?
- Javascript对象文字:什么是{a, b, c}?
- What do square brackets around a property name in an object literal mean?
- 在对象文字中,围绕属性名的方括号是什么意思?
Destructuring:
解构:
- of function parameters: Where can I get info on the object parameter syntax for javascript functions?
- 函数参数:在哪里可以获得关于javascript函数的对象参数语法的信息?
- of arrays: Multiple assignment in javascript? What does [a,b,c] = [1, 2, 3]; mean?
- 数组:javascript中的多重赋值?[a,b,c] = [1,2,3];的意思吗?
- of objects/imports: Javascript object bracket notation ({ Navigation } =) on left side of assign
- 对象/导入:在赋值左侧的Javascript对象括号表示法({导航}=)
Template literals:
模板文字:
- What does this
`…${…}…`
code from the node docs mean? - 来自节点文档的“…${…}”代码是什么意思?
function*
, yield
, yield*
Generator functions:
函数*、良率、良率*生成器函数:
- What is "function*" in JavaScript?
- JavaScript中的“函数*”是什么?
- What's the yield keyword in JavaScript?
- JavaScript中的yield关键字是什么?
- Delegated yield (yield star, yield *) in generator functions
- 在生成器函数中委派产量(产量星,产量*)
var
, let
, const
Declaring variables:
var, let, const声明变量:
- What's the difference between using "let" and "var" to declare a variable in JavaScript?
- 在JavaScript中使用“let”和“var”声明变量有什么区别?
- Are there constants in JavaScript?
- JavaScript中有常量吗?
- What is the temporal dead zone?
- 什么是时间死区?
this
Keyword:
关键字:
- How does the "this" keyword work?
- 这个关键字是如何工作的?
::
Bind operator:
::绑定运营商:
- JavaScript double colon (bind operator)
- JavaScript双冒号(绑定操作符)
new
operator
新的操作符
- What is the 'new' keyword in JavaScript?
- JavaScript中的“new”关键字是什么?
- What is "new.target"?
- “new.target”是什么?
delete
operator
删除操作符
- What is the purpose of the delete operator in Javascript?
- 在Javascript中,删除操作符的目的是什么?
label:
Labels
标签:标签
- Javascript strange syntax that works - but how?
- Javascript奇怪的语法-但是怎么做呢?
+=
Operator
+ =操作符
- How does += (plus equal) work?
- +=(+等)是怎么工作的?
...args
— Spread syntax
…arg游戏——传播语法
- What is the meaning of "...args" (three dots) in a function definition?
- 什么是“……”函数定义中的三个点?
- What does the "..." (triple dot) notation in arrays mean?
- 什么“……”数组中的(三重点)表示法是什么意思?
#1
112
MDN参考运营商
The List
==
, ===
Equality Operators
= = = = =平等运营商
- Which equals operator (== vs ===) should be used in JavaScript comparisons?
- 在JavaScript比较中应该使用哪个=运算符(== vs ==) ?
- How does JS type coercion work?
- JS类型强制如何工作?
- In Javascript, <int-value> == "<int-value>" evaluates to true. Why is it so?
-
在Javascript中,
= " "计算为true。为什么如此? - [] == ![] evaluates to true
- [] ==
- Why does "undefined equals false" return false?
- 为什么“undefined = false”返回false?
- Why does !new Boolean(false) equals false in JavaScript?
- 为什么?新的布尔(false)在JavaScript中等于false ?
- Javascript 0 == '0'. Explain this example
- Javascript 0 = = ' 0 '。解释这个例子
- Why false == "false" is false?
- 为什么false = "false"是假的?
!=
, !==
Inequality Operators
=、! = =不平等
- != vs. !==
- =和! = =
- Javascript operator !==
- Javascript操作符! = =
&&
, ||
, !
Logical Operators
& &,| |,!逻辑运算符
- Logical operators in JavaScript — how do you use them?
- JavaScript中的逻辑运算符——如何使用它们?
- Logical operator || in javascript, 0 stands for Boolean false?
- 逻辑运算符||在javascript中,0代表布尔错误?
- What does "var FOO = FOO || {}" (assign a variable or an empty object to that variable) mean in Javascript?, JavaScript OR (||) variable assignment explanation, What does the construct x = x || y mean?
- 在Javascript中,“var FOO = FOO ||{}”(为该变量分配一个变量或一个空对象)是什么意思?, JavaScript或(||)变量赋值说明,构造x = x || y是什么意思?
- Javascript AND operator within assignment
- Javascript和赋值操作符
- What is "x && foo()"? (also here and here)
- 什么是“x && foo()”?(这里和这里)
- What is the !! (not not) operator in JavaScript?
- 是什么! !(不是)JavaScript中的操作符?
- What is an exclamation point in JavaScript?
- 什么是JavaScript的感叹号?
,
Comma Operator
,逗号操作符
- What does a comma do in JavaScript expressions?
- 在JavaScript表达式中,逗号的作用是什么?
- Comma operator returns first value instead of second in argument list?
- 逗号操作符在参数列表中返回第一个值而不是第二个值?
- When is the comma operator useful?
- 逗号运算符什么时候有用?
?…:
Conditional (ternary) Operator
?…:条件(三元)操作符
- Question mark and colon in JavaScript
- JavaScript中的问号和冒号
- Operator precedence with Javascript Ternary operator
- 运算符优先与Javascript三元运算符
- How do you use the ? : (conditional) operator in JavaScript?
- 如何使用?:(条件)JavaScript中的操作符?
|
, &
, ^
, ~
Bitwise OR, AND, XOR & NOT operators
&,|,^ ~位,或者,XOR和运营商
- What do these JavaScript bitwise operators do?
- 这些JavaScript位操作符做什么?
- How to: The ~ operator?
- 如何:~操作员?
- Is there a & logical operator in Javascript
- Javascript中是否有&逻辑运算符
- What does the "|" (single pipe) do in JavaScript?
- “|”(单个管道)在JavaScript中做什么?
- What does the operator |= do in JavaScript?
- 操作符|=在JavaScript中做什么?
- Javascript, What does the ^ (caret) operator do?
- Javascript,^(脱字符号)运营商做什么?
- Using bitwise OR 0 to floor a number, How does x|0 floor the number in JavaScript?
- 用bitwise或0来表示一个数字,x|是如何在JavaScript中使用这个数字的?
- Why does
~1
equal-2
? - 为什么~1 = -2?
- What does ~~ ("double tilde") do in Javascript?
- 在Javascript中~(“double tilde”)做什么?
- How does !!~ (not not tilde/bang bang tilde) alter the result of a 'contains/included' Array method call? (also here and here)
- 如何! !~(不是tilde/bang tilde)修改'contains/include ' Array方法调用的结果?(这里和这里)
<<
, >>
, >>>
Bit shift operators
<<, >>, >>>位移位算子
- What do these JavaScript bitwise operators do?
- 这些JavaScript位操作符做什么?
- What is the JavaScript >>> operator and how do you use it?
- 什么是JavaScript >>>操作符?如何使用它?
+
, -
operators
+、-运营商
- What does = +_ mean in JavaScript, Single plus operator in javascript
- 在JavaScript中= +_是什么意思
- What's the significant use of unary plus and minus operators?
- 一元正负运算符的重要用途是什么?
++
, --
pre/post-increment/decrement operators
+ +,——pre / post-increment /递减运算符
++someVariable
vssomeVariable++
in Javascript- +someVariable与someVariable++在Javascript中
void
operator
空白符
- What does `void 0` mean?
- “void 0”是什么意思?
var x = function()
vs function x()
Function Declaration Syntax
var x = function() vs函数x()函数声明语法。
- var functionName = function() {} vs function functionName() {}
- var functionName = function() {} vs函数functionName() {}
=>
Arrow function expression syntax
=>箭头函数表达式语法
- What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript?
- 在JavaScript中,“=>”(由等号和大于组成的箭头)的含义是什么?
(function(){...})()
IIFE (Immediately Invoked Function Expression)
(function(){…})()IIFE(立即调用函数表达式)
- What is the purpose?, How is it called?
- 的目的是什么?,如何称呼?
- Why does
(function(){…})();
work butfunction(){…}();
doesn't? - 为什么(函数(){…})();工作,但函数(){…}();不?
(function(){…})();
vs(function(){…}());
- (函数(){…})();vs(函数(){…}());
-
shorter alternatives:
-
!function(){…}();
- What does the exclamation mark do before the function? - !(){…}()函数;-感叹号在函数之前做什么?
-
+function(){…}();
- JavaScript plus sign in front of function name - +(){…}()函数;-在函数名前面加上JavaScript符号
-
!function(){ }() vs (function(){ })(),
!
vs leading semicolon - !函数(){}()vs(函数(){})()!与领先的分号
-
- 短的替代品:!函数(){…}();-感叹号在函数之前做什么?+(){…}()函数;-在函数名前面加上JavaScript加符号!函数(){}()vs(函数(){})()!与领先的分号
(function(window, undefined){…}(window));
- (函数(窗口,定义){…}(窗口));
[]
, Array()
Array Notation
[]数组()数组表示法
- What’s the difference between "Array()" and "[]" while declaring a JavaScript array?
- 在声明JavaScript数组时,“Array()”和“[]”的区别是什么?
- What is array literal notation in javascript and when should you use it?
- javascript中什么是数组文字符号,什么时候应该使用它?
$
in regex replace patterns: $$
, $&
, $`
, $'
, $n
$ in regex替换模式:$$ $$ $$,$n。
- JavaScript replace() method dollar signs
- JavaScript替换()方法元符号
{key: value}
Object literal syntax:
{key: value}对象文字语法:
- What do curly braces in JavaScript mean?
- JavaScript中的花括号是什么意思?
- Javascript object literal: what exactly is {a, b, c}?
- Javascript对象文字:什么是{a, b, c}?
- What do square brackets around a property name in an object literal mean?
- 在对象文字中,围绕属性名的方括号是什么意思?
Destructuring:
解构:
- of function parameters: Where can I get info on the object parameter syntax for javascript functions?
- 函数参数:在哪里可以获得关于javascript函数的对象参数语法的信息?
- of arrays: Multiple assignment in javascript? What does [a,b,c] = [1, 2, 3]; mean?
- 数组:javascript中的多重赋值?[a,b,c] = [1,2,3];的意思吗?
- of objects/imports: Javascript object bracket notation ({ Navigation } =) on left side of assign
- 对象/导入:在赋值左侧的Javascript对象括号表示法({导航}=)
Template literals:
模板文字:
- What does this
`…${…}…`
code from the node docs mean? - 来自节点文档的“…${…}”代码是什么意思?
function*
, yield
, yield*
Generator functions:
函数*、良率、良率*生成器函数:
- What is "function*" in JavaScript?
- JavaScript中的“函数*”是什么?
- What's the yield keyword in JavaScript?
- JavaScript中的yield关键字是什么?
- Delegated yield (yield star, yield *) in generator functions
- 在生成器函数中委派产量(产量星,产量*)
var
, let
, const
Declaring variables:
var, let, const声明变量:
- What's the difference between using "let" and "var" to declare a variable in JavaScript?
- 在JavaScript中使用“let”和“var”声明变量有什么区别?
- Are there constants in JavaScript?
- JavaScript中有常量吗?
- What is the temporal dead zone?
- 什么是时间死区?
this
Keyword:
关键字:
- How does the "this" keyword work?
- 这个关键字是如何工作的?
::
Bind operator:
::绑定运营商:
- JavaScript double colon (bind operator)
- JavaScript双冒号(绑定操作符)
new
operator
新的操作符
- What is the 'new' keyword in JavaScript?
- JavaScript中的“new”关键字是什么?
- What is "new.target"?
- “new.target”是什么?
delete
operator
删除操作符
- What is the purpose of the delete operator in Javascript?
- 在Javascript中,删除操作符的目的是什么?
label:
Labels
标签:标签
- Javascript strange syntax that works - but how?
- Javascript奇怪的语法-但是怎么做呢?
+=
Operator
+ =操作符
- How does += (plus equal) work?
- +=(+等)是怎么工作的?
...args
— Spread syntax
…arg游戏——传播语法
- What is the meaning of "...args" (three dots) in a function definition?
- 什么是“……”函数定义中的三个点?
- What does the "..." (triple dot) notation in arrays mean?
- 什么“……”数组中的(三重点)表示法是什么意思?