is not defined
JavaScript Programming Language
Severity: ModerateWhat Does This Error Mean?
This error means JavaScript encountered a name it has never heard of. The variable, function, or object you are trying to use has not been declared anywhere in the current scope. JavaScript searches for the name, cannot find it, and stops with this error.
Affected Models
- All browsers
- Node.js
- Deno
- Any JavaScript runtime
Common Causes
- A variable name is misspelled — JavaScript is case-sensitive
- The variable was declared in a different file that was not loaded
- The variable was declared inside a function and is being used outside it
- A library (like jQuery or React) was not imported before your code tries to use it
- The variable declaration was deleted or accidentally removed from the code
How to Fix It
-
Read the full error message. It will name the exact variable or function that is not defined. Check for spelling mistakes — including wrong capitalization.
Example: if you wrote Consolee.log() instead of console.log(), JavaScript will say 'Consolee is not defined'.
-
Search your entire codebase for where that variable or function should be declared. Use Ctrl+F in your editor to search all open files.
Look for let, const, var, or function declarations with that name.
-
If the variable is in a different JavaScript file, make sure that file is loaded first. In HTML, the script tag for the file with the declaration must come before the script tag that uses it.
Script files load in order. If file-b.js uses a variable from file-a.js, file-a.js must be listed first.
-
If the variable is inside a function, it only exists inside that function. Move the declaration outside the function if it needs to be used elsewhere.
Variables declared with let or const inside {} curly braces are only available within those braces.
-
If the error says something like '$ is not defined' or 'React is not defined', make sure you have imported or included the library correctly.
For jQuery: make sure the jQuery script tag is above your code. For React: make sure import React from 'react'; is at the top of the file.
When to Call a Professional
This is a very common error that every JavaScript developer encounters. It does not require professional help — just careful checking of spelling, scope, and file loading order. If you are working in a large project with many files, ask a teammate to help trace where the variable should come from.
Frequently Asked Questions
Why does 'is not defined' and ReferenceError mean the same thing?
They do — 'X is not defined' is the message inside a ReferenceError. JavaScript throws a ReferenceError and puts 'is not defined' in the message to tell you which name it could not find. Some developers search for 'ReferenceError' and others search for 'is not defined' — both lead to the same problem and fix.
I declared the variable but still get this error. Why?
The most likely reason is scope — the variable is declared inside a block or function that is not accessible from where you are using it. Another reason is that the file containing the declaration is not loaded yet. Also double-check the exact spelling — myVariable and MyVariable are completely different names in JavaScript.
Can I declare a global variable to fix this?
You can, but it is not considered good practice. Global variables can be accidentally overwritten by other code and make bugs harder to track. A better approach is to organize your code so the variable is in the right scope, or use JavaScript modules to share values between files cleanly.