recursal/MDN huggingface dataset:
Unary plus (+)
==============

 The **unary plus (`+`)** operator precedes its operand and evaluates to its
 operand but attempts to convert it into a number, if it isn't already.

Try it
------

Syntax
------


```js
+x
```

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

Although unary negation (`-`) also can convert non-numbers, unary plus is the fastest and preferred way of converting something into a number, because it does not perform any other operations on the number.

Unary plus does the exact same steps as normal number coercion used by most built-in methods expecting numbers. It can convert string representations of integers and floats, as well as the non-string values `true`, `false`, and `null`. Integers in both decimal and hexadecimal (`0x`-prefixed) formats are supported. Negative numbers are supported (though not for hex). If it cannot parse a particular value, it will evaluate to `NaN`. Unlike other arithmetic operators, which work with both numbers and BigInts, using the `+` operator on BigInt values throws a `TypeError`.

Examples
--------

### Usage with numbers


```js
const x = 1;
const y = -1;

console.log(+x);
// 1
console.log(+y);
// -1
```

### Usage with non-numbers


```js
+true  // 1
+false // 0
+null  // 0
+[]    // 0
+function (val) { return val; } // NaN
+1n    // throws TypeError: Cannot convert BigInt value to number
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-unary-plus-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 negation (`-`)
async function expression
=========================

Baseline Widely available
-------------------------

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2017.

* Learn more
* See full compatibility
* Report feedback
The **`async function`** keywords can be used to define an async function inside an expression.

You can also define async functions using the `async function` declaration or the arrow syntax.

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 mimic top-level await. See also the chapter about functions for more information.

Examples
--------

### Using async function expression


```js
function resolveAfter2Seconds(x) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(x);
    }, 2000);
  });
}

// async function expression assigned to a variable
const add = async function (x) {
  const a = await resolveAfter2Seconds(20);
  const b = await resolveAfter2Seconds(30);
  return x + a + b;
};

add(10).then((v) => {
  console.log(v); // prints 60 after 4 seconds.
});

// async function expression used as an IIFE
(async function (x) {
  const p1 = resolveAfter2Seconds(20);
  const p2 = resolveAfter2Seconds(30);
  return x + (await p1) + (await p2);
})(10).then((v) => {
  console.log(v); // prints 60 after 2 seconds.
});
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-async-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`
* `AsyncFunction`
* `await`
Subtraction assignment (-=)
===========================

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


```js
let bar = 5;

bar -= 2; // 3
bar -= "foo"; // NaN

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

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
* Subtraction (`-`)
Remainder (%)
=============

The **remainder (`%`)** operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend.

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

For the operation `n % d`, `n` is called the dividend and `d` is called the divisor. The operation returns `NaN` if one of the operands is `NaN`, `n` is ±Infinity, or if `d` is ±0. Otherwise, if `d` is ±Infinity or if `n` is ±0, the dividend `n` is returned.

When both operands are non-zero and finite, the remainder `r` is calculated as `r := n - d * q` where `q` is the integer such that `r` has the same sign as the dividend `n` while being as close to 0 as possible.

