Why does an old script throw errors in a modern browser?
An old script usually throws errors in a modern browser for one of five reasons: it runs before its elements exist, needs a library that is not loaded, calls something the browser lacks, runs in strict mode or as a module, or is blocked by a security rule. The first console error tells you which.
Cite
CodeLifter Forum, "Why does an old script throw errors in a modern browser?", https://codelifter.com/forum/posts/why-does-an-old-script-throw-errors-in-a-modern-browser/, accessed 2026-12-02.- CodeLifter editorsStaffStaff, CodeLifter ·
How do you read the error?
Open the developer tools, switch to the Console tab and reload the page. Fix the first red error first: one early failure often stops the rest of the script, so later errors may disappear once it is fixed.
Each error line gives three things:
- The type, such as
TypeError,ReferenceErrororSyntaxError. Defined in one sentence each: aTypeErrormeans a value was the wrong kind, oftennullorundefined; aReferenceErrormeans a name does not exist where the code looks for it; aSyntaxErrormeans the code could not be parsed at all, so none of that script ran. - The message, which names the value or property involved.
- The file and line, as a link. Chrome's Console reference explains that you can expand an error to see its stack trace, "a history of function calls (frames) that led to the error", with the latest frame at the top.
Wording differs by browser. MDN's error reference pages list each engine's version, so search MDN for the message if it is unfamiliar.
What do the common errors mean in an old script?
Error (Chrome wording first) Usual cause in an old script Fix TypeError: Cannot read properties of nullorof undefinedgetElementById()found nothing: the script runs in the<head>before the element exists, or the id's case does not matchLoad the script with defer; check the id; test fornullbefore useReferenceError: $ is not definedjQuery or another library is missing, or loads after the script that uses it Load the library first, in order ReferenceError: x is not definedThe script calls a function or object from a file that is no longer included, or a name only an old browser had Find where it was defined; replace browser-only names with standard APIs TypeError: x is not a functionThe method does not exist on that object in this browser, or the name has a typo Check MDN for the method; test for it before calling ReferenceError: x is not definedon an assignment, only in strict codeA variable was never declared, and the file is now in strict mode or a module Declare it with constorletSyntaxErrorin a file that used to runStrict mode or a module rejects withstatements and old octal numbers such as0644Rewrite those lines Sources for each row: MDN's pages on "x" is (not) "y", "x" is not defined, "x" is not a function, assignment to undeclared variable and strict mode.
Why do these show up now, when the script used to work?
The page around it changed. Old snippets were pasted inline at the exact spot in the body where they were needed. Move one into a file in the
<head>anddocument.getElementById("menu")runs before<div id="menu">has been parsed, so it returnsnull. MDN's getElementById page also notes the id is case-sensitive:"Main"does not findid="main". Addingdeferfixes the first case; MDN's script reference says deferred scripts run "after the document has been parsed".The script is now strict. If you added
"use strict";, or loaded the file withtype="module", sloppy habits become errors. MDN's strict mode page says it "makes it impossible to accidentally create global variables": in Firefox the message isassignment to undeclared variable, while Chrome reports it asx is not defined. The same page says strict mode "prohibitswith" and makes 0-prefixed octal literals a syntax error. Modules are always strict, and their names are not global, so inlineonclick="..."handlers that call them fail too; the modernising thread covers that switch.The script relied on old browser behaviour. Some snippets read a global
eventinside handlers. MDN's Window.event page marks it deprecated, says it "is not universally supported", and tells you to use theEventpassed into the handler instead.document.allis also deprecated; MDN suggestsdocument.querySelectorAll("*")where you need every element.Something else is blocking it. A blocked script often produces no JavaScript error at all, only a console warning.
document.write()calls are ignored fromasyncanddeferscripts, which the document.write thread covers. Popups fromwindow.open()returnnullwhen blocked, and code that then uses the result throws aTypeError; see the popup replacement thread. A Content Security Policy refuses inline scripts andeval(), which a follow-up on the old tutorial scripts thread explains, andhttp://script links are blocked as mixed content on HTTPS pages.A repeatable way to fix it
- Save the page and script locally and serve the folder, for example with
python3 -m http.server 8000 --bind 127.0.0.1, so the browser treats it like a real site. - Reload with the Console open and click the first error's file link to jump to the line.
- Set a breakpoint on that line in the Sources panel, reload, and inspect the value that is
null,undefinedor missing. - Fix that one cause, reload, and repeat until the console is clean.
- Then read the warnings, not only the errors. The thread on whether old scripts still work has a table of patterns that fail silently.

The five-step fix loop for old script errors, as given in this article If the fix list is long, consider whether the script is still worth keeping. The Script Shelf shows which old CodeLifter scripts were rewritten, replaced by the platform, or retired.
Short version
- Read the first console error: its type, message and line point to the cause.
nullerrors usually mean the script ran before its element existed; load it withdefer.not definederrors mean a missing library, a missing file, or a name from an old browser.- Strict mode and modules turn undeclared variables,
withand old octal numbers into errors. - Blocked features often log warnings, not errors, so read those too.
- The type, such as
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.