recursal/MDN huggingface dataset:
Greater than or equal (>=)
==========================

 The **greater than or equal (`>=`)** operator returns `true` if
 the left operand is greater than or equal to the right operand, and `false`
 otherwise.

Try it
------

Syntax
------


```js
x >= y
```

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

The operands are compared using the same algorithm as the Less than operator, with the result negated. `x >= y` is generally equivalent to `!(x < y)`, except for two cases where `x >= y` and `x < y` are both `false`:

* If one of the operands gets converted to a BigInt, while the other gets converted to a string that cannot be converted to a BigInt value (it throws a syntax error when passed to `BigInt()`).
* If one of the operands gets converted to `NaN`. (For example, strings that cannot be converted to numbers, or `undefined`.)

`x >= y` is generally equivalent to `x > y || x == y`, except for a few cases:

* When one of `x` or `y` is `null`, and the other is something that's not `null` and becomes 0 when coerced to numeric (including `0`, `0n`, `false`, `""`, `"0"`, `new Date(0)`, etc.): `x >= y` is `true`, while `x > y || x == y` is `false`.
* When one of `x` or `y` is `undefined`, and the other is one of `null` or `undefined`: `x >= y` is `false`, while `x == y` is `true`.
* When `x` and `y` are the same object that becomes `NaN` after the first step of Less than (such as `new Date(NaN)`): `x >= y` is `false`, while `x == y` is `true`.
* When `x` and `y` are different objects that become the same value after the first step of Less than: `x >= y` is `true`, while `x > y || x == y` is `false`.
Examples
--------

### String to string comparison


```js
"a" >= "b"; // false
"a" >= "a"; // true
"a" >= "3"; // true
```

### String to number comparison


```js
"5" >= 3; // true
"3" >= 3; // true
"3" >= 5; // false

"hello" >= 5; // false
5 >= "hello"; // false
```

### Number to Number comparison


```js
5 >= 3; // true
3 >= 3; // true
3 >= 5; // false
```

### Number to BigInt comparison


```js
5n >= 3; // true
3 >= 3n; // true
3 >= 5n; // false
```

### Comparing Boolean, null, undefined, NaN


```js
true >= false; // true
true >= true; // true
false >= true; // false

true >= 0; // true
true >= 1; // true

null >= 0; // true
1 >= null; // true

undefined >= 3; // false
3 >= undefined; // false

3 >= NaN; // false
NaN >= 3; // false
```

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

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

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

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

See also
--------

* Greater than (`>`)
* Less than (`<`)
* Less than or equal (`<=`)
Multiplication assignment (\*=)
===============================

The **multiplication assignment (`*=`)** operator performs multiplication 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 multiplication assignment


```js
let bar = 5;

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

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

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
* Multiplication (`*`)
Logical NOT (!)
===============

 The **logical NOT (`!`)** (logical complement, negation) operator takes truth to
 falsity and vice versa. It is typically used with boolean (logical)
 values. When used with non-Boolean values, it returns `false` if its single
 operand can be converted to `true`; otherwise, returns `true`.

Try it
------

Syntax
------


```js
!x
```

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

 Returns `false` if its single operand can be converted to `true`;
 otherwise, returns `true`.

 If a value can be converted to `true`, the value is so-called
 truthy. If a value can be converted to `false`, the value is
 so-called falsy.

Examples of expressions that can be converted to false are:

* `null`;
* `NaN`;
* `0`;
* empty string (`""` or `''` or ````);
* `undefined`.

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. To explicitly convert its return value (or any expression in general) to the corresponding boolean value, use a double NOT operator (`!!`) or the `Boolean` constructor.

Examples
--------

### Using NOT

The following code shows examples of the `!` (logical NOT) operator.


```js
!true; // !t returns false
!false; // !f returns true
!""; // !f returns true
!"Cat"; // !t returns false
```

### Double NOT (`!!`)

 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.
 The conversion is based on the "truthyness" or "falsyness" of the value (see
 truthy and falsy).

The same conversion can be done through the `Boolean()` function.


```js
!!true; // !!truthy returns true
!!{}; // !!truthy returns true: any object is truthy...
!!new Boolean(false); // ...even Boolean objects with a false .valueOf()!
!!false; // !!falsy returns false
!!""; // !!falsy returns false
!!Boolean(false); // !!falsy returns false
```

### Converting between NOTs

The following operation involving **booleans**:


```js
!!bCondition
```


is always equal to:


```js
bCondition
```

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

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

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

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

See also
--------

* `Boolean`
* Truthy
* Falsy
Logical OR assignment (||=)
===========================

The **logical OR assignment (`||=`)** operator only evaluates the right operand and assigns to the left if the left operand is falsy.

Try it
------

Syntax
------


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

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

Logical OR assignment *short-circuits*, meaning that `x ||= y` is equivalent to `x || (x = y)`, except that the expression `x` is only evaluated once.

No assignment is performed if the left-hand side is not falsy, due to short-circuiting of the logical OR operator. For example, the following does not throw an error, despite `x` being `const`:


```js
const x = 1;
x ||= 2;
```


Neither would the following trigger the setter:


```js
const x = {
  get value() {
    return 1;
  },
  set value(v) {
    console.log("Setter called");
  },
};

x.value ||= 2;
```


In fact, if `x` is not falsy, `y` is not evaluated at all.


```js
const x = 1;
x ||= console.log("y evaluated");
// Logs nothing
```

Examples
--------

### Setting default content

If the "lyrics" element is empty, display a default value:


```js
document.getElementById("lyrics").textContent ||= "No lyrics.";
```


Here the short-circuit is especially beneficial, since the element will not be updated unnecessarily and won't cause unwanted side-effects such as additional parsing or rendering work, or loss of focus, etc.

 Note: Pay attention to the value returned by the API you're checking against. If an empty string is returned (a falsy value), `||=` must be used, so that "No lyrics." is displayed instead of a blank space. However, if the API returns `null` or
 `undefined` in case of blank content, `??=` should be used instead.

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

* Logical OR (`||`)
* Nullish coalescing operator (`??`)
* Bitwise OR assignment (`|=`)
* Truthy
* Falsy
Multiplication (\*)
===================

The **multiplication (`*`)** operator produces the product of the operands.

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 multiplication if both operands become BigInts; otherwise, it performs number multiplication. A `TypeError` is thrown if one operand becomes a BigInt but the other becomes a number.

Examples
--------

### Multiplication using numbers


```js
2 \* 2; // 4
-2 \* 2; // -4
```

### Multiplication with Infinity


```js
Infinity \* 0; // NaN
Infinity \* Infinity; // Infinity
```

### Multiplication with non-numbers


```js
"foo" \* 2; // NaN
"2" \* 2; // 4
```

### Multiplication using BigInts


```js
2n \* 2n; // 4n
-2n \* 2n; // -4n

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

// To multiply a BigInt with a non-BigInt, convert either operand
2n \* BigInt(2); // 4n
Number(2n) \* 2; // 4
```

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 (`-`)
* Division (`/`)
* Remainder (`%`)
* Exponentiation (`**`)
* Increment (`++`)
* Decrement (`--`)
* Unary negation (`-`)
* Unary plus (`+`)
Bitwise AND (&)
===============

The **bitwise AND (`&`)** operator returns a number or BigInt whose binary representation has a `1` in each bit position for which the corresponding bits of 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 AND if both operands become BigInts; otherwise, it converts both operands to 32-bit integers and performs number bitwise AND. 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 AND operation is:

| x | y | x AND y |
| --- | --- | --- |
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
```

     9 (base 10) = 00000000000000000000000000001001 (base 2)
    14 (base 10) = 00000000000000000000000000001110 (base 2)
                   --------------------------------
