recursal/MDN huggingface dataset:
Left shift assignment (<<=)
===========================

The **left shift assignment (`<<=`)** operator performs left shift on the two operands and assigns the result to the left operand.

Try it
------

Syntax
------


```js
x <<= y
```

Description
-----------

`x <<= y` is equivalent to `x = x << y`, except that the expression `x` is only evaluated once.

Examples
--------

### Using left shift assignment


```js
let a = 5;
// 00000000000000000000000000000101

a <<= 2; // 20
// 00000000000000000000000000010100

let b = 5n;
b <<= 2n; // 20n
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-assignment-operators |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Assignment operators in the JS guide
* Left shift (`<<`)
Exponentiation assignment (\*\*=)
=================================

The \*\*exponentiation assignment (`**=`)\*\* operator performs exponentiation on the two operands and assigns the result to the left operand.

Try it
------

Syntax
------


```js
x \*\*= y
```

Description
-----------

`x **= y` is equivalent to `x = x ** y`, except that the expression `x` is only evaluated once.

Examples
--------

### Using exponentiation assignment


```js
let bar = 5;

bar \*\*= 2; // 25
bar \*\*= "foo"; // NaN

let foo = 3n;
foo \*\*= 2n; // 9n
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-assignment-operators |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Assignment operators in the JS guide
* Exponentiation (`**`)
Conditional (ternary) operator
==============================

 The **conditional (ternary) operator** is the only JavaScript operator that takes three operands:
 a condition followed by a question mark (`?`), then an expression to execute if the condition is truthy followed by a colon (`:`), and finally the expression to execute if the condition is falsy.
 This operator is frequently used as an alternative to an `if...else` statement.

Try it
------

Syntax
------


```js
condition ? exprIfTrue : exprIfFalse
```

### Parameters

`condition`

An expression whose value is used as a condition.

`exprIfTrue`

An expression which is executed if the `condition` evaluates to a truthy value (one which equals or can be converted to `true`).

`exprIfFalse`

An expression which is executed if the `condition` is falsy (that is, has a value which can be converted to `false`).

Description
-----------

 Besides `false`, possible falsy expressions are: `null`, `NaN`, `0`, the empty string (`""`), and `undefined`.
 If `condition` is any of these, the result of the conditional expression will be the result of executing the expression `exprIfFalse`.

Examples
--------

### A simple example


```js
const age = 26;
const beverage = age >= 21 ? "Beer" : "Juice";
console.log(beverage); // "Beer"
```

### Handling null values

One common usage is to handle a value that may be `null`:


```js
const greeting = (person) => {
  const name = person ? person.name : "stranger";
  return `Howdy, ${name}`;
};

console.log(greeting({ name: "Alice" })); // "Howdy, Alice"
console.log(greeting(null)); // "Howdy, stranger"
```

### Conditional chains

The ternary operator is right-associative, which means it can be "chained" in the following way, similar to an `if … else if … else if … else` chain:


```js
function example() {
  return condition1 ? value1
    : condition2 ? value2
    : condition3 ? value3
    : value4;
}
```


This is equivalent to the following `if...else` chain.


```js
function example() {
  if (condition1) {
    return value1;
  } else if (condition2) {
    return value2;
  } else if (condition3) {
    return value3;
  } else {
    return value4;
  }
}
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-conditional-operator |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `if...else`
* Nullish coalescing operator (`??`)
* Optional chaining (`?.`)
* Making decisions in your code — conditionals
* Expressions and operators guide
Division (/)
============

The **division (`/`)** operator produces the quotient of its operands where the left operand is the dividend and the right operand is the divisor.

Try it
------

Syntax
------


```js
x / y
```

Description
-----------

The `/` operator is overloaded for two types of operands: number and BigInt. It first coerces both operands to numeric values and tests the types of them. It performs BigInt division if both operands become BigInts; otherwise, it performs number division. A `TypeError` is thrown if one operand becomes a BigInt but the other becomes a number.

For BigInt division, the result is the quotient of the two operands truncated towards zero, and the remainder is discarded. A `RangeError` is thrown if the divisor `y` is `0n`. This is because number division by zero returns `Infinity` or `-Infinity`, but BigInt has no concept of infinity.

Examples
--------

### Basic division


```js
1 / 2; // 0.5

Math.floor(3 / 2); // 1

1.0 / 2.0; // 0.5

1n / 2n; // 0n
5n / 3n; // 1n
-1n / 3n; // 0n
1n / -3n; // 0n

2n / 2; // TypeError: Cannot mix BigInt and other types, use explicit conversions

// To do division with a BigInt and a non-BigInt, convert either operand
2n / BigInt(2); // 1n
Number(2n) / 2; // 1
```

### Division by zero


```js
2.0 / 0; // Infinity

