- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
How to check if a variable exists in JavaScript?
To check if a variable exists in JavaScript, you need to check it against null as in the following code. Here, we’re checking the existence of variable myVar −
<html> <body> <script> var myVar = 20; if(myVar !== undefined && myVar !== null) { document.write("Variable exists"); } </script> </body> </html>
Advertisements