recursal/MDN huggingface dataset:
SyntaxError: invalid assignment left-hand side
==============================================

The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere. It may be triggered when a single `=` sign was used instead of `==` or `===`.

Message
-------
```

SyntaxError: Invalid left-hand side in assignment (V8-based)
SyntaxError: invalid assignment left-hand side (Firefox)
SyntaxError: Left side of assignment is not a reference. (Safari)
```

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

`SyntaxError` or `ReferenceError`, depending on the syntax.

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

There was an unexpected assignment somewhere. This might be due to a mismatch of an assignment operator and an equality operator, for example. While a single `=` sign assigns a value to a variable, the `==` or `===` operators compare a value.

Examples
--------

### Typical invalid assignments


```js
if (Math.PI + 1 = 3 || Math.PI + 1 = 4) {
  console.log("no way!");
}
// SyntaxError: invalid assignment left-hand side

const str = "Hello, "
+= "is it me "
+= "you're looking for?";
// SyntaxError: invalid assignment left-hand side
```


In the `if` statement, you want to use an equality operator (`===`), and for the string concatenation, the plus (`+`) operator is needed.


```js
if (Math.PI + 1 === 3 || Math.PI + 1 === 4) {
  console.log("no way!");
}

const str = "Hello, "
  + "from the "
  + "other side!";
```

### Assignments producing ReferenceErrors

Invalid assignments don't always produce syntax errors. Sometimes the syntax is almost correct, but at runtime, the left hand side expression evaluates to a *value* instead of a *reference*, so the assignment is still invalid. Such errors occur later in execution, when the statement is actually executed.


```js
function foo() {
  return { a: 1 };
}
foo() = 1; // ReferenceError: invalid assignment left-hand side
```


Function calls, `new` calls, `super()`, and `this` are all values instead of references. If you want to use them on the left hand side, the assignment target needs to be a property of their produced values instead.


```js
function foo() {
  return { a: 1 };
}
foo().a = 1;
```


**Note:** In Firefox and Safari, the first example produces a `ReferenceError` in non-strict mode, and a `SyntaxError` in strict mode. Chrome throws a runtime `ReferenceError` for both strict and non-strict modes.

### Using optional chaining as assignment target

Optional chaining is not a valid target of assignment.


```js
obj?.foo = 1; // SyntaxError: invalid assignment left-hand side
```


Instead, you have to first guard the nullish case.


```js
if (obj) {
  obj.foo = 1;
}
```

See also
--------

* Assignment operators
* Equality operators
SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead
===================================================================================

The JavaScript warning "Using `//@` to indicate sourceURL pragmas is deprecated. Use `//#` instead" occurs when there is a deprecated source map syntax in a JavaScript source.

Message
-------
```

Warning: SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead

Warning: SyntaxError: Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead
```

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

A warning that a `SyntaxError` occurred. JavaScript execution won't be halted.

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

There is a deprecated source map syntax in a JavaScript source.

JavaScript sources are often combined and minified to make delivering them from the server more efficient. With source maps, the debugger can map the code being executed to the original source files.

The source map specification changed the syntax due to a conflict with IE whenever it was found in the page after `//@cc_on` was interpreted to turn on conditional compilation in the IE JScript engine. The conditional compilation comment in IE is a little known feature, but it broke source maps with jQuery and other libraries.

Examples
--------

### Deprecated syntax

Syntax with the "@" sign is deprecated.


```js
//@ sourceMappingURL=http://example.com/path/to/your/sourcemap.map
```

### Standard syntax

Use the "#" sign instead.


```js
//# sourceMappingURL=http://example.com/path/to/your/sourcemap.map
```


Or, alternatively, you can set a `SourceMap` header to your JavaScript file to avoid having a comment at all:


```http
SourceMap: /path/to/file.js.map
```

See also
--------

* Use a source map in the Firefox source docs
* Introduction to JavaScript source maps on developer.chrome.com (2012)
* `SourceMap`
RangeError: BigInt division by zero
===================================

