diff --git a/files/en-us/web/javascript/reference/operators/assignment/index.html b/files/en-us/web/javascript/reference/operators/assignment/index.html index 35f234e7d3226bc..d8879b7998fdc47 100644 --- a/files/en-us/web/javascript/reference/operators/assignment/index.html +++ b/files/en-us/web/javascript/reference/operators/assignment/index.html @@ -2,11 +2,11 @@ title: Assignment (=) slug: Web/JavaScript/Reference/Operators/Assignment tags: -- Assignment operator -- JavaScript -- Language feature -- Operator -- Reference + - Assignment operator + - JavaScript + - Language feature + - Operator + - Reference ---
a & b
+a & bDescription
@@ -117,7 +117,7 @@Browser compatibility
See also
diff --git a/files/en-us/web/javascript/reference/operators/bitwise_or/index.html b/files/en-us/web/javascript/reference/operators/bitwise_or/index.html index 8774fe9fcf1fdfe..089822ff494c13b 100644 --- a/files/en-us/web/javascript/reference/operators/bitwise_or/index.html +++ b/files/en-us/web/javascript/reference/operators/bitwise_or/index.html @@ -2,11 +2,11 @@ title: Bitwise OR (|) slug: Web/JavaScript/Reference/Operators/Bitwise_OR tags: -- Bitwise operator -- JavaScript -- Language feature -- Operator -- Reference + - Bitwise operator + - JavaScript + - Language feature + - Operator + - Reference ---~a
+~aDescription
@@ -97,6 +97,6 @@Browser compatibility
See also
a | b
+a | bDescription
@@ -119,7 +119,7 @@Browser compatibility
See also
a ^ b
+a ^ bDescription
@@ -124,7 +124,7 @@Browser compatibility
See also
Throws {{jsxref("TypeError")}} in {{jsxref("Functions_and_function_scope/Strict_mode", +
Throws {{jsxref("TypeError")}} in {{jsxref("Strict_mode", "strict mode")}} if the property is an own non-configurable property.
Computed property names, like on object literals, can be used with destructuring.
+Computed property names, like on object literals, can be used with destructuring.
let key = 'z'; let {[key]: foo} = {z: 'bar'}; @@ -439,6 +439,6 @@diff --git a/files/en-us/web/javascript/reference/operators/division_assignment/index.html b/files/en-us/web/javascript/reference/operators/division_assignment/index.html index 4a313e82bd697a6..4116cac6a246bca 100644 --- a/files/en-us/web/javascript/reference/operators/division_assignment/index.html +++ b/files/en-us/web/javascript/reference/operators/division_assignment/index.html @@ -2,11 +2,11 @@ title: Division assignment (/=) slug: Web/JavaScript/Reference/Operators/Division_assignment tags: -- Assignment operator -- JavaScript -- Language feature -- Operator -- Reference + - Assignment operator + - JavaScript + - Language feature + - Operator + - Reference ---Browser compatibility
See also
Note that some programming languages use the caret symbol ^ for exponentiation, but JavaScript uses that symbol for the bitwise + href="/en-US/docs/Web/JavaScript/Reference/Operators#bitwise_xor">bitwise logical XOR operator.
a << b
+a << bDescription
@@ -66,6 +66,6 @@Browser compatibility
See also
Even though the &&
operator can be used with operands that are not
Boolean values, it can still be considered a boolean operator since its return value can
always be converted to a boolean primitive.
+ href="/en-US/docs/Web/JavaScript/Data_structures#boolean_type">boolean primitive
Even though the !
operator can be used with operands that are not Boolean
values, it can still be considered a boolean operator since its return value can always
be converted to a boolean primitive.
+ href="/en-US/docs/Web/JavaScript/Data_structures#boolean_type">boolean primitive
!!
)It is possible to use a couple of NOT operators in series to explicitly force the conversion of any value to the corresponding boolean primitive. + href="/en-US/docs/Web/JavaScript/Data_structures#boolean_type">boolean primitive
Even though the ||
operator can be used with operands that are not Boolean
values, it can still be considered a boolean operator since its return value can always
be converted to a boolean primitive.
+ href="/en-US/docs/Web/JavaScript/Data_structures#boolean_type">boolean primitive
{{JSSidebar("Operators")}}
@@ -19,8 +19,8 @@ href="/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR">logical OR (||
) operator, which returns the right-hand side operand if the left
operand is any falsy
+ href="/en-US/docs/Web/JavaScript/Reference/Operators#description">falsy
value, not only null
or undefined
. In other words,
if you use ||
to provide some default value to another variable
foo
, you may encounter unexpected behaviors if you consider some falsy
@@ -74,7 +74,7 @@ Earlier, when one wanted to assign a default value to a variable, a common pattern was
to use the logical OR operator
- (||
):
+ (||
):
let foo; @@ -187,7 +187,7 @@See also
||
) operatorAn object initializer is an expression that describes the initialization of an {{jsxref("Object")}}. Objects consist of properties, which are used to describe an object. The values of object properties can either contain primitive data types or other objects.
+An object initializer is an expression that describes the initialization of an {{jsxref("Object")}}. Objects consist of properties, which are used to describe an object. The values of object properties can either contain primitive data types or other objects.
The Rest/Spread Properties for ECMAScript proposal (stage 4) adds spread properties to object literals. It copies own enumerable properties from a provided object onto a new object.
+The Rest/Spread Properties for ECMAScript proposal (stage 4) adds spread properties to object literals. It copies own enumerable properties from a provided object onto a new object.
Shallow-cloning (excluding prototype
) or merging objects is now possible using a shorter syntax than {{jsxref("Object.assign()")}}.
… ++
… --
++ …
-- …
… = …
If you use callbacks or fetch methods from an object with a
+ href="/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#object_destructuring">a
destructuring assignment, you may have non-existent values that you cannot call as
functions unless you have tested their existence. Using ?.
, you can avoid
this extra test:
You can also use the optional chaining operator when accessing properties with an expression using the + href="/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors#bracket_notation">the bracket notation of the property accessor:
let nestedProp = obj?.['prop' + 'Name']; diff --git a/files/en-us/web/javascript/reference/operators/property_accessors/index.html b/files/en-us/web/javascript/reference/operators/property_accessors/index.html index ce23afbcb9051c8..9433f8c8cf71518 100644 --- a/files/en-us/web/javascript/reference/operators/property_accessors/index.html +++ b/files/en-us/web/javascript/reference/operators/property_accessors/index.html @@ -2,10 +2,10 @@ title: Property accessors slug: Web/JavaScript/Reference/Operators/Property_Accessors tags: -- JavaScript -- Language feature -- Operator -- Reference + - JavaScript + - Language feature + - Operator + - Reference ---{{jsSidebar("Operators")}}@@ -38,7 +38,7 @@Description
Dot notation
In the
object.property
syntax, theproperty
must - be a valid JavaScript identifier. (In the + be a valid JavaScript identifier. (In the ECMAScript standard, the names of properties are technically "IdentifierNames", not "Identifiers", so reserved words can be used but are not recommended). For example,object.$1
is valid, whileobject.1
is @@ -128,14 +128,14 @@Method binding
this
is not fixed in a method. Put another way,this
does not necessarily refer to the object containing a method. Instead,this
is "passed" by the function call. See method + href="/en-US/docs/Web/JavaScript/Reference/Operators/this#method_binding">method binding.Examples
Bracket notation vs.
-eval
JavaScript novices often make the mistake of using {{jsxref("eval", "eval()")}} where +
JavaScript novices often make the mistake of using {{jsxref("Global_Objects/eval", "eval()")}} where the bracket notation can be used instead.
For example, the following syntax is often seen in many scripts.
diff --git a/files/en-us/web/javascript/reference/operators/remainder_assignment/index.html b/files/en-us/web/javascript/reference/operators/remainder_assignment/index.html index 5fd9f11e8d74e69..fd8c7155546d71a 100644 --- a/files/en-us/web/javascript/reference/operators/remainder_assignment/index.html +++ b/files/en-us/web/javascript/reference/operators/remainder_assignment/index.html @@ -2,11 +2,11 @@ title: Remainder assignment (%=) slug: Web/JavaScript/Reference/Operators/Remainder_assignment tags: -- Assignment operator -- JavaScript -- Language feature -- Operator -- Reference + - Assignment operator + - JavaScript + - Language feature + - Operator + - Reference ---{{jsSidebar("Operators")}}@@ -53,7 +53,7 @@See also
a >> b
+a >> bDescription
@@ -83,7 +83,7 @@Browser compatibility
See also
"undefined"
const
variables (or using typeof
on a class
) in a
block before they are declared will throw a {{JSxRef("ReferenceError")}}. Block scoped
variables are in a "temporal
+ href="/en-US/docs/Web/JavaScript/Reference/Statements/let#the_temporal_dead_zone_and_typeof">temporal
dead zone" from the start of the block until the initialization is processed,
during which, it will throw an error if accessed.
diff --git a/files/en-us/web/javascript/reference/operators/unsigned_right_shift/index.html b/files/en-us/web/javascript/reference/operators/unsigned_right_shift/index.html
index 37635c7a0f863f1..50e5db5a43eb633 100644
--- a/files/en-us/web/javascript/reference/operators/unsigned_right_shift/index.html
+++ b/files/en-us/web/javascript/reference/operators/unsigned_right_shift/index.html
@@ -2,11 +2,11 @@
title: Unsigned right shift (>>>)
slug: Web/JavaScript/Reference/Operators/Unsigned_right_shift
tags:
-- Bitwise operator
-- JavaScript
-- Language feature
-- Operator
-- Reference
+ - Bitwise operator
+ - JavaScript
+ - Language feature
+ - Operator
+ - Reference
---
a >>> b
+a >>> bDescription
@@ -87,7 +87,7 @@Browser compatibility
See also
expression
{{optional_inline}}undefined
is returned instead.rv
{{optional_inline}}valueN
All the considerations about the "temporal
+ href="/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz">temporal
dead zone" apply to both {{jsxref("Statements/let", "let")}} and
const
.
The for...of
statement creates a loop iterating over iterable
+ href="/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol">iterable
objects, including: built-in {{jsxref("String")}}, {{jsxref("Array")}}, array-like
objects (e.g., {{jsxref("Functions/arguments", "arguments")}}
or {{domxref("NodeList")}}), {{jsxref("TypedArray")}}, {{jsxref("Map")}},
@@ -254,7 +254,7 @@
for..
properties
The for...of
statement iterates over values that the iterable
+ href="/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#iterables">iterable
object defines to be iterated over.
The following example shows the difference between a for...of
loop and a
@@ -291,7 +291,7 @@
for..
Every object will inherit the objCustom
property and every object that is
an {{jsxref("Array")}} will inherit the arrCustom
property since these
- properties have been added to {{jsxref("Object.prototype")}} and
+ properties have been added to {{jsxref("Object")}} and
{{jsxref("Array.prototype")}}, respectively. The object iterable
inherits
the properties objCustom
and arrCustom
because of inheritance and
@@ -331,7 +331,7 @@ Difference between for..
}
This loop iterates and logs values that iterable
, as an
- iterable
+ iterable
object, defines to be iterated over. The object's elements
3
, 5
, 7
are shown, but none of the object's
properties.
diff --git a/files/en-us/web/javascript/reference/statements/function_star_/index.html b/files/en-us/web/javascript/reference/statements/function_star_/index.html
index 16effa111fb7a40..4d2faaa5f1a80bf 100644
--- a/files/en-us/web/javascript/reference/statements/function_star_/index.html
+++ b/files/en-us/web/javascript/reference/statements/function_star_/index.html
@@ -2,12 +2,12 @@
title: function*
slug: Web/JavaScript/Reference/Statements/function*
tags:
-- ECMAScript 2015
-- Function
-- Iterator
-- JavaScript
-- Language feature
-- Statement
+ - ECMAScript 2015
+ - Function
+ - Iterator
+ - JavaScript
+ - Language feature
+ - Statement
---
{{jsSidebar("Statements")}}
@@ -268,7 +268,7 @@ See also
- {{jsxref("Function")}} object
- {{jsxref("Statements/function", "function")}} declaration
- {{jsxref("Operators/function", "function")}} expression
- - {{jsxref("Functions_and_function_scope", "Functions and function scope", "", 1)}}
+
- {{jsxref("Functions", "Functions and function scope", "", 1)}}
- Other web resources:
diff --git a/files/en-us/web/javascript/reference/statements/if...else/index.html b/files/en-us/web/javascript/reference/statements/if...else/index.html
index 0289aa2466995ee..f8cb76c813ce0da 100644
--- a/files/en-us/web/javascript/reference/statements/if...else/index.html
+++ b/files/en-us/web/javascript/reference/statements/if...else/index.html
@@ -2,12 +2,12 @@
title: if...else
slug: Web/JavaScript/Reference/Statements/if...else
tags:
-- JavaScript
-- Language feature
-- Reference
-- Statement
-- else
-- if
+ - JavaScript
+ - Language feature
+ - Reference
+ - Statement
+ - else
+ - if
---
{{jsSidebar("Statements")}}
@@ -34,7 +34,7 @@ Syntax
condition
- An expression
+ href="/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#expressions">expression
that is considered to be either {{Glossary("truthy")}} or {{Glossary("falsy")}}.
statement1
- Statement that is executed if condition is {{Glossary("truthy")}}. Can be
@@ -174,6 +174,6 @@
See also
- {{jsxref("Statements/block", "block")}}
- {{jsxref("Statements/switch", "switch")}}
- Conditional
+ href="/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator">Conditional
operator
let
is that the latter is initialized to a value only when a parser evaluates it (see below).
+ href="#temporal_dead_zone">parser evaluates it (see below)Just like {{jsxref("statements/const", "const", "Description")}} the let
does not create properties of the {{domxref("window")}} object when declared
diff --git a/files/en-us/web/javascript/reference/statements/return/index.html b/files/en-us/web/javascript/reference/statements/return/index.html
index 849249298e0e96f..9be51b6361cd683 100644
--- a/files/en-us/web/javascript/reference/statements/return/index.html
+++ b/files/en-us/web/javascript/reference/statements/return/index.html
@@ -2,9 +2,9 @@
title: return
slug: Web/JavaScript/Reference/Statements/return
tags:
-- JavaScript
-- Language feature
-- Statement
+ - JavaScript
+ - Language feature
+ - Statement
---
The return
statement is affected by automatic
+ href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion">automatic
semicolon insertion (ASI). No line terminator is allowed between the
return
keyword and the expression.
A switch
statement first evaluates its expression. It then looks for the
first case
clause whose expression evaluates to the same value as the
result of the input expression (using the strict
+ href="/en-US/docs/Web/JavaScript/Reference/Operators">strict
comparison, ===
) and transfers control to that clause, executing the
associated statements. (If multiple case
s match the provided value, the
first case
that matches is selected, even if the case
s are not
diff --git a/files/en-us/web/javascript/reference/statements/throw/index.html b/files/en-us/web/javascript/reference/statements/throw/index.html
index 23fc25bbf8d1b0b..06b45a67d901033 100644
--- a/files/en-us/web/javascript/reference/statements/throw/index.html
+++ b/files/en-us/web/javascript/reference/statements/throw/index.html
@@ -2,10 +2,10 @@
title: throw
slug: Web/JavaScript/Reference/Statements/throw
tags:
-- Exception
-- JavaScript
-- Language feature
-- Statement
+ - Exception
+ - JavaScript
+ - Language feature
+ - Statement
---
Also note that the throw
statement is affected by automatic
+ href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion">automatic
semicolon insertion (ASI) as no line terminator between the throw
keyword and the expression is allowed.
statement
{ ... }
) to group those statements.break
statement to stop a loop before condition evaluates
diff --git a/files/en-us/web/javascript/reference/statements/with/index.html b/files/en-us/web/javascript/reference/statements/with/index.html
index a0e0116ef08d2ee..d074303db4623f8 100644
--- a/files/en-us/web/javascript/reference/statements/with/index.html
+++ b/files/en-us/web/javascript/reference/statements/with/index.html
@@ -2,10 +2,10 @@
title: with
slug: Web/JavaScript/Reference/Statements/with
tags:
-- Deprecated
-- JavaScript
-- Language feature
-- Statement
+ - Deprecated
+ - JavaScript
+ - Language feature
+ - Statement
---
with
statement is not recommended, as it may
be the source of confusing bugs and compatibility issues. See the "Ambiguity Contra"
@@ -42,7 +42,7 @@ with
is not recommended, and is forbidden in
ECMAScript 5 strict
+ href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict
mode. The recommended alternative is to assign the object whose properties you
want to access to a temporary variable.Sometimes you'll see the default, non-strict mode referred to as "sloppy mode". This isn't an official term, but be aware of it, just in case.
JavaScript's strict mode, introduced in ECMAScript 5, is a way to opt in to a restricted variant of JavaScript, thereby implicitly opting-out of "sloppy mode". Strict mode isn't just a subset: it intentionally has different semantics from normal code. Browsers not supporting strict mode will run strict mode code with different behavior from browsers that do, so don't rely on strict mode without feature-testing for support for the relevant aspects of strict mode. Strict mode code and non-strict mode code can coexist, so scripts can opt into strict mode incrementally.
+JavaScript's strict mode, introduced in ECMAScript 5, is a way to opt in to a restricted variant of JavaScript, thereby implicitly opting-out of "sloppy mode". Strict mode isn't just a subset: it intentionally has different semantics from normal code. Browsers not supporting strict mode will run strict mode code with different behavior from browsers that do, so don't rely on strict mode without feature-testing for support for the relevant aspects of strict mode. Strict mode code and non-strict mode code can coexist, so scripts can opt into strict mode incrementally.
Strict mode makes several changes to normal JavaScript semantics:
@@ -33,7 +33,7 @@Strict mode applies to entire scripts or to individual functions. It doesn't apply to block statements enclosed in {}
braces; attempting to apply it to such contexts does nothing. eval
code, Function
code, event handler attributes, strings passed to WindowTimers.setTimeout()
, and related functions are entire scripts, and invoking strict mode in them works as expected.
Strict mode applies to entire scripts or to individual functions. It doesn't apply to block statements enclosed in {}
braces; attempting to apply it to such contexts does nothing. eval
code, Function
code, event handler attributes, strings passed to WindowTimers.setTimeout()
, and related functions are entire scripts, and invoking strict mode in them works as expected.
Sixth, strict mode in ECMAScript 2015 forbids setting properties on primitive values. Without strict mode, setting properties is ignored (no-op), with strict mode, however, a {{jsxref("TypeError")}} is thrown.
+Sixth, strict mode in ECMAScript 2015 forbids setting properties on primitive values. Without strict mode, setting properties is ignored (no-op), with strict mode, however, a {{jsxref("TypeError")}} is thrown.
(function() { 'use strict'; diff --git a/files/en-us/web/javascript/reference/strict_mode/transitioning_to_strict_mode/index.html b/files/en-us/web/javascript/reference/strict_mode/transitioning_to_strict_mode/index.html index d6d17cd17194771..7be110bd589cdb7 100644 --- a/files/en-us/web/javascript/reference/strict_mode/transitioning_to_strict_mode/index.html +++ b/files/en-us/web/javascript/reference/strict_mode/transitioning_to_strict_mode/index.html @@ -8,7 +8,7 @@ ---{{jsSidebar("More")}}-ECMAScript 5 introduced strict mode which is now implemented in all major browsers (including IE10). While making web browsers interpret code as strict is easy (just add
+'use strict';
at the top of your source code), transitioning an existing code base to strict mode requires a bit more work.ECMAScript 5 introduced strict mode which is now implemented in all major browsers (including IE10). While making web browsers interpret code as strict is easy (just add
'use strict';
at the top of your source code), transitioning an existing code base to strict mode requires a bit more work.This article aims at providing guidance for developers.
@@ -27,7 +27,7 @@Syntax errors
with
statementdelete
on a variable name delete myVariable
;eval
or arguments
as variable or function argument nameimplements
, interface
, let
, package
, private
, protected
, public
, static
, and yield
implements
, interface
, let
, package
, private
, protected
, public
, static
, and yield
if (a < b) { function f() {} }
The special raw
property, available on the first argument to the tag
function, allows you to access the raw strings as they were entered, without processing
escape
+ href="/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#using_special_characters_in_strings">escape
sequences.
function tag(strings) {