2.0 / 0.0; // Infinity, because 0.0 === 0

2.0 / -0.0; // -Infinity

2n / 0n; // RangeError: Division by zero
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-multiplicative-operators |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Addition (`+`)
* Subtraction (`-`)
* Multiplication (`*`)
* Remainder (`%`)
* Exponentiation (`**`)
* Increment (`++`)
* Decrement (`--`)
* Unary negation (`-`)
* Unary plus (`+`)
Division assignment (/=)
========================

The **division assignment (`/=`)** operator performs division on the two operands and assigns the result to the left operand.

Try it
------

Syntax
------


```js
x /= y
```

Description
-----------

`x /= y` is equivalent to `x = x / y`, except that the expression `x` is only evaluated once.

Examples
--------

### Using division assignment


```js
let bar = 5;

bar /= 2; // 2.5
bar /= 2; // 1.25
bar /= 0; // Infinity
bar /= "foo"; // NaN

let foo = 3n;
foo /= 2n; // 1n
foo /= 2n; // 0n
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-assignment-operators |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Assignment operators in the JS guide
* Division (`/`)
Strict equality (===)
=====================

 The **strict equality (`===`)** operator checks whether its two operands are
 equal, returning a Boolean result. Unlike the equality operator,
 the strict equality operator always considers operands of different types to be
 different.

Try it
------

Syntax
------


```js
x === y
```

Description
-----------

The strict equality operators (`===` and `!==`) provide the IsStrictlyEqual semantic.

* If the operands are of different types, return `false`.
* If both operands are objects, return `true` only if they refer to the
 same object.
* If both operands are `null` or both operands are `undefined`,
 return `true`.
* If either operand is `NaN`, return `false`.
* Otherwise, compare the two operand's values:
    + Numbers must have the same numeric values. `+0` and `-0`
     are considered to be the same value.
    + Strings must have the same characters in the same order.
    + Booleans must be both `true` or both `false`.

 The most notable difference between this operator and the equality
 (`==`) operator is that if the operands are of different types, the
 `==` operator attempts to convert them to the same type before comparing.

Examples
--------

### Comparing operands of the same type


```js
"hello" === "hello"; // true
"hello" === "hola"; // false

3 === 3; // true
3 === 4; // false

true === true; // true
true === false; // false

null === null; // true
```

### Comparing operands of different types


```js
"3" === 3; // false
true === 1; // false
null === undefined; // false
3 === new Number(3); // false
```

### Comparing objects


```js
const object1 = {
  key: "value",
};

const object2 = {
  key: "value",
};

console.log(object1 === object2); // false
console.log(object1 === object1); // true
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-equality-operators |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Equality (`==`)
* Inequality (`!=`)
* Strict inequality (`!==`)
async function\* expression
===========================

The **`async function*`** keywords can be used to define an async generator function inside an expression.

You can also define async generator functions using the `async function*` declaration.

Try it
------

Syntax
------


```js
async function\* (param0) {
  statements
}
async function\* (param0, param1) {
  statements
}
async function\* (param0, param1, /\* …, \*/ paramN) {
  statements
}

async function\* name(param0) {
  statements
}
async function\* name(param0, param1) {
  statements
}
async function\* name(param0, param1, /\* …, \*/ paramN) {
  statements
}
```


**Note:** An expression statement cannot begin with the keywords `async function` to avoid ambiguity with an `async function*` declaration. The `async function` keywords only begin an expression when they appear in a context that cannot accept statements.

### Parameters

`name` Optional

The function name. Can be omitted, in which case the function is *anonymous*. The name is only local to the function body.

`paramN` Optional

The name of a formal parameter for the function. For the parameters' syntax, see the Functions reference.

`statements` Optional

The statements which comprise the body of the function.

Description
-----------

An `async function*` expression is very similar to, and has almost the same syntax as, an `async function*` declaration. The main difference between an `async function*` expression and an `async function*` declaration is the *function name*, which can be omitted in `async function*` expressions to create *anonymous* functions. An `async function*` expression can be used as an IIFE (Immediately Invoked Function Expression) which runs as soon as it is defined, allowing you to create an ad-hoc async iterable object. See also the chapter about functions for more information.

Examples
--------

### Using async function\* expression

The following example defines an unnamed asynchronous generator function and assigns it to `x`. The function yields the square of its argument:


```js
const x = async function\* (y) {
  yield Promise.resolve(y \* y);
};
x(6)
  .next()
  .then((res) => console.log(res.value)); // 36
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-async-generator-function-definitions |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Functions guide
* Functions
* `async function*`
* `AsyncGeneratorFunction`
* Iteration protocols
* `yield`
* `yield*`
Bitwise OR assignment (|=)
==========================

The **bitwise OR assignment (`|=`)** operator performs bitwise OR on the two operands and assigns the result to the left operand.

Try it
------

Syntax
------


```js
x |= y
```

Description
-----------

`x |= y` is equivalent to `x = x | y`, except that the expression `x` is only evaluated once.

Examples
--------

### Using bitwise OR assignment


```js
let a = 5;
a |= 2; // 7
// 5: 00000000000000000000000000000101
// 2: 00000000000000000000000000000010
// -----------------------------------
// 7: 00000000000000000000000000000111

let b = 5n;
b |= 2n; // 7n
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-assignment-operators |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Assignment operators in the JS guide
* Bitwise OR (`|`)
* Logical OR assignment (`||=`)
Bitwise XOR (^)
===============

The **bitwise XOR (`^`)** operator returns a number or BigInt whose binary representation has a `1` in each bit position for which the corresponding bits of either but not both operands are `1`.

Try it
------

Syntax
------


```js
x ^ y
```

Description
-----------

The `^` operator is overloaded for two types of operands: number and BigInt. For numbers, the operator returns a 32-bit integer. For BigInts, the operator returns a BigInt. It first coerces both operands to numeric values and tests the types of them. It performs BigInt XOR if both operands become BigInts; otherwise, it converts both operands to 32-bit integers and performs number bitwise XOR. A `TypeError` is thrown if one operand becomes a BigInt but the other becomes a number.

The operator operates on the operands' bit representations in two's complement. Each bit in the first operand is paired with the corresponding bit in the second operand: *first bit* to *first bit*, *second bit* to *second bit*, and so on. The operator is applied to each pair of bits, and the result is constructed bitwise.

The truth table for the XOR operation is:

| x | y | x XOR y |
| --- | --- | --- |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
```

     9 (base 10) = 00000000000000000000000000001001 (base 2)
    14 (base 10) = 00000000000000000000000000001110 (base 2)
                   --------------------------------
14 ^ 9 (base 10) = 00000000000000000000000000000111 (base 2) = 7 (base 10)
```


Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32-bit integer:
```

Before: 11100110111110100000000000000110000000000001
After:              10100000000000000110000000000001
```


For BigInts, there's no truncation. Conceptually, understand positive BigInts as having an infinite number of leading `0` bits, and negative BigInts having an infinite number of leading `1` bits.

Bitwise XORing any number `x` with `0` returns `x` converted to a 32-bit integer. Do not use `^ 0` to truncate numbers to integers; use `Math.trunc()` instead.

Examples
--------

### Using bitwise XOR


```js
// 9 (00000000000000000000000000001001)
// 14 (00000000000000000000000000001110)

14 ^ 9;
// 7 (00000000000000000000000000000111)

14n ^ 9n; // 7n
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # prod-BitwiseXORExpression |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Bitwise operators in the JS guide
* Bitwise XOR assignment (`^=`)
Strict inequality (!==)
=======================

 The **strict inequality (`!==`)** operator checks whether its two operands are
 not equal, returning a Boolean result. Unlike the inequality
 operator, the strict inequality operator always considers operands of different types to
 be different.

Try it
------

Syntax
------


```js
x !== y
```

Description
-----------

 The strict inequality operator checks whether its operands are not equal.
 It is the negation of the
 strict equality operator
 so the following two lines will always give the same result:


```js
x !== y;

!(x === y);
```


 For details of the comparison algorithm, see the page for the
 strict equality operator.

 Like the strict equality operator, the strict inequality operator will always consider
 operands of different types to be different:


```js
3 !== "3"; // true
```

Examples
--------

### Comparing operands of the same type


```js
"hello" !== "hello"; // false
"hello" !== "hola"; // true

3 !== 3; // false
3 !== 4; // true

true !== true; // false
true !== false; // true

null !== null; // false
```

### Comparing operands of different types


```js
"3" !== 3; // true
true !== 1; // true
null !== undefined; // true
```

### Comparing objects


```js
const object1 = {
  key: "value",
};

const object2 = {
  key: "value",
};

console.log(object1 !== object2); // true
console.log(object1 !== object1); // false
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-equality-operators |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Equality (`==`)
* Inequality (`!=`)
* Strict equality (`===`)
Bitwise NOT (~)
===============

The **bitwise NOT (`~`)** operator returns a number or BigInt whose binary representation has a `1` in each bit position for which the corresponding bit of the operand is `0`, and a `0` otherwise.

Try it
------

Syntax
------


```js
~x
```

Description
-----------

The `~` operator is overloaded for two types of operands: number and BigInt. For numbers, the operator returns a 32-bit integer. For BigInts, the operator returns a BigInt. It first coerces the operand to a numeric value and tests the type of it. It performs BigInt NOT if the operand becomes a BigInt; otherwise, it converts the operand to a 32-bit integer and performs number bitwise NOT.

