JavaScript ReferenceError: x is not defined
A plain-words explanation of this JavaScript message: what it means, the usual causes, and the steps that fix it.
The messageUncaught ReferenceError: totl is not defined
Make the error yourself
Run in Google Chrome 157.0.8103.51. This is the smallest example we could find that shows it.
JavaScript (in a script tag)
const total = 10 + 5;
console.log(totl);Browser console (the real message)
ReferenceError: totl is not definedWhy it happens
JavaScript looked for a variable or function with that name in the current scope and in every outer scope, and did not find one. The most common causes are a typo (totl), using a variable outside the block or function where it was declared with let or const, using it before it is declared, forgetting to load the script or library that defines it, and a misspelt library name such as $ when jQuery did not load. In a browser, a missing <script> tag or a failed download gives exactly this error.
How to fix it
- Compare the name in the message with where you declared it, letter by letter and with capitals.
- Move the declaration so that it is in an outer scope, or return the value from the function.
- If the name belongs to a library (
$,axios,moment), open the Network tab and make sure its script loaded before your code, and that the order of the<script>tags is right. - In modules, make sure you
importthe name.
The corrected version
JavaScript (in a script tag)
const total = 10 + 5;
console.log(total);Browser console (the corrected version)
15How to avoid it
Turn on a linter such as ESLint with the no-undef rule, or use TypeScript, which finds unknown names before the page runs.
Questions
Why does the same name work in the console but not in my script?
The console can see variables from the page's global scope. Your script may be inside a function or a module, where they are not visible.
This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.