recursal/MDN huggingface dataset:
class
=====

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

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

* Learn more
* See full compatibility
* Report feedback
The **`class`** declaration creates a binding of a new class to a given name.

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

Try it
------

Syntax
------


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

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

The class body of a class declaration is executed in strict mode. The `class` declaration is very similar to `let`:

* `class` declarations are scoped to blocks as well as functions.
* `class` declarations can only be accessed after the place of declaration is reached (see temporal dead zone). For this reason, `class` declarations are commonly regarded as non-hoisted (unlike function declarations).
* `class` declarations do not create properties on `globalThis` when declared at the top level of a script (unlike function declarations).
* `class` declarations cannot be redeclared by any other declaration in the same scope.

Outside the class body, `class` declarations can be re-assigned like `let`, but you should avoid doing so. Within the class body, the binding is constant like `const`.


```js
class Foo {
  static {
    Foo = 1; // TypeError: Assignment to constant variable.
  }
}

class Foo2 {
  bar = (Foo2 = 1); // TypeError: Assignment to constant variable.
}

class Foo3 {}
Foo3 = 1;
console.log(Foo3); // 1
```

Examples
--------

### A simple class declaration

In the following example, we first define a class named `Rectangle`, then extend it to create a class named `FilledRectangle`.

Note that `super()`, used in the `constructor`, can only be used in constructors, and *must* be called *before* the `this` keyword can be used.


```js
class Rectangle {
  constructor(height, width) {
    this.name = "Rectangle";
    this.height = height;
    this.width = width;
  }
}

class FilledRectangle extends Rectangle {
  constructor(height, width, color) {
    super(height, width);
    this.name = "Filled rectangle";
    this.color = color;
  }
}
```

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

* `function`
* `class` expression
* Classes
do...while
==========

 The **`do...while`** statement creates a loop that executes a
 specified statement until the test condition evaluates to false. The condition is
 evaluated after executing the statement, resulting in the specified statement executing
 at least once.

Try it
------

Syntax
------


```js
do
  statement
while (condition);
```


`statement`

 A statement that is executed at least once and is re-executed each time the
 condition evaluates to true. To execute multiple statements within the loop, use a
 block statement (`{ /* ... */ }`) to
 group those statements.


`condition`

 An expression evaluated after each pass through the loop. If `condition`
evaluates to true, the `statement` is re-executed. When
 `condition` evaluates to false, control passes to the statement following
 the `do...while`.


 Note: Use the `break` statement to stop a loop before `condition` evaluates
 to false.


Examples
--------

### Using `do...while`

 In the following example, the `do...while` loop iterates at least once and
 reiterates until `i` is no longer less than 5.


```js
let result = "";
let i = 0;
do {
  i += 1;
  result += `${i} `;
} while (i > 0 && i < 5);
// Despite i === 0 this will still loop as it starts off without the test

console.log(result);
```

### Using an assignment as a condition

In some cases, it can make sense to use an assignment as a condition, such as this:


```js
do {
  // …
} while ((match = regexp.exec(str)));
```


But when you do, there are readability tradeoffs. The `while` documentation has a Using an assignment as a condition section with our recommendations.

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-do-while-statement |

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

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

See also
--------

* `while`
* `for`
* `break`
* `continue`
debugger
========

 The **`debugger`** statement invokes any available debugging
 functionality, such as setting a breakpoint. If no debugging functionality is available,
 this statement has no effect.

Syntax
------


```js
debugger;
```

Examples
--------

### Using the debugger statement

 The following example shows code where a `debugger` statement has been
 inserted, to invoke a debugger (if one exists) when the function is called.


```js
function potentiallyBuggyCode() {
  debugger;
  // do potentially buggy stuff to examine, step through, etc.
}
```


 When the debugger is invoked, execution is paused at the `debugger`
 statement. It is like a breakpoint in the script source.

![A browser with developer tools open to the debugger panel showing how execution is paused at the debugger statement to allow close inspection of variables, scopes, events, etc.](/en-US/docs/Web/JavaScript/Reference/Statements/debugger/screen_shot_2014-02-07_at_9.14.35_am.png)

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-debugger-statement |

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

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