The JavaScript exception "BigInt division by zero" occurs when a `BigInt` is divided by `0n`.

Message
-------
```

RangeError: Division by zero (V8-based)
RangeError: BigInt division by zero (Firefox)
RangeError: 0 is an invalid divisor value. (Safari)
```

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

`RangeError`.

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

The divisor of a division or remainder operator is `0n`. In `Number` arithmetic, this produces `Infinity`, but there's no "infinity value" in BigInts, so an error is issued. Check if the divisor is `0n` before doing the division.

Examples
--------

### Division by 0n


```js
const a = 1n;
const b = 0n;
const quotient = a / b;
// RangeError: BigInt division by zero
```


Instead, check if the divisor is `0n` first, and either issue an error with a better message, or fallback to a different value, like `Infinity` or `undefined`.


```js
const a = 1n;
const b = 0n;
const quotient = b === 0n ? undefined : a / b;
```

See also
--------

* `BigInt`
* Division (`/`)
* Remainder (`%`)
RangeError: repeat count must be non-negative
=============================================

 The JavaScript exception "repeat count must be non-negative" occurs when the
 `String.prototype.repeat()` method is used with a `count`
 argument that is a negative number.

Message
-------
```

RangeError: Invalid count value: -1 (V8-based)
RangeError: repeat count must be non-negative (Firefox)
RangeError: String.prototype.repeat argument must be greater than or equal to 0 and not be Infinity (Safari)
```

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

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

 The `String.prototype.repeat()` method has been used. It has a
 `count` parameter indicating the number of times to repeat the string. It
 must be between 0 and less than positive `Infinity` and cannot be a negative
 number. The range of allowed values can be described like this: [0, +∞).

Examples
--------

### Invalid cases


```js
"abc".repeat(-1); // RangeError
```

### Valid cases


```js
"abc".repeat(0); // ''
"abc".repeat(1); // 'abc'
"abc".repeat(2); // 'abcabc'
"abc".repeat(3.5); // 'abcabcabc' (count will be converted to integer)
```

See also
--------

* `String.prototype.repeat()`
Warning: -file- is being assigned a //# sourceMappingURL, but already has one
=============================================================================

The JavaScript warning "-file- is being assigned a //# sourceMappingURL, but already has one." occurs when a source map has been specified more than once for a given JavaScript source.

Message
-------
```

Warning: -file- is being assigned a //# sourceMappingURL, but already has one.
```

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

A warning. JavaScript execution won't be halted.

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

A source map has been specified more than once for a given JavaScript source.

JavaScript sources are often combined and minified to make delivering them from the server more efficient. With source maps, the debugger can map the code being executed to the original source files. There are two ways to assign a source map, either by using a comment or by setting a header to the JavaScript file.

Examples
--------

### Setting source maps

Setting a source map by using a comment in the file:


```js
//# sourceMappingURL=http://example.com/path/to/your/sourcemap.map
```


Or, alternatively, you can set a header to your JavaScript file:


```http
X-SourceMap: /path/to/file.js.map
```

See also
--------

* Use a source map in the Firefox source docs
* Introduction to JavaScript source maps on developer.chrome.com (2012)
TypeError: can't define property "x": "obj" is not extensible
=============================================================

 The JavaScript exception "can't define property "x": "obj" is not extensible" occurs
 when `Object.preventExtensions()` marked an object as no longer extensible,
 so that it will never have properties beyond the ones it had at the time it was marked
 as non-extensible.

Message
-------
```

TypeError: Cannot add property x, object is not extensible (V8-based)
TypeError: Cannot define property x, object is not extensible (V8-based)
TypeError: can't define property "x": Object is not extensible (Firefox)
TypeError: Attempting to define property on object that is not extensible. (Safari)
```

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

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

 Usually, an object is extensible and new properties can be added to it. However, in
 this case `Object.preventExtensions()` marked an object as no longer
 extensible, so that it will never have properties beyond the ones it had at the time it
 was marked as non-extensible.

Examples
--------

### Adding new properties to a non-extensible objects

 In strict mode,
 attempting to add new properties to a non-extensible object throws a
 `TypeError`. In sloppy mode, the addition of the "x" property is silently
 ignored.


