- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
TypeError: ‘undefined’ is not an object in JavaScript
The “TypeError: ‘undefined’ is not an object” error occurs when a property is accessed or a method is called on an undefined object. This error is shown only on safari browser.
Following is the code for TypeError − ‘undefined’ is not an object error in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color:blueviolet } </style> </head> <body> <h1>TypeError: ‘undefined’ is not an object example</h1> <div class="result"></div> <br /> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to access the name property of person object</h3> <script> var resEle = document.querySelector('.result'); var BtnEle = document.querySelector('.Btn'); var person; BtnEle.addEventListener('click',function(){ try{ alert(person.name); } catch(err){ resEle.innerHTML=err; } }); </script> </body> </html>
Output
On clicking the ‘CLICK HERE’ button −
- Related Articles
- What is the difference between undefined and not defined in JavaScript?
- What is Undefined X1 in JavaScript
- Undefined in JavaScript
- Sorting an array that contains undefined in JavaScript?
- What is "undefined x 1" in JavaScript?
- JavaScript undefined Property
- Undeclared vs Undefined? In JavaScript
- PHP TypeError
- Is their JavaScript “not in” operator for checking object properties?
- What is the difference between null and undefined in JavaScript?
- JavaScript - array undefined element count
- What is an Object Oriented Programming in JavaScript?
- How to find the biggest number in an array around undefined elements? - JavaScript
- What is the difference between JavaScript undefined and void(0)?
- Merge two objects in JavaScript ignoring undefined values

Advertisements