recursal/MDN huggingface dataset:
TypeError: X.prototype.y called on incompatible type
====================================================

 The JavaScript exception "called on incompatible target (or object)" occurs when a
 function (on a given object), is called with a `this` not corresponding to
 the type expected by the function.

Message
-------
```

TypeError: Method Set.prototype.add called on incompatible receiver undefined (V8-based)
TypeError: Bind must be called on a function (V8-based)
TypeError: Function.prototype.toString called on incompatible object (Firefox)
TypeError: Function.prototype.bind called on incompatible target (Firefox)
TypeError: Type error (Safari)
TypeError: undefined is not an object (Safari)
```

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

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

 When this error is thrown, a function (on a given object), is called with a
 `this` not corresponding to the type expected by the function.

 This issue can arise when using the `Function.prototype.call()` or
 `Function.prototype.apply()` methods, and providing a `this`
 argument which does not have the expected type.

 This issue can also happen when providing a function that is stored as a property of an
 object as an argument to another function. In this case, the object that stores the
 function won't be the `this` target of that function when it is called by the
 other function. To work-around this issue, you will either need to provide a lambda
 which is making the call, or use the `Function.prototype.bind()` function to
 force the `this` argument to the expected object.

Examples
--------

### Invalid cases


```js
const mySet = new Set();
["bar", "baz"].forEach(mySet.add);
// mySet.add is a function, but "mySet" is not captured as this.

const myFun = function () {
  console.log(this);
};
["bar", "baz"].forEach(myFun.bind);
// myFun.bind is a function, but "myFun" is not captured as this.
```

### Valid cases


```js
const mySet = new Set();
["bar", "baz"].forEach(mySet.add.bind(mySet));
// This works due to binding "mySet" as this.

const myFun = function () {
  console.log(this);
};
["bar", "baz"].forEach((x) => myFun.bind(x));
// This works using the "bind" function. It creates a lambda forwarding the argument.
```

See also
--------

* `Function.prototype.call()`
* `Function.prototype.apply()`
* `Function.prototype.bind()`
SyntaxError: missing } after property list
==========================================

 The JavaScript exception "missing } after property list" occurs when there is a mistake
 in the object initializer syntax somewhere.
 Might be in fact a missing curly bracket, but could also be a missing comma.

Message
-------
```

SyntaxError: missing } after property list (Firefox)
SyntaxError: Unexpected identifier 'c'. Expected '}' to end an object literal. (Safari)
```

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

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

 There is a mistake in the object initializer
 syntax somewhere. Might be in fact a missing curly bracket, but could
 also be a missing comma, for example. Also check if any closing curly braces or
 parenthesis are in the correct order. Indenting or formatting the code a bit nicer might
 also help you to see through the jungle.

Examples
--------

### Forgotten comma

Oftentimes, there is a missing comma in your object initializer code:


```js
const obj = {
  a: 1,
  b: { myProp: 2 }
  c: 3
};
```


Correct would be:


```js
const obj = {
  a: 1,
  b: { myProp: 2 },
  c: 3,
};
```

See also
--------

* Object initializer
SyntaxError: "x" is a reserved identifier
=========================================

 The JavaScript exception "*variable* is a reserved identifier" occurs
 when reserved keywords are used as identifiers.

Message
-------
```

SyntaxError: Unexpected reserved word (V8-based)
SyntaxError: implements is a reserved identifier (Firefox)
SyntaxError: Cannot use the reserved word 'implements' as a variable name. (Safari)
```

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

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

Reserved keywords will throw in
 if they are used as identifiers. These are reserved in
 strict mode and sloppy mode:

* `enum`

The following are only reserved when they are found in strict mode code:

* `implements`
* `interface`
* `let`
* `package`
* `private`
* `protected`
* `public`
* `static`
Examples
--------

### Strict and non-strict reserved keywords

The `enum` identifier is generally reserved.


```js
const enum = { RED: 0, GREEN: 1, BLUE: 2 };
// SyntaxError: enum is a reserved identifier
```


In strict mode code, more identifiers are reserved.


```js
"use strict";
const package = ["potatoes", "rice", "fries"];
// SyntaxError: package is a reserved identifier
```


You'll need to rename these variables.


```js
const colorEnum = { RED: 0, GREEN: 1, BLUE: 2 };
const list = ["potatoes", "rice", "fries"];
```

### Update older browsers

 If you are using an older browser that does not yet implement
 `let` or
 `class`,
 for example, you should update to a more recent browser version that does support these
 new language features.


```js
"use strict";
class DocArchiver {}

// SyntaxError: class is a reserved identifier
// (throws in older browsers only, e.g. Firefox 44 and older)
```

See also
--------

* Lexical grammar
ReferenceError: "x" is not defined
==================================

 The JavaScript exception "*variable* is not defined" occurs when there is a
 non-existent variable referenced somewhere.

Message
-------
```

ReferenceError: "x" is not defined (V8-based & Firefox)
ReferenceError: Can't find variable: x (Safari)
```

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

`ReferenceError`.

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

 There is a non-existent variable referenced somewhere. This variable needs to be
 declared, or you need to make sure it is available in your current script or scope.


**Note:** When loading a library (such as jQuery), make sure it is
 loaded before you access library variables, such as "$". Put the
 `<script>` element that loads the library before your code that uses
 it.


Examples
--------

### Variable not declared


```js
foo.substring(1); // ReferenceError: foo is not defined
```


 The "foo" variable isn't defined anywhere. It needs to be some string, so that the
 `String.prototype.substring()` method will work.


```js
const foo = "bar";
foo.substring(1); // "ar"
```

### Wrong scope

 A variable needs to be available in the current context of execution. Variables defined
 inside a function cannot be
 accessed from anywhere outside the function, because the variable is defined only in the
 scope of the function


```js
function numbers() {
  const num1 = 2;
  const num2 = 3;
  return num1 + num2;
}

console.log(num1); // ReferenceError num1 is not defined.
```


 However, a function can access all variables and functions defined inside the scope in
 which it is defined. In other words, a function defined in the global scope can access
 all variables defined in the global scope.


```js
const num1 = 2;
const num2 = 3;

function numbers() {
  return num1 + num2;
}

console.log(numbers()); // 5
```

See also
--------

* Scope
* Declaring variables in the JavaScript Guide
* Function scope in the JavaScript Guide
TypeError: can't assign to property "x" on "y": not an object
=============================================================

 The JavaScript strict mode exception "can't assign to property" occurs when attempting
 to create a property on primitive value
 such as a symbol, a string, a number or a boolean. Primitive values cannot hold any property.

Message
-------
```

TypeError: Cannot create property 'x' on number '1' (V8-based)
TypeError: can't assign to property "x" on 1: not an object (Firefox)
TypeError: Attempted to assign to readonly property. (Safari)
```

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

`TypeError`.

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

 In strict mode, a `TypeError` is raised when attempting to
 create a property on primitive value such
 as a symbol, a string, a number or a boolean. Primitive values cannot hold any property.

 The problem might be that an unexpected value is flowing at an unexpected place, or
 that an object variant of a `String` or a `Number` is expected.

Examples
--------

### Invalid cases


```js
"use strict";

const foo = "my string";
// The following line does nothing if not in strict mode.
foo.bar = {}; // TypeError: can't assign to property "bar" on "my string": not an object
```

### Fixing the issue

Either fix the code to prevent the primitive from being used in such places, or fix the issue by creating the object equivalent `Object`.


```js
"use strict";

const foo = new String("my string");
foo.bar = {};
```

See also
--------

* Strict mode
* primitive
Warning: unreachable code after return statement
================================================

 The JavaScript warning "unreachable code after return statement" occurs when using an
 expression after a `return` statement, or when using a
 semicolon-less return statement but including an expression directly after.

Message
-------
```

Warning: unreachable code after return statement (Firefox)
```

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

Warning

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

Unreachable code after a return statement might occur in these situations:

* When using an expression after a `return`
 statement, or
* when using a semicolon-less return statement but including an expression directly
 after.

 When an expression exists after a valid `return` statement, a warning is
 given to indicate that the code after the `return` statement is unreachable,
 meaning it can never be run.

 Why should I have semicolons after `return` statements? In the case of
 semicolon-less `return` statements, it can be unclear whether the developer
 intended to return the statement on the following line, or to stop execution and return.
 The warning indicates that there is ambiguity in the way the `return`
 statement is written.

Warnings will not be shown for semicolon-less returns if these statements follow it:

* `throw`
* `break`
* `var`
* `function`
Examples
--------

### Invalid cases


```js
function f() {
  let x = 3;
  x += 4;
  return x;   // return exits the function immediately
  x -= 3;     // so this line will never run; it is unreachable
}

function g() {
  return     // this is treated like `return;`
    3 + 4;   // so the function returns, and this line is never reached
}
```

### Valid cases


```js
function f() {
  let x = 3;
  x += 4;
  x -= 3;
  return x; // OK: return after all other statements
}

function g() {
  return 3 + 4 // OK: semicolon-less return with expression on the same line
}
```

See also
--------

* Automatic semicolon insertion
SyntaxError: invalid BigInt syntax
==================================

The JavaScript exception "invalid BigInt syntax" occurs when a string value is being coerced to a `BigInt` but it failed to be parsed as an integer.

Message
-------
```

SyntaxError: Cannot convert x to a BigInt (V8-based)
SyntaxError: invalid BigInt syntax (Firefox)
SyntaxError: Failed to parse String to BigInt (Safari)
```

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

`SyntaxError`.

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

When using the `BigInt()` function to convert a string to a BigInt, the string will be parsed in the same way as source code, and the resulting value must be an integer value.

Examples
--------

### Invalid cases


```js
const a = BigInt("1.5");
const b = BigInt("1n");
const c = BigInt.asIntN(4, "8n");
// SyntaxError: invalid BigInt syntax
```

### Valid cases


```js
const a = BigInt("1");
const b = BigInt(" 1 ");
const c = BigInt.asIntN(4, "8");
```

See also
--------

* `BigInt`
SyntaxError: getter and setter for private name #x should either be both static or non-static
=============================================================================================

The JavaScript exception "mismatched placement" occurs when a private getter and setter are mismatched in whether or not they are `static`.

Message
-------
```

SyntaxError: Identifier '#x' has already been declared (V8-based)
SyntaxError: getter and setter for private name #x should either be both static or non-static (Firefox)
SyntaxError: Cannot declare a private non-static getter if there is a static private setter with used name. (Safari)
```

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

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

Private getters and setters for the same name must either be both `static`, or both non-static. This limitation does not exist for public methods.

Examples
--------

### Mismatched placement


```js
class Test {
  static set #foo(\_) {}
  get #foo() {}
}

// SyntaxError: getter and setter for private name #foo should either be both static or non-static
```


Since `foo` is private, the methods must be either both `static`:


```js
class Test {
  static set #foo(\_) {}
  static get #foo() {}
}
```


or non-static:


```js
class Test {
  set #foo(\_) {}
  get #foo() {}
}
```

See also
--------

* `get`
* `set`
* `static`
* Private properties
RangeError: radix must be an integer
====================================

 The JavaScript exception "radix must be an integer at least 2 and no greater than 36"
 occurs when the optional `radix` parameter of the
 `Number.prototype.toString()` or
 the `BigInt.prototype.toString()` method was specified and is not between 2
 and 36.

Message
-------
```

RangeError: toString() radix argument must be between 2 and 36 (V8-based & Safari)
RangeError: radix must be an integer at least 2 and no greater than 36 (Firefox)
```

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

`RangeError`What went wrong?
----------------

 The optional `radix` parameter of the
 `Number.prototype.toString()` or
 the `BigInt.prototype.toString()` method was specified. Its value must be an
 integer (a number) between 2 and 36, specifying the base of the number system to be used
 for representing numeric values. For example, the decimal (base 10) number 169 is
 represented in hexadecimal (base 16) as A9.

 Why is this parameter's value limited to 36? A radix that is larger than 10 uses
 alphabetical characters as digits; therefore, the radix can't be larger than 36, since
 the Latin alphabet (used by English and many other languages) only has 26 characters.

The most common radixes:

* 2 for binary numbers,
* 8 for octal numbers,
* 10 for decimal numbers,
* 16 for hexadecimal numbers.
Examples
--------

### Invalid cases


```js
(42).toString(0);
(42).toString(1);
(42).toString(37);
(42).toString(150);
// You cannot use a string like this for formatting:
(12071989).toString("MM-dd-yyyy");
```

### Valid cases


```js
(42).toString(2); // "101010" (binary)
(13).toString(8); // "15" (octal)
(0x42).toString(10); // "66" (decimal)
(100000).toString(16); // "186a0" (hexadecimal)
```

See also
--------

* `Number.prototype.toString()`
* `BigInt.prototype.toString()`
SyntaxError: test for equality (==) mistyped as assignment (=)?
===============================================================

 The JavaScript warning "test for equality (==) mistyped as assignment (=)?" occurs when
 there was an assignment (`=`) when you would normally expect a test for
 equality (`==`).

Message
-------
```

Warning: SyntaxError: test for equality (==) mistyped as assignment (=)?
```

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

 (Firefox only) `SyntaxError` warning which is reported only if
 `javascript.options.strict` preference is set to `true`.

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

 There was an assignment (`=`) when you would normally expect a test for
 equality (`==`). To help debugging, JavaScript (with strict warnings enabled)
 warns about this pattern.

Examples
--------

### Assignment within conditional expressions

 It is advisable to not use simple assignments in a conditional expression (such as
 `if...else`),
 because the assignment can be confused with equality when glancing over the code. For
 example, do not use the following code:


```js
if (x = y) {
  // do the right thing
}
```


 If you need to use an assignment in a conditional expression, a common practice is to
 put additional parentheses around the assignment. For example:


```js
if ((x = y)) {
  // do the right thing
}
```


 Otherwise, you probably meant to use a comparison operator (e.g. `==` or
 `===`):


```js
if (x === y) {
  // do the right thing
}
```

See also
--------

* `if...else`
* Equality operators
SyntaxError: "0"-prefixed octal literals and octal escape seq. are deprecated
=============================================================================

 The JavaScript strict mode-only exception "0-prefixed octal literals and octal escape sequences are
 deprecated; for octal literals use the "0o" prefix instead" occurs when deprecated octal
 literals and octal escape sequences are used.

Message
-------
```

SyntaxError: Octal literals are not allowed in strict mode. (V8-based)
SyntaxError: "0"-prefixed octal literals are deprecated; use the "0o" prefix instead (Firefox)
SyntaxError: Decimal integer literals with a leading zero are forbidden in strict mode (Safari)

SyntaxError: Octal escape sequences are not allowed in strict mode. (V8-based)
SyntaxError: octal escape sequences can't be used in untagged template literals or in strict mode code (Firefox)
SyntaxError: The only valid numeric escape in strict mode is '\0' (Safari)
```

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

`SyntaxError` in strict mode only.

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

 Octal literals and octal escape sequences are deprecated and will throw a
 `SyntaxError` in strict mode. The
 standardized syntax uses a leading zero followed by a lowercase or uppercase Latin
 letter "O" (`0o` or `0O`).

Examples
--------

### "0"-prefixed octal literals


```js
"use strict";

03;

// SyntaxError: "0"-prefixed octal literals are deprecated; use the "0o" prefix instead
```

### Octal escape sequences


```js
"use strict";

"\251";

// SyntaxError: octal escape sequences can't be used in untagged template literals or in strict mode code
```

### Valid octal numbers

Use a leading zero followed by the letter "o" or "O":


```js
0o3;
```


For octal escape sequences, you can use hexadecimal escape sequences instead:


```js
"\xA9";
```

See also
--------

* Lexical grammar
TypeError: Reduce of empty array with no initial value
======================================================

 The JavaScript exception "reduce of empty array with no initial value" occurs when a
 reduce function is used.

Message
-------
```

TypeError: Reduce of empty array with no initial value (V8-based & Firefox & Safari)
```

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

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

In JavaScript, there are several reduce functions:

* `Array.prototype.reduce()`, `Array.prototype.reduceRight()`
 and
