pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Undeclared_var

rity="low" />

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?

You have an assignment of the form x = ..., but x has not been previously declared with the var, let, or const keyword. This error occurs in strict mode code only. In non-strict code, assignment to an undeclared variable implicitly creates a property on the global scope.

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

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy