recursal/MDN huggingface dataset:
SyntaxError: function statement requires a name
===============================================

 The JavaScript exception "function statement requires a name" occurs
 when there is a function statement
 in the code that requires a name.

Message
-------
```

SyntaxError: Function statements require a function name (V8-based)
SyntaxError: function statement requires a name (Firefox)
SyntaxError: Function statements must have a name. (Safari)
```

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

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

 There is a function statement in the code that requires a name.
 You'll need to check how functions are defined and if you need to provide a name for it, or if the function in question needs to be a function expression, an IIFE, or if the function code is placed correctly in this context at all.

Examples
--------

### Statements vs. expressions

 A *function statement* (or *function declaration*) requires a name.
 This won't work:


```js
function () {
  return "Hello world";
}
// SyntaxError: function statement requires a name
```


You can use a function expression (assignment) instead:


```js
const greet = function () {
  return "Hello world";
};
```


If your function is intended to be an IIFE (Immediately Invoked Function Expression, which is a function that runs as soon as it is defined) you will need to add a few more braces:


```js
(function () {
  // …
})();
```

### Labeled functions

Labels are an entirely different feature from function names. You can't use a label as a function name.


```js
function Greeter() {
  german: function () {
    return "Moin";
  }
}
// SyntaxError: function statement requires a name
```


In addition, labeled function declarations themselves are a deprecated feature. Use regular function declarations instead.


```js
function Greeter() {
  function german() {
    return "Moin";
  }
}
```

### Object methods

 If you intended to create a method of an object, you will need to create an object.
 The following syntax without a name after the `function` keyword is valid then.


```js
const greeter = {
  german: function () {
    return "Moin";
  },
};
```


You can also use the method syntax.


```js
const greeter = {
  german() {
    return "Moin";
  },
};
```

### Callback syntax

 Also, check your syntax when using callbacks.
 Braces and commas can quickly get confusing.


```js
promise.then(
  function () {
    console.log("success");
  });
  function () {
    console.log("error");
}
// SyntaxError: function statement requires a name
```


Correct would be:


```js
promise.then(
  function () {
    console.log("success");
  },
  function () {
    console.log("error");
  },
);
```

See also
--------

* Functions guide
* `function`
* `function` expression
* IIFE
* Labeled statement
SyntaxError: unparenthesized unary expression can't appear on the left-hand side of '\*\*'
==========================================================================================

The JavaScript exception "unparenthesized unary expression can't appear on the left-hand side of '\*\*'" occurs when a unary operator (one of `typeof`, `void`, `delete`, `await`, `!`, `~`, `+`, `-`) is used on the left operand of the exponentiation operator without parentheses.

Message
-------
```

SyntaxError: Unary operator used immediately before exponentiation expression. Parenthesis must be used to disambiguate operator precedence (V8-based)
SyntaxError: unparenthesized unary expression can't appear on the left-hand side of '**' (Firefox)
SyntaxError: Unexpected token '**'. Ambiguous unary expression in the left hand side of the exponentiation expression; parentheses must be used to disambiguate the expression. (Safari)
```

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

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

You likely wrote something like this:


```js
-a \*\* b
```


Whether it should be evaluated as `(-a) ** b` or `-(a ** b)` is ambiguous. In mathematics, -x2 means `-(x ** 2)` — and that's how many languages, including Python, Haskell, and PHP, handle it. But making the unary minus operator take precedence over `**` breaks symmetry with `a ** -b`, which is unambiguously `a ** (-b)`. Therefore, the language forbids this syntax and requires you to parenthesize either side to resolve the ambiguity.


```js
(-a) \*\* b
-(a \*\* b)
```


Other unary operators cannot be the left-hand side of exponentiation either.


```js
await a \*\* b
!a \*\* b
+a \*\* b
~a \*\* b
```

Examples
--------

When writing complex math expressions involving exponentiation, you may write something like this:


```js
function taylorSin(x) {
  return (n) => (-1 \*\* n \* x \*\* (2 \* n + 1)) / factorial(2 \* n + 1);
  // SyntaxError: unparenthesized unary expression can't appear on the left-hand side of '\*\*'
}
```


