Get to know MDN better
The JavaScript strict mode-only exception "is read-only" occurs when a global variable or object property that was assigned to is a read-only property.
TypeError in strict mode only.
The global variable or object property that was assigned to is a read-only property. (Technically, it is a non-writable data property.)
This error happens only in strict mode code. In non-strict code, the assignment is silently ignored.
Read-only properties are not super common, but they can be created using Object.defineProperty() or Object.freeze().
There are also a few read-only properties built into JavaScript. Maybe you tried to redefine a mathematical constant.
Sorry, you can't do that.
The global variable undefined is also read-only, so you can't silence the infamous "undefined is not a function" error by doing this:
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.