14 & 9 (base 10) = 00000000000000000000000000001000 (base 2) = 8 (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 ANDing any number `x` with `-1` returns `x` converted to a 32-bit integer. Do not use `& -1` to truncate numbers to integers; use `Math.trunc()` instead.

Examples
--------

### Using bitwise AND


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

14 & 9;
// 8 (00000000000000000000000000001000)

14n & 9n; // 8n
```

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

| Specification |
| --- |
| ECMAScript Language Specification # prod-BitwiseANDExpression |

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 AND assignment (`&=`)
Addition (+)
============

The **addition (`+`)** operator produces the sum of numeric operands or string concatenation.

Try it
------

Syntax
------


```js
x + y
```

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

The `+` operator is overloaded for two distinct operations: numeric addition and string concatenation. When evaluating, it first coerces both operands to primitives. Then, the two operands' types are tested:

* If one side is a string, the other operand is also converted to a string and they are concatenated.
* If they are both BigInts, BigInt addition is performed. If one side is a BigInt but the other is not, a `TypeError` is thrown.
* Otherwise, both sides are converted to numbers, and numeric addition is performed.

String concatenation is often thought to be equivalent with template literals or `String.prototype.concat()`, but they are not. Addition coerces the expression to a *primitive*, which calls `valueOf()` in priority; on the other hand, template literals and `concat()` coerce the expression to a *string*, which calls `toString()` in priority. If the expression has a `@@toPrimitive` method, string concatenation calls it with `"default"` as hint, while template literals use `"string"`. This is important for objects that have different string and primitive representations — such as Temporal, whose `valueOf()` method throws.


```js
const t = Temporal.Now.instant();
"" + t; // Throws TypeError
`${t}`; // '2022-07-31T04:48:56.113918308Z'
"".concat(t); // '2022-07-31T04:48:56.113918308Z'
```


You are advised to not use `"" + x` to perform string coercion.

Examples
--------

### Number addition


```js
// Number + Number -> addition
1 + 2; // 3

// Boolean + Number -> addition
true + 1; // 2

// Boolean + Boolean -> addition
false + false; // 0
```

### BigInt addition


```js
// BigInt + BigInt -> addition
1n + 2n; // 3n

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

// To add a BigInt to a non-BigInt, convert either operand
1n + BigInt(2); // 3n
Number(1n) + 2; // 3
```

### String concatenation


```js
// String + String -> concatenation
"foo" + "bar"; // "foobar"

// Number + String -> concatenation
5 + "foo"; // "5foo"

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

// String + Number -> concatenation
"2" + 2; // "22"
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-addition-operator-plus |

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

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

See also
--------

* Subtraction (`-`)
* Division (`/`)
* Multiplication (`*`)
* Remainder (`%`)
* Exponentiation (`**`)
* Increment (`++`)
* Decrement (`--`)
* Unary negation (`-`)
* Unary plus (`+`)
function\* expression
=====================

The **`function*`** keyword can be used to define a generator function inside an expression.

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

Try it
------

Syntax
------


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

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


**Note:** An expression statement cannot begin with the keyword `function` to avoid ambiguity with a `function*` declaration. The `function` keyword only begins an expression when it appears 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
-----------

A `function*` expression is very similar to, and has almost the same syntax as, a `function*` declaration. The main difference between a `function*` expression and a `function*` declaration is the *function name*, which can be omitted in `function*` expressions to create *anonymous* functions. A `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 iterable iterator object. See also the chapter about functions for more information.

Examples
--------

### Using function\* expression

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


```js
const x = function\* (y) {
  yield y \* y;
};
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-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
* `function*`
* `GeneratorFunction`
* Iteration protocols
* `yield`
* `yield*`
Subtraction (-)
===============

The **subtraction (`-`)** operator subtracts the two operands, producing their difference.

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 subtraction if both operands become BigInts; otherwise, it performs number subtraction. A `TypeError` is thrown if one operand becomes a BigInt but the other becomes a number.

Examples
--------

### Subtraction with numbers


```js
// Number - Number -> subtraction
5 - 3; // 2

// Number - Number -> subtraction
3 - 5; // -2
```

### Subtraction with non-numbers


```js
// String - Number -> subtraction
"foo" - 3; // NaN; "foo" is converted to the number NaN

// Number - String -> subtraction
5 - "3"; // 2; "3" is converted to the number 3
```

### Subtraction with BigInts


```js
// BigInt - BigInt -> subtraction
2n - 1n; // 1n
```


You cannot mix BigInt and number operands in subtraction.


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

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-subtraction-operator-minus |

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

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

See also
--------

* Addition (`+`)
* Division (`/`)
* Multiplication (`*`)
* Remainder (`%`)
* Exponentiation (`**`)
* Increment (`++`)
* Decrement (`--`)
* Unary negation (`-`)
* Unary plus (`+`)
Left shift (<<)
===============

The **left shift (`<<`)** operator returns a number or BigInt whose binary representation is the first operand shifted by the specified number of bits to the left. Excess bits shifted off to the left are discarded, and zero bits are shifted in from the right.

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 left shift if both operands become BigInts; otherwise, it converts both operands to 32-bit integers and performs number left shift. A `TypeError` is thrown if one operand becomes a BigInt but the other becomes a number.

The operator operates on the left operand's bit representation in two's complement. For example, `9 << 2` yields 36:
```

     9 (base 10): 00000000000000000000000000001001 (base 2)
                  --------------------------------
9 << 2 (base 10): 00000000000000000000000000100100 (base 2) = 36 (base 10)
```


Bitwise a 32-bit integer `x` to the left by `y` bits yields `x * 2 ** y`. So for example, `9 << 3` is equivalent to `9 * (2 ** 3) = 9 * (8) = 72`.

If the left operand is a number with more than 32 bits, it will get the 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
```


The right operand will be converted to an unsigned 32-bit integer and then taken modulo 32, so the actual shift offset will always be a positive integer between 0 and 31, inclusive. For example, `100 << 32` is the same as `100 << 0` (and produces `100`) because 32 modulo 32 is 0.

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.

Left shifting any number `x` by `0` returns `x` converted to a 32-bit integer. Do not use `<< 0` to truncate numbers to integers; use `Math.trunc()` instead.

Examples
--------

### Using left shift


```js
9 << 3; // 72

// 9 \* (2 \*\* 3) = 9 \* (8) = 72

9n << 3n; // 72n
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-left-shift-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
* Left shift assignment (`<<=`)
Unary negation (-)
==================

The **unary negation (`-`)** operator precedes its operand and negates it.

Try it
------

Syntax
------


```js
-x
```

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

The `-` operator is overloaded for two types of operands: number and BigInt. It first coerces the operand to a numeric value and tests the type of it. It performs BigInt negation if the operand becomes a BigInt; otherwise, it performs number negation.

Examples
--------

### Negating numbers


```js
const x = 3;
const y = -x;
// y is -3; x is 3
```

### Negating non-numbers

The unary negation operator can convert a non-number into a number.


```js
const x = "4";
const y = -x;

// y is -4
```


BigInts can be negated using the unary negation operator.


```js
const x = 4n;
const y = -x;

// y is -4n
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-unary-minus-operator |

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

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

See also
--------

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