* `TypedArray.prototype.reduce()`,
 `TypedArray.prototype.reduceRight()`).

 These functions optionally take an `initialValue` (which will be used as the
 first argument to the first call of the `callback`). However, if no initial
 value is provided, it will use the first element of the `Array` or
 `TypedArray` as the initial value. This error is raised when an empty array
 is provided because no initial value can be returned in that case.

Examples
--------

### Invalid cases

 This problem appears frequently when combined with a filter
 (`Array.prototype.filter()`, `TypedArray.prototype.filter()`)
 which will remove all elements of the list. Thus leaving none to be used as the initial
 value.


```js
const ints = [0, -1, -2, -3, -4, -5];
ints
  .filter((x) => x > 0) // removes all elements
  .reduce((x, y) => x + y); // no more elements to use for the initial value.
```


 Similarly, the same issue can happen if there is a typo in a selector, or an unexpected
 number of elements in a list:


```js
const names = document.getElementsByClassName("names");
const name_list = Array.prototype.reduce.call(
  names,
  (acc, name) => acc + ", " + name,
);
```

### Valid cases

These problems can be solved in two different ways.

 One way is to actually provide an `initialValue` as the neutral element of
 the operator, such as 0 for the addition, 1 for a multiplication, or an empty string for
 a concatenation.


```js
const ints = [0, -1, -2, -3, -4, -5];
ints
  .filter((x) => x > 0) // removes all elements
  .reduce((x, y) => x + y, 0); // the initial value is the neutral element of the addition
```


 Another way would be to handle the empty case, either before calling
 `reduce`, or in the callback after adding an unexpected dummy initial value.


```js
const names = document.getElementsByClassName("names");

let nameList1 = "";
if (names.length >= 1) {
  nameList1 = Array.prototype.reduce.call(
    names,
    (acc, name) => `${acc}, ${name}`,
  );
}
// nameList1 === "" when names is empty.

const nameList2 = Array.prototype.reduce.call(
  names,
  (acc, name) => {
    if (acc === "")
      // initial value
      return name;
    return `${acc}, ${name}`;
  },
  "",
);
// nameList2 === "" when names is empty.
```

See also
--------

* `Array.prototype.reduce()`
* `Array.prototype.reduceRight()`
* `TypedArray.prototype.reduce()`
* `TypedArray.prototype.reduceRight()`
* `Array`
* `TypedArray`
* `Array.prototype.filter()`
* `TypedArray.prototype.filter()`
SyntaxError: for-in loop head declarations may not have initializers
====================================================================

 The JavaScript strict mode-only exception
 "for-in loop head declarations may not have initializers"
 occurs when the head of a for...in contains
 an initializer expression, such as `for (var i = 0 in obj)`. This is not
 allowed in for-in loops in strict mode. In addition, lexical declarations with initializers like `for (const i = 0 in obj)` are not allowed outside strict mode either.

Message
-------
```

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

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

`SyntaxError`.

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

 The head of a for...in loop contains an initializer expression.
 That is, a variable is declared and assigned a value `for (var i = 0 in obj)`.
 In non-strict mode, this head declaration is silently ignored and behaves like `for (var i in obj)`.
 In strict mode, however, a `SyntaxError` is thrown. In addition, lexical declarations with initializers like `for (const i = 0 in obj)` are not allowed outside strict mode either, and will always produce a `SyntaxError`.

Examples
--------

This example throws a `SyntaxError`:


```js
const obj = { a: 1, b: 2, c: 3 };

for (const i = 0 in obj) {
  console.log(obj[i]);
}

// SyntaxError: for-in loop head declarations may not have initializers
```

### Valid for-in loop

You can remove the initializer (`i = 0`) in the head of the for-in loop.


```js
const obj = { a: 1, b: 2, c: 3 };

for (const i in obj) {
  console.log(obj[i]);
}
```

### Array iteration

 The for...in loop shouldn't be used for Array iteration.
 Did you intend to use a `for` loop
 instead of a `for-in` loop to iterate an `Array`? The
 `for` loop allows you to set an initializer then as well:


```js
const arr = ["a", "b", "c"];

for (let i = 2; i < arr.length; i++) {
  console.log(arr[i]);
}

// "c"
```

See also
--------

* `for...in`
* `for...of`
* `for`