

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 for null, undefined, or blank variables in JavaScript?
On getting the result of the following, you can find whether a variable is null or undefined. If the result is “false”, it means the variable is null and undefined.
Here, the variable results in “True” −
<html> <body> <script> var age = 10; if(age){ document.write("True"); } else{ document.write("False"); } </script> </body> </html>
Use “typeof” to check whether a variable exists or not −
<html> <body> <script> var age = 10; if( typeof age !== 'undefined' ) { document.write("True"); } else{ document.write("False"); } </script> </body> </html>
- Related Questions & Answers
- Is there is a standard function to check for null, undefined, or blank variables in JavaScript?
- How to check for 'undefined' or 'null' in a JavaScript array and display only non-null values?
- How to remove blank (undefined) elements from JavaScript array - JavaScript
- Replace a value if null or undefined in JavaScript?
- How to check for “undefined” variable in JavaScript?
- MySQL update column to NULL for blank values
- Check for NULL or NOT NULL values in a column in MySQL
- How do I check for null values in JavaScript?
- How to skip blank and null values in MySQL?
- How to determine if a variable is 'undefined' or 'null'?
- C# Program to check a string for whitespace characters or null
- What is the difference between null and undefined in JavaScript?
- Check for null in MongoDB?
- Compute the sum of elements of an array which can be null or undefined JavaScript
- Check for NULL or empty variable in a MySQL stored procedure
Advertisements