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
MDN reference on operators
The List
==
, ===
Equality Operators
Which equals operator (== vs ===) should be used in JavaScript comparisons? How does JS type coercion work? In Javascript, <int-value> == "<int-value>" evaluates to true. Why is it so? [] == ![] evaluates to true Why does "undefined equals false" return false? Why does !new Boolean(false) equals false in JavaScript? Javascript 0 == '0'. Explain this example Why false == "false" is false?
!=
, !==
Inequality Operators
!= vs. !== Javascript operator !==
&&
, ||
, !
Logical Operators
Logical operators in JavaScript — how do you use them? Logical operator || in javascript, 0 stands for Boolean false? 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 AND operator within assignment What is "x && foo()"? (also here and here) What is the !! (not not) operator in JavaScript? What is an exclamation point in JavaScript?
,
Comma Operator
What does a comma do in JavaScript expressions? Comma operator returns first value instead of second in argument list? When is the comma operator useful?
?…:
Conditional (ternary) Operator
Question Mark in JavaScript Operator precedence with Javascript Ternary operator How do you use the ? : (conditional) operator in JavaScript?
|
, &
, ^
, ~
Bitwise OR, AND, XOR & NOT operators
What do these JavaScript bitwise operators do? How to: The ~ operator? Is there a & logical operator in Javascript What does the "|" (single pipe) do in JavaScript? What does the operator |= do in JavaScript? Javascript, What does the ^ (caret) operator do? Using bitwise OR 0 to floor a number, How does x|0 floor the number in JavaScript? Why does ~1
equal -2
? What does ~~ ("double tilde") do in Javascript? How does !!~ (not not tilde/bang bang tilde) alter the result of a 'contains/included' Array method call? (also here and here)
<<
, >>
, >>>
Bit shift operators
What do these JavaScript bitwise operators do? What is the JavaScript >>> operator and how do you use it?
+
, -
operators
What does = +_ mean in JavaScript, Single plus operator in javascript What's the significant use of unary plus and minus operators?
++
, --
pre/post-increment/decrement operators
++someVariable
vs someVariable++
in Javascript
void
operator
What does `void 0` mean?
var x = function()
vs function x()
Function Declaration Syntax
var functionName = function() {} vs function functionName() {}
=>
Arrow function expression syntax
What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript?
(function(){...})()
IIFE (Immediately Invoked Function Expression)
What is the purpose?, How is it called? Why does (function(){…})();
work but function(){…}();
doesn't? (function(){…})();
vs (function(){…}());
shorter alternatives: !function(){…}();
- What does the exclamation mark do before the function? +function(){…}();
- JavaScript plus sign in front of function name !function(){ }() vs (function(){ })(), !
vs leading semicolon (function(window, undefined){…}(window));
[]
, Array()
Array Notation
What's the difference between "Array()" and "[]" while declaring a JavaScript array? What is array literal notation in javascript and when should you use it?
$
in regex replace patterns: $$
, $&
, $`
, $'
, $n
JavaScript replace() method dollar signs
Object literal syntax
Javascript object literal: what exactly is {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? of arrays: Multiple assignment in javascript? What does [a,b,c] = [1, 2, 3]; mean? of objects/imports: Javascript object bracket notation ({ Navigation } =) on left side of assign
Template literals:
What does this `…${…}…`
code from the node docs mean?
function*
, yield
, yield*
Generator functions:
What is "function*" in JavaScript? What's the yield keyword in JavaScript? Delegated yield (yield star, yield *) in generator functions
var
, let
, const
Declaring variables:
What's the difference between using "let" and "var" to declare a variable? Are there constants in JavaScript? What is the temporal dead zone?
this
Keyword:
How does the "this" keyword work?
::
Bind operator:
JavaScript double colon (bind operator)
new
operator
What is the 'new' keyword in JavaScript? What is "new.target"?
delete
operator
What is the purpose of the delete operator in Javascript?
label:
Labels
Javascript strange syntax that works - but how?
+=
Operator
How does += (plus equal) work?
...args
— Spread syntax
What is the meaning of "...args" (three dots) in a function definition? What does the "..." (triple dot) notation in arrays mean?
链接地址:
http://www.djcxy.com/p/73938.html
上一篇:
JavaScript为一个数字添加一个字符串
下一篇:
这个符号在JavaScript中意味着什么?