```js
"use strict";

const obj = {};
Object.preventExtensions(obj);

obj.x = "foo";
// TypeError: can't define property "x": Object is not extensible
```


 In both, strict mode and
 sloppy mode, a call to `Object.defineProperty()` throws when adding a new
 property to a non-extensible object.


```js
const obj = {};
Object.preventExtensions(obj);

Object.defineProperty(obj, "x", { value: "foo" });
// TypeError: can't define property "x": Object is not extensible
```


 To fix this error, you will either need to remove the call to
 `Object.preventExtensions()` entirely, or move it to a position so that the
 property is added earlier and only later the object is marked as non-extensible. Of
 course you can also remove the property that was attempted to be added, if you don't
 need it.


```js
"use strict";

const obj = {};
obj.x = "foo"; // add property first and only then prevent extensions

Object.preventExtensions(obj);
```

See also
--------

* `Object.preventExtensions()`
URIError: malformed URI sequence
================================

 The JavaScript exception "malformed URI sequence" occurs when URI encoding or decoding
 wasn't successful.

Message
-------
```

URIError: URI malformed (V8-based)
URIError: malformed URI sequence (Firefox)
URIError: String contained an illegal UTF-16 sequence. (Safari)
```

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

`URIError`What went wrong?
----------------

 URI encoding or decoding wasn't successful. An argument given to either the
 `decodeURI`, `encodeURI`, `encodeURIComponent`, or
 `decodeURIComponent` function was not valid, so that the function was unable
 encode or decode properly.

Examples
--------

### Encoding

 Encoding replaces each instance of certain characters by one, two, three, or four
 escape sequences representing the UTF-8 encoding of the character. An
 `URIError` will be thrown if there is an attempt to encode a surrogate which
 is not part of a high-low pair, for example:


```js
encodeURI("\uD800");
// "URIError: malformed URI sequence"

encodeURI("\uDFFF");
// "URIError: malformed URI sequence"
```


A high-low pair is OK. For example:


```js
encodeURI("\uD800\uDFFF");
// "%F0%90%8F%BF"
```

### Decoding

 Decoding replaces each escape sequence in the encoded URI component with the character
 that it represents. If there isn't such a character, an error will be thrown:


```js
decodeURIComponent("%E0%A4%A");
// "URIError: malformed URI sequence"
```


With proper input, this should usually look like something like this:


```js
decodeURIComponent("JavaScript\_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");
// "JavaScript\_шеллы"
```

See also
--------

* `URIError`
* `decodeURI`
* `encodeURI`
* `encodeURIComponent`
* `decodeURIComponent`
SyntaxError: missing ] after element list
=========================================

 The JavaScript exception "missing ] after element list" occurs when there is an error
 with the array initializer syntax somewhere. Likely there is a closing square bracket
 (`]`) or a comma (`,`) missing.

Message
-------
```

SyntaxError: missing ] after element list (Firefox)
SyntaxError: Unexpected token ';'. Expected either a closing ']' or a ',' following an array element. (Safari)
```

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

`SyntaxError`.

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

 There is an error with the array initializer syntax somewhere. Likely there is a
 closing square bracket (`]`) or a comma (`,`) missing.

Examples
--------

### Incomplete array initializer


```js
const list = [1, 2,

const instruments = [
  "Ukulele",
  "Guitar",
  "Piano",
};

const data = [{ foo: "bar" } { bar: "foo" }];
```


Correct would be:


```js
const list = [1, 2];

const instruments = ["Ukulele", "Guitar", "Piano"];

const data = [{ foo: "bar" }, { bar: "foo" }];
```

See also
--------

* `Array`
TypeError: "x" is not a non-null object
=======================================

 The JavaScript exception "is not a non-null object" occurs when an object is expected
 somewhere and wasn't provided. `null` is not an object and won't work.