See also
--------

* The Firefox JavaScript Debugger¶ in the Firefox source docs
Empty statement
===============

 An **empty statement** is used to provide no statement, although the
 JavaScript syntax would expect one.

Try it
------

Syntax
------


```js
;
```

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

 The empty statement is a semicolon (`;`) indicating that no statement will
 be executed, even if JavaScript syntax requires one.

 The opposite behavior, where you want multiple statements, but JavaScript only allows a
 single one, is possible using a block statement,
 which combines several statements into a single one.

Examples
--------

### Empty loop body

 The empty statement is sometimes used with loop statements. See the following example
 with an empty loop body:


```js
const arr = [1, 2, 3];

// Assign all array values to 0
for (let i = 0; i < arr.length; arr[i++] = 0) /\* empty statement \*/ ;

console.log(arr);
// [0, 0, 0]
```

### Unintentional usage

 It is a good idea to comment *intentional* use of the empty statement, as it is
 not really obvious to distinguish from a normal semicolon.

In the following example, the usage is probably not intentional:


```js
if (condition);      // Caution, this "if" does nothing!
  killTheUniverse(); // So this always gets executed!!!
```

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

| Specification |
| --- |
| ECMAScript Language Specification # sec-empty-statement |

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

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

See also
--------

* Block statement
SyntaxError: missing formal parameter
=====================================

 The JavaScript exception "missing formal parameter" occurs when your function
 declaration is missing valid parameters.

Message
-------
```

SyntaxError: missing formal parameter (Firefox)
SyntaxError: Unexpected number '3'. Expected a parameter pattern or a ')' in parameter list. (Safari)
SyntaxError: Unexpected string literal "x". Expected a parameter pattern or a ')' in parameter list. (Safari)
```

Error type
----------

`SyntaxError`What went wrong?
----------------

 "Formal parameter" is a fancy way of saying "function parameter". Your function
 declaration is missing valid parameters. In the declaration of a function, the
 parameters must be identifiers, not any
 value like numbers, strings, or objects. Declaring functions and calling functions are
 two separate steps. Declarations require identifier as parameters, and only when calling
 (invoking) the function, you provide the values the function should use.

 In JavaScript, identifiers can contain
 only alphanumeric characters (or "$" or "\_"), and may not start with a digit. An
 identifier differs from a **string** in that a string is data, while an
 identifier is part of the code.

Examples
--------

### Provide proper function parameters

 Function parameters must be identifiers when setting up a function. All these function
 declarations fail, as they are providing values for their parameters:


```js
function square(3) {
  return number \* number;
}
// SyntaxError: missing formal parameter

function greet("Howdy") {
  return greeting;
}
// SyntaxError: missing formal parameter

function log({ obj: "value"}) {
  console.log(arg)
}
// SyntaxError: missing formal parameter
```


You will need to use identifiers in function declarations:


```js
function square(number) {
  return number \* number;
}

function greet(greeting) {
  return greeting;
}

function log(arg) {
  console.log(arg);
}
```


You can then call these functions with the arguments you like:


```js
square(2); // 4

greet("Howdy"); // "Howdy"

log({ obj: "value" }); // { obj: "value" }
```

See also
--------

* SyntaxError: redeclaration of formal parameter "x"
ReferenceError: assignment to undeclared variable "x"
=====================================================

The JavaScript strict mode-only exception "Assignment to undeclared variable" occurs when the value has been assigned to an undeclared variable.

Message
-------
```

ReferenceError: x is not defined (V8-based)
ReferenceError: assignment to undeclared variable x (Firefox)
ReferenceError: Can't find variable: x (Safari)
```

Error type
----------

`ReferenceError` in strict mode only.

What went wrong?
----------------

 A value has been assigned to an undeclared variable.
 In other words, there was an assignment without the `var` keyword.
 There are some differences between declared and undeclared variables, which might lead to unexpected results and that's why JavaScript presents an error in strict mode.

Three things to note about declared and undeclared variables:

* Declared variables are constrained in the execution context in which they are declared.
 Undeclared variables are always global.