The operator operates on the operands' bit representations in two's complement. The operator is applied to each bit, and the result is constructed bitwise.

The truth table for the NOT operation is:

| x | NOT x |
| --- | --- |
| 0 | 1 |
| 1 | 0 |
```

 9 (base 10) = 00000000000000000000000000001001 (base 2)
               --------------------------------
~9 (base 10) = 11111111111111111111111111110110 (base 2) = -10 (base 10)
```


Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32-bit integer:
```

Before: 11100110111110100000000000000110000000000001
After:              10100000000000000110000000000001
```


For BigInts, there's no truncation. Conceptually, understand positive BigInts as having an infinite number of leading `0` bits, and negative BigInts having an infinite number of leading `1` bits.

Bitwise NOTing any 32-bit integer `x` yields `-(x + 1)`. For example, `~-5` yields `4`.

Bitwise NOTing any number `x` twice returns `x` converted to a 32-bit integer. Do not use `~~x` to truncate numbers to integers; use `Math.trunc()` instead. Due to using 32-bit representation for numbers, both `~-1` and `~4294967295` (232 - 1) result in `0`.

Examples
--------

### Using bitwise NOT


```js
~0; // -1
~-1; // 0
~1; // -2

~0n; // -1n
~4294967295n; // -4294967296n
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-bitwise-not-operator |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Bitwise operators in the JS guide
Addition assignment (+=)
========================

The **addition assignment (`+=`)** operator performs addition (which is either numeric addition or string concatenation) on the two operands and assigns the result to the left operand.

Try it
------

Syntax
------


```js
x += y
```

Description
-----------

`x += y` is equivalent to `x = x + y`, except that the expression `x` is only evaluated once.

Examples
--------

### Using addition assignment


```js
let baz = true;

// Boolean + Number -> addition
baz += 1; // 2

// Number + Boolean -> addition
baz += false; // 2
```



```js
let foo = "foo";

// String + Boolean -> concatenation
foo += false; // "foofalse"

// String + String -> concatenation
foo += "bar"; // "foofalsebar"
```



```js
let bar = 5;

// Number + Number -> addition
bar += 2; // 7

// Number + String -> concatenation
bar += "foo"; // "7foo"
```



```js
let x = 1n;

// BigInt + BigInt -> addition
x += 2n; // 3n

// BigInt + Number -> throws TypeError
x += 1; // TypeError: Cannot mix BigInt and other types, use explicit conversions
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-assignment-operators |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Assignment operators in the JS guide
* Addition (`+`)
Bitwise OR (|)
==============

The **bitwise OR (`|`)** operator returns a number or BigInt whose binary representation has a `1` in each bit position for which the corresponding bits of either or both operands are `1`.

Try it
------

Syntax
------


```js
x | y
```

Description
-----------

The `|` operator is overloaded for two types of operands: number and BigInt. For numbers, the operator returns a 32-bit integer. For BigInts, the operator returns a BigInt. It first coerces both operands to numeric values and tests the types of them. It performs BigInt OR if both operands become BigInts; otherwise, it converts both operands to 32-bit integers and performs number bitwise OR. A `TypeError` is thrown if one operand becomes a BigInt but the other becomes a number.

The operator operates on the operands' bit representations in two's complement. Each bit in the first operand is paired with the corresponding bit in the second operand: *first bit* to *first bit*, *second bit* to *second bit*, and so on. The operator is applied to each pair of bits, and the result is constructed bitwise.

The truth table for the OR operation is:

| x | y | x OR y |
| --- | --- | --- |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
```

     9 (base 10) = 00000000000000000000000000001001 (base 2)
    14 (base 10) = 00000000000000000000000000001110 (base 2)
                   --------------------------------
14 | 9 (base 10) = 00000000000000000000000000001111 (base 2) = 15 (base 10)
```


Numbers with more than 32 bits get their most significant bits discarded. For example, the following integer with more than 32 bits will be converted to a 32-bit integer:
```

Before: 11100110111110100000000000000110000000000001
After:              10100000000000000110000000000001
```


For BigInts, there's no truncation. Conceptually, understand positive BigInts as having an infinite number of leading `0` bits, and negative BigInts having an infinite number of leading `1` bits.

Bitwise ORing any number `x` with `0` returns `x` converted to a 32-bit integer. Do not use `| 0` to truncate numbers to integers; use `Math.trunc()` instead.

Examples
--------

### Using bitwise OR


```js
// 9 (00000000000000000000000000001001)
// 14 (00000000000000000000000000001110)

14 | 9;
// 15 (00000000000000000000000000001111)

14n | 9n; // 15n
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # prod-BitwiseORExpression |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Bitwise operators in the JS guide
* Bitwise OR assignment (`|=`)