Message
-------
```

TypeError: Property description must be an object: x (V8-based)
TypeError: Property descriptor must be an object, got "x" (Firefox)
TypeError: Property description must be an object. (Safari)

TypeError: Invalid value used in weak set (V8-based)
TypeError: WeakSet value must be an object, got "x" (Firefox)
TypeError: Attempted to add a non-object value to a WeakSet (Safari)
```

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

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

 An object is expected somewhere and wasn't provided. `null` is not an
 object and won't work. You must provide a proper object in the given situation.

Examples
--------

### Property descriptor expected

 When methods like `Object.create()` or
 `Object.defineProperty()` and `Object.defineProperties()` are
 used, the optional descriptor parameter expects a property descriptor object. Providing
 no object (like just a number), will throw an error:


```js
Object.defineProperty({}, "key", 1);
// TypeError: 1 is not a non-null object

Object.defineProperty({}, "key", null);
// TypeError: null is not a non-null object
```


A valid property descriptor object might look like this:


```js
Object.defineProperty({}, "key", { value: "foo", writable: false });
```

### WeakMap and WeakSet objects require object or symbol keys

`WeakMap` and `WeakSet` objects store object or symbol keys. You can't
 use other types as keys.


```js
const ws = new WeakSet();
ws.add("foo");
// TypeError: "foo" is not a non-null object
```


Use objects instead:


```js
ws.add({ foo: "bar" });
ws.add(window);
```

See also
--------

* `Object.create()`
* `Object.defineProperty()`
* `Object.defineProperties()`
* `WeakMap`
* `WeakSet`
SyntaxError: invalid regular expression flag "x"
================================================

The JavaScript exception "invalid regular expression flag" occurs when the flags in a regular expression contain any flag that is not one of: `d`, `g`, `i`, `m`, `s`, `u`, `v`, or `y`.

It may also be raised if the expression contains more than one instance of a valid flag.

Message
-------
```

SyntaxError: Invalid regular expression flags (V8-based)
SyntaxError: invalid regular expression flag x (Firefox)
SyntaxError: Invalid regular expression: invalid flags (Safari)
```

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

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

The regular expression contains invalid flags, or valid flags have been used more than once in the expression.

The valid (allowed) flags are `d`, `g`, `i`, `m`, `s`, `u`, `v`, and `y`. They are introduced in more detail in Regular expressions > Advanced searching with flags.

Examples
--------

 In a regular expression literal, which consists of a pattern enclosed between slashes, the flags are defined after the second slash.
 Regular expression flags can be used separately or together in any order.
 This syntax shows how to declare the flags using the regular expression literal:


```js
const re = /pattern/flags;
```


They can also be defined in the constructor function of the `RegExp` object (second parameter):


```js
const re = new RegExp("pattern", "flags");
```


Here is an example showing use of only correct flags.


```js
/foo/g;
/foo/gims;
/foo/uy;
```


Below is an example showing the use of some invalid flags `b`, `a` and `r`:


```js
/foo/bar;

// SyntaxError: invalid regular expression flag "b"
```


The code below is incorrect, because `W`, `e` and `b` are not valid flags.


```js
const obj = {
  url: /docs/Web,
};

// SyntaxError: invalid regular expression flag "W"
```


 An expression containing two slashes is interpreted as a regular expression literal.
 Most likely the intent was to create a string literal, using single or double quotes as shown below:


```js
const obj = {
  url: "/docs/Web",
};
```

See also
--------

* Regular expressions guide
SyntaxError: Unexpected '#' used outside of class body
======================================================

 The JavaScript exception "Unexpected '#' used outside of class body" occurs when a hash
 ("#") is encountered in an unexpected context, most notably
 outside of a class declaration.
 Hashes are valid at the beginning of a file as a hashbang comment,
 or inside of a class as part of a private field. You may encounter this error if you forget
 the quotation marks when trying to access a DOM identifier as well.

Message
-------
```

SyntaxError: Unexpected '#' used outside of class body.
```

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

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

 We encountered a `#` somewhere unexpected. This may be due to code moving around and no
 longer being part of a class, a hashbang comment found on a line other than the first
 line of a file, or accidentally forgetting the quotation marks around a DOM identifier.