Note that while in most languages, '%' is a remainder operator, in some (e.g. Python, Perl) it is a modulo operator. Modulo is defined as `k := n - d * q` where `q` is the integer such that `k` has the same sign as the divisor `d` while being as close to 0 as possible. For two values of the same sign, the two are equivalent, but when the operands are of different signs, the modulo result always has the same sign as the *divisor*, while the remainder has the same sign as the *dividend*, which can make them differ by one unit of `d`. To obtain a modulo in JavaScript, in place of `n % d`, use `((n % d) + d) % d`. In JavaScript, the modulo operation (which doesn't have a dedicated operator) is used to normalize the second operand of bitwise shift operators (`<<`, `>>`, etc.), making the offset always a positive value.

For BigInt division, a `RangeError` is thrown if the divisor `y` is `0n`. This is because number remainder by zero returns `NaN`, but BigInt has no concept of `NaN`.

Examples
--------

### Remainder with positive dividend


```js
13 % 5; // 3
1 % -2; // 1
1 % 2; // 1
2 % 3; // 2
5.5 % 2; // 1.5

3n % 2n; // 1n
```

### Remainder with negative dividend


```js
-13 % 5; // -3
-1 % 2; // -1
-4 % 2; // -0

-3n % 2n; // -1n
```

### Remainder with NaN


```js
NaN % 2; // NaN
```

### Remainder with Infinity


```js
Infinity % 2; // NaN
Infinity % 0; // NaN
Infinity % Infinity; // NaN
2 % Infinity; // 2
0 % Infinity; // 0
```

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 (`/`)
* Multiplication (`*`)
* Exponentiation (`**`)
* Increment (`++`)
* Decrement (`--`)
* Unary negation (`-`)
* Unary plus (`+`)
* Remainder operator vs. modulo operator by Dr. Axel Rauschmayer (2019)
Right shift assignment (>>=)
============================

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


```js
let a = 5; // (00000000000000000000000000000101)
a >>= 2; // 1 (00000000000000000000000000000001)

let b = -5; // (-00000000000000000000000000000101)
b >>= 2; // -2 (-00000000000000000000000000000010)

let c = 5n;
c >>= 2n; // 1n
```

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
* Right shift (`>>`)
Nullish coalescing assignment (??=)
===================================

The **nullish coalescing assignment (`??=`)** operator, also known as the **logical nullish assignment** operator, only evaluates the right operand and assigns to the left if the left operand is nullish (`null` or `undefined`).

Try it
------

Syntax
------


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

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

Nullish coalescing 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 nullish, due to short-circuiting of the nullish coalescing 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 nullish, `y` is not evaluated at all.


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

Examples
--------

### Using nullish coalescing assignment

You can use the nullish coalescing assignment operator to apply default values to object properties. Compared to using destructuring and default values, `??=` also applies the default value if the property has value `null`.


```js
function config(options) {
  options.duration ??= 100;
  options.speed ??= 25;
  return options;
}

config({ duration: 125 }); // { duration: 125, speed: 25 }
config({}); // { duration: 100, speed: 25 }
```

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

* Nullish coalescing operator (`??`)
* Nullish
* Truthy
* Falsy
Bitwise XOR assignment (^=)
===========================

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


```js
let a = 5; // (00000000000000000000000000000101)
a ^= 3; // (00000000000000000000000000000011)

console.log(a); // 6 (00000000000000000000000000000110)

let b = 5; // (00000000000000000000000000000101)
b ^= 0; // (00000000000000000000000000000000)

console.log(b); // 5 (00000000000000000000000000000101)

let c = 5n;
c ^= 3n;
console.log(c); // 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
* Bitwise XOR (`^`)
Unsigned right shift assignment (>>>=)
======================================

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


```js
let a = 5; // (00000000000000000000000000000101)
a >>>= 2; // 1 (00000000000000000000000000000001)

let b = -5; // (-00000000000000000000000000000101)
b >>>= 2; // 1073741822 (00111111111111111111111111111110)

let c = 5n;
c >>>= 2n; // 1n
```

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
* Unsigned right shift (`>>>`)
Remainder assignment (%=)
=========================

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


```js
let bar = 5;

bar %= 2; // 1
bar %= "foo"; // NaN
bar %= 0; // NaN

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

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
* Remainder (`%`)
Greater than (>)
================

 The **greater than (`>`)** operator returns `true` if the left
 operand is greater than 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, except the two operands are swapped. `x > y` is generally equivalent to `y < x`, except that `x > y` coerces `x` to a primitive before `y`, while `y < x` coerces `y` to a primitive before `x`. Because coercion may have side effects, the order of the operands may matter.

Examples
--------

### String to string comparison


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

### String to number comparison


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

"hello" > 5; // false
5 > "hello"; // false

"5" > 3n; // true
"3" > 5n; // false
```

### Number to Number comparison


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

### Number to BigInt comparison


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

### Comparing Boolean, null, undefined, NaN


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

true > 0; // true
true > 1; // false

null > 0; // false
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 or equal (`>=`)
* Less than (`<`)
* Less than or equal (`<=`)
class expression
================

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

You can also define classes using the `class` declaration.

Try it
------

Syntax
------


```js
class {
  // class body
}
class name {
  // class body
}
```


**Note:** An expression statement cannot begin with the keyword `class` to avoid ambiguity with a `class` declaration. The `class` keyword only begins an expression when it appears in a context that cannot accept statements.

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

A `class` expression is very similar to, and has almost the same syntax as, a `class` declaration. As with `class` declarations, the body of a `class` expression is executed in strict mode. The main difference between a `class` expression and a `class` declaration is the *class name*, which can be omitted in `class` expressions to create *anonymous* classes. Class expressions allow you to redefine classes, while redeclaring a class using `class` declarations throws a `SyntaxError`. See also the chapter about classes for more information.

Examples
--------

### A simple class expression

This is just a simple anonymous class expression which you can refer to using the variable `Foo`.


```js
const Foo = class {
  constructor() {}
  bar() {
    return "Hello World!";
  }
};

const instance = new Foo();
instance.bar(); // "Hello World!"
Foo.name; // "Foo"
```

### Named class expressions

If you want to refer to the current class inside the class body, you can create a *named class expression*. The name is only visible within the scope of the class expression itself.


```js
const Foo = class NamedFoo {
  constructor() {}
  whoIsThere() {
    return NamedFoo.name;
  }
};
const bar = new Foo();
bar.whoIsThere(); // "NamedFoo"
NamedFoo.name; // ReferenceError: NamedFoo is not defined
Foo.name; // "NamedFoo"
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-class-definitions |

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

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

See also
--------

* `class`
* Classes
null
====

 The **`null`** value represents the intentional absence of any object value. It
 is one of JavaScript's primitive values and
 is treated as falsy for boolean operations.

Try it
------

Syntax
------


```js
null
```

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

 The value `null` is written with a literal: `null`.
 `null` is not an identifier for a property of the global object, like
 `undefined` can be. Instead,
 `null` expresses a lack of identification, indicating that a variable points
 to no object. In APIs, `null` is often retrieved in a place where an object
 can be expected but no object is relevant.


```js
// foo does not exist. It is not defined and has never been initialized:
foo; //ReferenceError: foo is not defined
```



```js
// foo is known to exist now but it has no type or value:
const foo = null;
foo; //null
```

Examples
--------

### Difference between `null` and `undefined`

 When checking for `null` or `undefined`, beware of the differences between equality (==) and identity (===) operators, as the former performs
 type-conversion.


```js
typeof null; // "object" (not "null" for legacy reasons)
typeof undefined; // "undefined"
null === undefined; // false
null == undefined; // true
null === null; // true
null == null; // true
!null; // true
Number.isNaN(1 + null); // false
Number.isNaN(1 + undefined); // true
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-null-value |

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

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

See also
--------

* `undefined`
* `NaN`
* `void`
Inequality (!=)
===============

 The **inequality (`!=`)** operator checks whether its two operands are not
 equal, returning a Boolean result.
 Unlike the strict inequality operator,
 it attempts to convert and compare operands that are of different types.

Try it
------

Syntax
------


```js
x != y
```

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

 The inequality operator checks whether its operands are not equal. It is the negation
 of the 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 equality operator.

 Like the equality operator, the inequality operator will attempt to convert and compare
 operands of different types:


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


 To prevent this, and require that different types are considered to be different, use
 the strict inequality operator instead:


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

Examples
--------

### Comparison with no type conversion


```js
1 != 2; // true
"hello" != "hola"; // true

1 != 1; // false
"hello" != "hello"; // false
```

### Comparison with type conversion


```js
"1" != 1; // false
1 != "1"; // false
0 != false; // false
0 != null; // true
0 != undefined; // true
0 != !!null; // false, look at Logical NOT operator
0 != !!undefined; // false, look at Logical NOT operator
null != undefined; // false

const number1 = new Number(3);
const number2 = new Number(3);
number1 != 3; // false
number1 != number2; // true
```

### Comparison of 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 (`==`)
* Strict equality (`===`)
* Strict inequality (`!==`)
Logical AND assignment (&&=)
============================

The **logical AND assignment (`&&=`)** operator only evaluates the right operand and assigns to the left if the left operand is truthy.

Try it
------

Syntax
------


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

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

Logical AND 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 truthy, due to short-circuiting of the logical AND operator. For example, the following does not throw an error, despite `x` being `const`:


```js
const x = 0;
x &&= 2;
```


Neither would the following trigger the setter:


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

x.value &&= 2;
```


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


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

Examples
--------

### Using logical AND assignment


```js
let x = 0;
let y = 1;

x &&= 0; // 0
x &&= 1; // 0
y &&= 1; // 1
y &&= 0; // 0
```

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 AND (`&&`)
* Nullish coalescing operator (`??`)
* Bitwise AND assignment (`&=`)
* Truthy
* Falsy