However, the `-1 ** n` part is illegal in JavaScript. Instead, parenthesize the left operand:


```js
function taylorSin(x) {
  return (n) => ((-1) \*\* n \* x \*\* (2 \* n + 1)) / factorial(2 \* n + 1);
}
```


This also makes the code's intent much clearer to other readers.

See also
--------

* Exponentiation (`**`)
* Operator precedence
* Original discussion of exponentiation operator precedence on esdiscuss.org
TypeError: "x" is (not) "y"
===========================

 The JavaScript exception "*x* is (not) *y*" occurs when there was an
 unexpected type. Oftentimes, unexpected `undefined` or `null`
 values.

Message
-------
```

TypeError: Cannot read properties of undefined (reading 'x') (V8-based)
TypeError: "x" is undefined (Firefox)
TypeError: "undefined" is not an object (Firefox)
TypeError: undefined is not an object (evaluating 'obj.x') (Safari)

TypeError: "x" is not a symbol (V8-based & Firefox)
TypeError: Symbol.keyFor requires that the first argument be a symbol (Safari)
```

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

`TypeError`.

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

 There was an unexpected type. This occurs oftentimes with `undefined` or
 `null` values.

 Also, certain methods, such as `Object.create()` or
 `Symbol.keyFor()`, require a specific type, that must be provided.

Examples
--------

### Invalid cases

You cannot invoke a method on an `undefined` or `null` variable.


```js
const foo = undefined;
foo.substring(1); // TypeError: foo is undefined

const foo2 = null;
foo2.substring(1); // TypeError: foo is null
```


Certain methods might require a specific type.


```js
const foo = {};
Symbol.keyFor(foo); // TypeError: foo is not a symbol

const foo2 = "bar";
Object.create(foo2); // TypeError: "foo" is not an object or null
```

### Fixing the issue

To fix null pointer to `undefined` or `null` values, you can test if the value is `undefined` or `null` first.


```js
if (foo !== undefined && foo !== null) {
  // Now we know that foo is defined, we are good to go.
}
```


Or, if you are confident that `foo` will not be another falsy value like `""` or `0`, or if filtering those cases out is not an issue, you can simply test for its truthiness.


```js
if (foo) {
  // Now we know that foo is truthy, it will necessarily not be null/undefined.
}
```

See also
--------

* `undefined`
* `null`
TypeError: cannot use 'in' operator to search for 'x' in 'y'
============================================================

 The JavaScript exception "right-hand side of 'in' should be an object" occurs when the
 `in` operator
 was used to search in strings, or in numbers, or other primitive types. It can only be
 used to check if a property is in an object.

Message
-------
```

TypeError: Cannot use 'in' operator to search for 'x' in 'y' (V8-based & Firefox)
TypeError: right-hand side of 'in' should be an object, got null (Firefox)
TypeError: "y" is not an Object. (evaluating '"x" in "y"') (Safari)
```

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

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

 The `in` operator can only be used
 to check if a property is in an object.
 You can't search in strings, or in numbers, or other primitive types.

Examples
--------

### Searching in strings

 Unlike in other programming languages (e.g. Python), you can't search in strings using
 the `in` operator.


```js
"Hello" in "Hello World";
// TypeError: cannot use 'in' operator to search for 'Hello' in 'Hello World'
```


Instead you will need to use `String.prototype.includes()`, for example.


```js
"Hello World".includes("Hello");
// true
```

### The operand can't be null or undefined

 Make sure the object you are inspecting isn't actually `null` or
 `undefined`.


```js
const foo = null;
"bar" in foo;
// TypeError: cannot use 'in' operator to search for 'bar' in 'foo' (Chrome)
// TypeError: right-hand side of 'in' should be an object, got null (Firefox)
```


The `in` operator always expects an object.


```js
const foo = { baz: "bar" };
"bar" in foo; // false

"PI" in Math; // true
"pi" in Math; // false
```