Examples
--------

### Missing quotation marks

For each case, there might be something slightly wrong. For example


```js
document.querySelector(#some-element)
```


This can be fixed via


```js
document.querySelector("#some-element");
```

### Outside of a class


```js
class ClassWithPrivateField {
  #privateField;

  constructor() {}
}

this.#privateField = 42;
```


This can be fixed by moving the private field back into the class


```js
class ClassWithPrivateField {
  #privateField;

  constructor() {
    this.#privateField = 42;
  }
}
```

See also
--------

* `SyntaxError`
TypeError: invalid Array.prototype.sort argument
================================================

The JavaScript exception "invalid Array.prototype.sort argument" occurs when the argument of `Array.prototype.sort()` isn't either `undefined` or a function which compares its operands.

Message
-------
```

TypeError: The comparison function must be either a function or undefined (V8-based)
TypeError: invalid Array.prototype.sort argument (Firefox)
TypeError: Array.prototype.sort requires the comparator argument to be a function or undefined (Safari)
```

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

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

The argument of `Array.prototype.sort()` is expected to be either `undefined` or a function which compares its operands.

Examples
--------

### Invalid cases


```js
[1, 3, 2].sort(5); // TypeError
```

### Valid cases


```js
[1, 3, 2].sort(); // [1, 2, 3]
[1, 3, 2].sort((a, b) => a - b); // [1, 2, 3]
```

See also
--------

* `Array.prototype.sort()`
SyntaxError: unlabeled break must be inside loop or switch
==========================================================

The JavaScript exception "unlabeled break must be inside loop or switch" occurs when a `break` statement is not inside a loop or a `switch` statement.

Message
-------
```

SyntaxError: Illegal break statement (V8-based)
SyntaxError: unlabeled break must be inside loop or switch (Firefox)
SyntaxError: 'break' is only valid inside a switch or loop statement. (Safari)
```

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

`SyntaxError`.

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

`break` statements can be used to exit a loop or a `switch` statement, and using them elsewhere is a syntax error. Alternatively, you can provide a label to the `break` statement to break out of any statement with that label — however, if the label does not reference a containing statement, another error SyntaxError: label not found will be thrown.

Examples
--------

### Unsyntactic break

`break` cannot be used outside `switch` or loops.


```js
let score = 0;

function increment() {
  if (score === 100)
    break; // SyntaxError: unlabeled break must be inside loop or switch
  }
  score++;
}
```


Maybe instead of `break`, you intend to use `return` to early-terminate a function.


```js
let score = 0;

function increment() {
  if (score === 100) {
    return;
  }
  score++;
}
```

### Using break in callbacks

`break` cannot be used in callbacks, even if the callback is called from a loop.


```js
let containingIndex = 0;
const matrix = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
];

while (containingIndex < matrix.length) {
  matrix[containingIndex].forEach((value) => {
    if (value === 5) {
      break; // SyntaxError: unlabeled break must be inside loop or switch
    }
  });
  containingIndex++;
}
```


Instead, refactor the code so the `break` is used outside the callback.


```js
let containingIndex = 0;
const matrix = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
];

outer: while (containingIndex < matrix.length) {
  for (const value of matrix[containingIndex]) {
    if (value === 5) {
      break outer;
    }
  }
  containingIndex++;
}
```



```js
let containingIndex = 0;
const matrix = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
];

while (containingIndex < matrix.length) {
  if (matrix[containingIndex].includes(5)) {
    break;
  }
  containingIndex++;
}
```


There's no way to early-terminate a `forEach()` loop. You can use `some()` instead, or convert it to a `for...of` loop.


```js
array.forEach((value) => {
  if (value === 5) {
    break; // SyntaxError: unlabeled break must be inside loop or switch
  }
  // do something with value
});
```



```js
array.some((value) => {
  if (value === 5) {
    return true;
  }
  // do something with value
  return false;
});
```



```js
for (const value of array) {
  if (value === 5) {
    break;
  }
  // do something with value
}
```

See also
--------

* `break`