JavaScript TypeError Object
A TypeError is thrown when a value isn't the type an operation expects, such as calling something that isn't a function or reading a property of undefined.
Description
A TypeError is the most common error in JavaScript. It is thrown when an operation is used on a value of the wrong type: calling a value that isn't a function, reading a property of undefined or null, assigning to a constant, or changing a frozen object in strict mode.
Messages such as "Cannot read properties of undefined" usually mean a variable or property you expected doesn't exist yet. The optional chaining operator ?. and checks with typeof help avoid them. You can also throw a TypeError yourself when a function receives an argument of the wrong type.
In strict mode, which applies to modules and classes, many silent failures become TypeErrors, such as writing to a read-only property or adding a property to a frozen object. Mixing BigInt and Number values in arithmetic, calling a class without new, and using new with an arrow function also throw one. Error messages differ between browsers, so check the type rather than the message text.
Creating
new TypeError(message)Example
Browser Support
The following information will show you the current browser support for the TypeError object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