### Searching in arrays

 Be careful when using the `in` operator to search in `Array`
 objects. The `in` operator checks the index number, not the value at that
 index.


```js
const trees = ["redwood", "bay", "cedar", "oak", "maple"];
3 in trees; // true
"oak" in trees; // false
```

See also
--------

* `in`
Error: Permission denied to access property "x"
===============================================

 The JavaScript exception "Permission denied to access property" occurs when there was
 an attempt to access an object for which you have no permission.

Message
-------
```

DOMException: Blocked a frame with origin "x" from accessing a cross-origin frame. (Chromium-based)
DOMException: Permission denied to access property "x" on cross-origin object (Firefox)
SecurityError: Blocked a frame with origin "x" from accessing a cross-origin frame. Protocols, domains, and ports must match. (Safari)
```

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

`DOMException`.

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

 There was attempt to access an object for which you have no permission. This is likely
 an `<iframe>` element loaded from a different domain for which you
 violated the same-origin policy.

Examples
--------

### No permission to access document


```html
<!doctype html>
<html lang="en-US">
  <head>
    <iframe
 id="myframe"
 src="http://www1.w3c-test.org/common/blank.html"></iframe>
    <script>
 onload = function () {
 console.log(frames[0].document);
 // Error: Permission denied to access property "document"
 };
 </script>
  </head>
  <body></body>
</html>
```

See also
--------

* `<iframe>`
* Same-origin policy
SyntaxError: missing : after property id
========================================

 The JavaScript exception "missing : after property id" occurs when objects are created
 using the object initializer syntax.
 A colon (`:`) separates keys and values for the
 object's properties. Somehow, this colon is missing or misplaced.

Message
-------
```

SyntaxError: Invalid shorthand property initializer (V8-based)
SyntaxError: missing : after property id (Firefox)
SyntaxError: Unexpected token '='. Expected a ':' following the property name 'x'. (Safari)
SyntaxError: Unexpected token '+'. Expected an identifier as property name. (Safari)
```

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

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

 When creating objects with the object initializer syntax,
 a colon (`:`) separates keys and values for the object's properties.


```js
const obj = { propertyKey: "value" };
```

Examples
--------

### Colons vs. equal signs

 This code fails, as the equal sign can't be used this way in this object initializer
 syntax.


```js
const obj = { propertyKey = "value" };
// SyntaxError: missing : after property id
```


 Correct would be to use a colon, or to use square brackets to assign a new property
 after the object has been created already.


```js
const obj = { propertyKey: "value" };
```


Or alternatively:


```js
const obj = {};
obj.propertyKey = "value";
```

### Computed properties

 If you create a property key from an expression, you need to use square brackets.
 Otherwise the property name can't be computed:


```js
const obj = { "b"+"ar": "foo" };
// SyntaxError: missing : after property id
```


Put the expression in square brackets `[]`:


```js
const obj = { ["b" + "ar"]: "foo" };
```

See also
--------

* Object initializer
SyntaxError: Unexpected token
=============================

 The JavaScript exceptions "unexpected token" occur when a specific language construct
 was expected, but something else was provided. This might be a simple typo.

Message
-------
```

SyntaxError: expected expression, got "x"
SyntaxError: expected property name, got "x"
SyntaxError: expected target, got "x"
SyntaxError: expected rest argument name, got "x"
SyntaxError: expected closing parenthesis, got "x"
SyntaxError: expected '=>' after argument list, got "x"
```

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

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

 A specific language construct was expected, but something else was provided. This might
 be a simple typo.

Examples
--------

### Expression expected

For example, when chaining expressions, trailing commas are not allowed.


```js
for (let i = 0; i < 5,; ++i) {
  console.log(i);
}
// Uncaught SyntaxError: expected expression, got ';'
```


Correct would be omitting the comma or adding another expression:


```js
for (let i = 0; i < 5; ++i) {
  console.log(i);
}
```

### Not enough parentheses

Sometimes, you leave out parentheses around `if` statements:


```js
function round(n, upperBound, lowerBound) {
  if (n > upperBound) || (n < lowerBound) { // Not enough parenthese here!
    throw new Error(`Number ${n} is more than ${upperBound} or less than ${lowerBound}`);
  } else if (n < (upperBound + lowerBound) / 2) {
    return lowerBound;
  } else {
    return upperBound;
  }
} // SyntaxError: expected expression, got '||'
```


 The parentheses may look correct at first, but note how the `||` is outside the
 parentheses. Correct would be putting parentheses around the `||`:


```js
function round(n, upperBound, lowerBound) {
  if ((n > upperBound) || (n < lowerBound)) {
    throw new Error(
      `Number ${n} is more than ${upperBound} or less than ${lowerBound}`,
    );
  } else if (n < (upperBound + lowerBound) / 2) {
    return lowerBound;
  } else {
    return upperBound;
  }
}
```

See also
--------

* `SyntaxError`
TypeError: setting getter-only property "x"
===========================================

 The JavaScript strict mode-only exception "setting getter-only property" occurs when there is an attempt
 to set a new value to a property for which only a getter is specified.

Message
-------
```

TypeError: Cannot set property x of #<Object> which has only a getter (V8-based)
TypeError: setting getter-only property "x" (Firefox)
TypeError: Attempted to assign to readonly property. (Safari)
```

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

`TypeError` in strict mode only.

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

 There is an attempt to set a new value to a property for which only a getter is specified.
 While this will be silently ignored in non-strict mode, it will throw a
 `TypeError` in strict mode.

Examples
--------

### Property with no setter

 The example below shows how to set a getter for a property.
 It doesn't specify a setter, so a
 `TypeError` will be thrown upon trying to set the `temperature`
 property to `30`. For more details see also the
 `Object.defineProperty()` page.


```js
"use strict";

function Archiver() {
  const temperature = null;
  Object.defineProperty(this, "temperature", {
    get() {
      console.log("get!");
      return temperature;
    },
  });
}

const arc = new Archiver();
arc.temperature; // 'get!'

arc.temperature = 30;
// TypeError: setting getter-only property "temperature"
```


 To fix this error, you will either need to remove line 16, where there is an attempt to
 set the temperature property, or you will need to implement a setter for it, for
 example like this:


```js
"use strict";

function Archiver() {
  let temperature = null;
  const archive = [];

  Object.defineProperty(this, "temperature", {
    get() {
      console.log("get!");
      return temperature;
    },
    set(value) {
      temperature = value;
      archive.push({ val: temperature });
    },
  });

  this.getArchive = function () {
    return archive;
  };
}

const arc = new Archiver();
arc.temperature; // 'get!'
arc.temperature = 11;
arc.temperature = 13;
arc.getArchive(); // [{ val: 11 }, { val: 13 }]
```

See also
--------

* `Object.defineProperty()`
* `Object.defineProperties()`
SyntaxError: applying the 'delete' operator to an unqualified name is deprecated
================================================================================

The JavaScript strict mode-only exception "applying the 'delete' operator to an unqualified name is deprecated" occurs when variables are attempted to be deleted using the `delete` operator.

Message
-------
```

SyntaxError: Delete of an unqualified identifier in strict mode. (V8-based)
SyntaxError: applying the 'delete' operator to an unqualified name is deprecated (Firefox)
SyntaxError: Cannot delete unqualified property 'a' in strict mode. (Safari)
```

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

`SyntaxError` in strict mode only.

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

Normal variables in JavaScript can't be deleted using the `delete` operator. In strict mode, an attempt to delete a variable will throw an error and is not allowed.

The `delete` operator can only delete properties on an object. Object properties are "qualified" if they are configurable.

Unlike what common belief suggests, the `delete` operator has **nothing** to do with directly freeing memory. Memory management is done indirectly via breaking references, see the memory management page and the `delete` operator page for more details.

This error only happens in strict mode code. In non-strict code, the operation just returns `false`.

Examples
--------

### Freeing the contents of a variable

Attempting to delete a plain variable throws an error in strict mode:


```js
"use strict";

var x;

// …

delete x;

// SyntaxError: applying the 'delete' operator to an unqualified name
// is deprecated
```


To free the contents of a variable, you can set it to `null`:


```js
"use strict";

var x;

// …

x = null;

// x can be garbage collected
```

See also
--------

* `delete`
* Memory management
* TypeError: property "x" is non-configurable and can't be deleted
SyntaxError: unterminated string literal
========================================

 The JavaScript error "unterminated string literal" occurs when there is an unterminated
 string literal somewhere. String literals must be enclosed by single
 (`'`) or double (`"`) quotes.

Message
-------
```

SyntaxError: Unterminated string constant (Edge)
SyntaxError: unterminated string literal (Firefox)
```

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

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

 There is an unterminated
 string literal somewhere. String literals must be
 enclosed by single (`'`) or double (`"`) quotes. JavaScript makes
 no distinction between single-quoted strings and double-quoted strings.
 Escape sequences work
 in strings created with either single or double quotes.
 To fix this error, check if:

* you have opening and closing quotes (single or double) for your string literal,
* you have escaped your string literal correctly,
* your string literal isn't split across multiple lines.
Examples
--------

### Multiple lines

You can't split a string across multiple lines like this in JavaScript:


```js
const longString = "This is a very long string which needs
                    to wrap across multiple lines because
                    otherwise my code is unreadable.";
// SyntaxError: unterminated string literal
```


 Instead, use the + operator,
 a backslash, or template literals.
 The `+` operator variant looks like this:


```js
const longString =
  "This is a very long string which needs " +
  "to wrap across multiple lines because " +
  "otherwise my code is unreadable.";
```


 Or you can use the backslash character ("\") at the end of each line to indicate that
 the string will continue on the next line. Make sure there is no space or any other
 character after the backslash (except for a line break), or as an indent; otherwise it
 will not work. That form looks like this:


```js
const longString =
  "This is a very long string which needs \
to wrap across multiple lines because \
otherwise my code is unreadable.";
```


Another possibility is to use template literals.


```js
const longString = `This is a very long string which needs 
to wrap across multiple lines because 
otherwise my code is unreadable.`;
```

See also
--------

* string literal
* Template literals
ReferenceError: reference to undefined property "x"
===================================================

 The JavaScript warning "reference to undefined property" occurs when a script attempted
 to access an object property which doesn't exist.

Message
-------
```

ReferenceError: reference to undefined property "x" (Firefox)
```

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

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

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

 The script attempted to access an object property which doesn't exist. There are two
 ways to access properties; see the property accessors reference page to learn more about them.

Examples
--------

### Invalid cases

 In this case, the property `bar` is an undefined property, so a
 `ReferenceError` will occur.


```js
const foo = {};
foo.bar; // ReferenceError: reference to undefined property "bar"
```

### Valid cases

 To avoid the error, you need to either add a definition for `bar` to the
 object or check for the existence of the `bar` property before trying to
 access it; ways to do that include using the `in` operator,
 or the `Object.hasOwn()` method, like this:


```js
const foo = {};

// Define the bar property

foo.bar = "moon";
console.log(foo.bar); // "moon"

// Test to be sure bar exists before accessing it

if (Object.hasOwn(foo, "bar")) {
  console.log(foo.bar);
}
```

See also
--------

* Property accessors
TypeError: "x" has no properties
================================

 The JavaScript exception "null (or undefined) has no properties" occurs when you
 attempt to access properties of `null` and `undefined`. They
 don't have any.

Message
-------
```

TypeError: Cannot read properties of undefined (reading 'x') (V8-based)
TypeError: null has no properties (Firefox)
TypeError: undefined has no properties (Firefox)
TypeError: undefined is not an object (evaluating 'undefined.x') (Safari)
```

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

`TypeError`.

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

 Both `null` and `undefined`, have no properties you could
 access.

Examples
--------

### null and undefined have no properties


```js
null.foo;
// TypeError: null has no properties

undefined.bar;
// TypeError: undefined has no properties
```

See also
--------

* `null`
* `undefined`