* Declared variables are created before any code is executed.
 Undeclared variables do not exist until the code assigning to them is executed.
* Declared variables are a non-configurable property of their execution context (function or global).
 Undeclared variables are configurable (e.g. can be deleted).

For more details and examples, see the `var` reference page.

 Errors about undeclared variable assignments occur in strict mode code only.
 In non-strict code, they are silently ignored.

Examples
--------

### Invalid cases

In this case, the variable "bar" is an undeclared variable.


```js
function foo() {
  "use strict";
  bar = true;
}
foo(); // ReferenceError: assignment to undeclared variable bar
```

### Valid cases

To make "bar" a declared variable, you can add a `let`, `const`, or `var` keyword in front of it.


```js
function foo() {
  "use strict";
  const bar = true;
}
foo();
```

See also
--------

* Strict mode
TypeError: can't delete non-configurable array element
======================================================

 The JavaScript exception "can't delete non-configurable array element" occurs when it
 was attempted to shorten the length
 of an array, but one of the array's elements is non-configurable.

Message
-------
```

TypeError: Cannot delete property '1' of [object Array] (V8-based)
TypeError: can't delete non-configurable array element (Firefox)
TypeError: Unable to delete property. (Safari)
```

Error type
----------

`TypeError`What went wrong?
----------------

 It was attempted to shorten the length
 of an array, but one of the array's elements is non-configurable.
 When shortening an array, the elements beyond the new array length will be deleted,
 which failed in this situation.

 The `configurable` attribute controls whether the property can be deleted
 from the object and whether its attributes (other than `writable`) can be
 changed.

Usually, properties in an object created by an array initializer are configurable. However, for example, when using `Object.defineProperty()`, the property isn't configurable by default.

Examples
--------

### Non-configurable properties created by Object.defineProperty

 The `Object.defineProperty()` creates non-configurable properties by
 default if you haven't specified them as configurable.


```js
"use strict";
const arr = [];
Object.defineProperty(arr, 0, { value: 0 });
Object.defineProperty(arr, 1, { value: "1" });

arr.length = 1;
// TypeError: can't delete non-configurable array element
```


You will need to set the elements as configurable, if you intend to shorten the array.


```js
"use strict";
const arr = [];
Object.defineProperty(arr, 0, { value: 0, configurable: true });
Object.defineProperty(arr, 1, { value: "1", configurable: true });

arr.length = 1;
```

### Sealed Arrays

 The `Object.seal()` function marks all existing elements as
 non-configurable.


```js
"use strict";
const arr = [1, 2, 3];
Object.seal(arr);

arr.length = 1;
// TypeError: can't delete non-configurable array element
```


 You either need to remove the `Object.seal()` call, or make a copy of it.
 In case of a copy, shortening the copy of the array does not modify the original array
 length.


```js
"use strict";
const arr = [1, 2, 3];
Object.seal(arr);

// Copy the initial array to shorten the copy
const copy = Array.from(arr);
copy.length = 1;
// arr.length === 3
```

See also
--------

* [[Configurable]]
* `length`
* `Object.defineProperty()`
* `Object.seal()`
SyntaxError: missing ) after argument list
==========================================

 The JavaScript exception "missing ) after argument list" occurs when there is an error
 with how a function is called. This might be a typo, a missing operator, or an unescaped
 string.

Message
-------
```

SyntaxError: missing ) after argument list (V8-based & Firefox)
SyntaxError: Unexpected identifier 'x'. Expected ')' to end an argument list. (Safari)
```

Error type
----------

`SyntaxError`.

What went wrong?
----------------

 There is an error with how a function is called. This might be a typo, a missing
 operator, or an unescaped string, for example.

Examples
--------

 Because there is no "+" operator to concatenate the string, JavaScript expects the
 argument for the `log` function to be just `"PI: "`. In that case,
 it should be terminated by a closing parenthesis.


```js
console.log("PI: " Math.PI);
// SyntaxError: missing ) after argument list
```


You can correct the `log` call by adding the `+` operator:


```js
console.log("PI: " + Math.PI);
// "PI: 3.141592653589793"
```


Alternatively, you can consider using a template literal, or take advantage of the fact that `console.log` accepts multiple parameters:


```js
console.log(`PI: ${Math.PI}`);
console.log("PI:", Math.PI);
```

### Unterminated strings


```js
console.log('"Java" + "Script" = \"' + "Java" + 'Script\");
// SyntaxError: missing ) after argument list
```


 Here JavaScript thinks that you meant to have `);` inside the string and
 ignores it, and it ends up not knowing that you meant the `);` to end the
 function `console.log`. To fix this, we could put a`'` after the
 "Script" string:


```js
console.log('"Java" + "Script" = "' + "Java" + 'Script"');
// '"Java" + "Script" = "JavaScript"'
```

See also
--------

* Functions guide
TypeError: can't convert BigInt to number
=========================================

The JavaScript exception "can't convert BigInt to number" occurs when an arithmetic operation involves a mix of `BigInt` and `Number` values.

Message
-------
```

TypeError: Cannot mix BigInt and other types, use explicit conversions (V8-based)
TypeError: BigInts have no unsigned right shift, use >> instead (V8-based)
TypeError: can't convert BigInt to number (Firefox)
TypeError: Invalid mix of BigInt and other type in addition/multiplication/…. (Safari)
TypeError: BigInt does not support >>> operator (Safari)
```

Error type
----------

`TypeError`.

What went wrong?
----------------

The two sides of an arithmetic operator must both be BigInts or both not. If an operation involves a mix of BigInts and numbers, it's ambiguous whether the result should be a BigInt or number, since there may be loss of precision in both cases.

The error can also happen if the unsigned right shift operator (`>>>`) is used between two BigInts. In Firefox, the message is the same: "can't convert BigInt to number".

Examples
--------

### Mixing numbers and BigInts in operations


```js
const sum = 1n + 1;
// TypeError: can't convert BigInt to number
```


Instead, explicitly coerce one side to a BigInt or number.


```js
const sum = 1n + BigInt(1);
const sum2 = Number(1n) + 1;
```

### Using unsigned right shift on BigInts


```js
const a = 4n >>> 2n;
// TypeError: can't convert BigInt to number
```


Use normal right shift instead.


```js
const a = 4n >> 2n;
```

See also
--------

* `BigInt`
SyntaxError: return not in function
===================================

The JavaScript exception "return not in function" occurs when a `return` statement is called outside of a function.

Message
-------
```

SyntaxError: Illegal return statement (V8-based)
SyntaxError: return not in function (Firefox)
SyntaxError: Return statements are only valid inside functions. (Safari)
```

Error type
----------

`SyntaxError`.

What went wrong?
----------------

A `return` statement is called outside of a function. Maybe there are missing curly braces somewhere? The `return` statement must be in a function, because it ends function execution and specifies a value to be returned to the function caller.

Examples
--------

### Missing curly braces


```js
function cheer(score) {
  if (score === 147)
    return "Maximum!";
  }
  if (score > 100) {
    return "Century!";
  }
}

// SyntaxError: return not in function
```


The curly braces look correct at a first glance, but this code snippet is missing a `{` after the first `if` statement. Correct would be:


```js
function cheer(score) {
  if (score === 147) {
    return "Maximum!";
  }
  if (score > 100) {
    return "Century!";
  }
}
```

See also
--------

* `return`
TypeError: can't convert x to BigInt
====================================

The JavaScript exception "x can't be converted to BigInt" occurs when attempting to convert a `Symbol`, `null`, or `undefined` value to a `BigInt`, or if an operation expecting a BigInt parameter receives a number.

Message
-------
```

TypeError: Cannot convert null to a BigInt (V8-based)
TypeError: can't convert null to BigInt (Firefox)
TypeError: Invalid argument type in ToBigInt operation (Safari)
```

Error type
----------

`TypeError`.

What went wrong?
----------------

When using the `BigInt()` function to convert a value to a BigInt, the value would first be converted to a primitive. Then, if it's not one of BigInt, string, number, and boolean, the error is thrown.

Some operations, like `BigInt.asIntN`, require the parameter to be a BigInt. Passing in a number in this case will also throw this error.

Examples
--------

### Using BigInt() on invalid values


```js
const a = BigInt(null);
// TypeError: can't convert null to BigInt
const b = BigInt(undefined);
// TypeError: can't convert undefined to BigInt
const c = BigInt(Symbol("1"));
// TypeError: can't convert Symbol("1") to BigInt
```



```js
const a = BigInt(1);
const b = BigInt(true);
const c = BigInt("1");
const d = BigInt(Symbol("1").description);
```


**Note:** Simply coercing the value to a string or number using `String()` or `Number()` before passing it to `BigInt()` is usually not sufficient to avoid all errors. If the string is not a valid integer number string, a SyntaxError is thrown; if the number is not an integer (most notably, `NaN`), a RangeError is thrown. If the range of input is unknown, properly validate it before using `BigInt()`.

### Passing a number to a function expecting a BigInt


```js
const a = BigInt.asIntN(4, 8);
// TypeError: can't convert 8 to BigInt
const b = new BigInt64Array(3).fill(3);
// TypeError: can't convert 3 to BigInt
```



```js
const a = BigInt.asIntN(4, 8n);
const b = new BigInt64Array(3).fill(3n);
```

See also
--------

* `BigInt()` constructor
SyntaxError: a declaration in the head of a for-of loop can't have an initializer
=================================================================================

The JavaScript exception "a declaration in the head of a for-of loop can't have an initializer" occurs when the head of a for...of loop contains an initializer expression such as `for (const i = 0 of iterable)`. This is not allowed in for-of loops.

Message
-------
```

SyntaxError: for-of loop variable declaration may not have an initializer. (V8-based)
SyntaxError: a declaration in the head of a for-of loop can't have an initializer (Firefox)
SyntaxError: Cannot assign to the loop variable inside a for-of loop header. (Safari)
```

Error type
----------

`SyntaxError`What went wrong?
----------------

The head of a for...of loop contains an initializer expression. That is, a variable is declared and assigned a value `for (const i = 0 of iterable)`. This is not allowed in for-of loops. You might want a `for` loop that does allow an initializer.

Examples
--------

### Invalid for-of loop


```js
const iterable = [10, 20, 30];

for (const value = 50 of iterable) {
  console.log(value);
}

// SyntaxError: a declaration in the head of a for-of loop can't
// have an initializer
```

### Valid for-of loop

You need to remove the initializer (`value = 50`) in the head of the `for-of` loop. Maybe you intended to make 50 an offset value, in that case you could add it to the loop body, for example.


```js
const iterable = [10, 20, 30];

for (let value of iterable) {
  value += 50;
  console.log(value);
}
// 60
// 70
// 80
```

See also
--------

* `for...of`
* `for...in`
* `for`
SyntaxError: identifier starts immediately after numeric literal
================================================================

 The JavaScript exception "identifier starts immediately after numeric literal" occurs
 when an identifier started with a digit. Identifiers can only start with a letter,
 underscore (\_), or dollar sign ($).

Message
-------
```

SyntaxError: Unexpected identifier after numeric literal (Edge)
SyntaxError: identifier starts immediately after numeric literal (Firefox)
SyntaxError: Unexpected number (Chrome)
```

Error type
----------

`SyntaxError`What went wrong?
----------------

 The names of variables, called identifiers, conform to certain rules,
 which your code must adhere to!

 A JavaScript identifier must start with a letter, underscore (\_), or dollar sign ($).
 They can't start with a digit! Only subsequent characters can be digits (0-9).

Examples
--------

### Variable names starting with numeric literals

Variable names can't start with numbers in JavaScript. The following fails:


```js
const 1life = "foo";
// SyntaxError: identifier starts immediately after numeric literal

const foo = 1life;
// SyntaxError: identifier starts immediately after numeric literal

alert(1.foo);
// SyntaxError: identifier starts immediately after numeric literal
```


You will need to rename your variable to avoid the leading number.


```js
const life1 = "foo";
const foo = life1;
```

See also
--------

* Lexical grammar
* Grammar and types guide