JavaScript is very flexible with regards to checking for "null" values. I'm guessing you're actually looking for empty strings, in which case this simpler code will work:

if(!pass || !cpass || !email || !cemail || !user){

Which will check for empty strings (""), null, undefined, false and the numbers 0 and NaN.

Please note that if you are specifically checking for numbers, it is a common mistake to miss 0 with this method, and num !== 0 is preferred (or num !== -1 or ~num (hacky code that also checks against -1)) for functions that return -1, e.g. indexOf).

Answer from user578895 on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › null
null - JavaScript | MDN
JavaScript is unique to have two nullish values: null and undefined. Semantically, their difference is very minor: undefined represents the absence of a value, while null represents the absence of an object. For example, the end of the prototype chain is null because the prototype chain is ...
Top answer
1 of 16
1093

JavaScript is very flexible with regards to checking for "null" values. I'm guessing you're actually looking for empty strings, in which case this simpler code will work:

if(!pass || !cpass || !email || !cemail || !user){

Which will check for empty strings (""), null, undefined, false and the numbers 0 and NaN.

Please note that if you are specifically checking for numbers, it is a common mistake to miss 0 with this method, and num !== 0 is preferred (or num !== -1 or ~num (hacky code that also checks against -1)) for functions that return -1, e.g. indexOf).

2 of 16
728

To check for null SPECIFICALLY you would use this:

if (variable === null)

This test will ONLY pass for null and will not pass for "", undefined, false, 0, or NaN.

Additionally, I've provided absolute checks for each "false-like" value (one that would return true for !variable).

Note, for some of the absolute checks, you will need to implement use of the absolutely equals: === and typeof.

I've created a JSFiddle here to show all of the individual tests working

Here is the output of each check:

Null Test:

if (variable === null)

- variable = ""; (false) typeof variable = string

- variable = null; (true) typeof variable = object

- variable = undefined; (false) typeof variable = undefined

- variable = false; (false) typeof variable = boolean

- variable = 0; (false) typeof variable = number

- variable = NaN; (false) typeof variable = number



Empty String Test:

if (variable === '')

- variable = ''; (true) typeof variable = string

- variable = null; (false) typeof variable = object

- variable = undefined; (false) typeof variable = undefined

- variable = false; (false) typeof variable = boolean

- variable = 0; (false) typeof variable = number

- variable = NaN; (false) typeof variable = number




Undefined Test:

if (typeof variable == "undefined")

-- or --

if (variable === undefined)

- variable = ''; (false) typeof variable = string

- variable = null; (false) typeof variable = object

- variable = undefined; (true) typeof variable = undefined

- variable = false; (false) typeof variable = boolean

- variable = 0; (false) typeof variable = number

- variable = NaN; (false) typeof variable = number



False Test:

if (variable === false)

- variable = ''; (false) typeof variable = string

- variable = null; (false) typeof variable = object

- variable = undefined; (false) typeof variable = undefined

- variable = false; (true) typeof variable = boolean

- variable = 0; (false) typeof variable = number

- variable = NaN; (false) typeof variable = number



Zero Test:

if (variable === 0)

- variable = ''; (false) typeof variable = string

- variable = null; (false) typeof variable = object

- variable = undefined; (false) typeof variable = undefined

- variable = false; (false) typeof variable = boolean

- variable = 0; (true) typeof variable = number

- variable = NaN; (false) typeof variable = number



NaN Test:

if (typeof variable == 'number' && !parseFloat(variable) && variable !== 0)

-- or --

if (isNaN(variable))

- variable = ''; (false) typeof variable = string

- variable = null; (false) typeof variable = object

- variable = undefined; (false) typeof variable = undefined

- variable = false; (false) typeof variable = boolean

- variable = 0; (false) typeof variable = number

- variable = NaN; (true) typeof variable = number

As you can see, it's a little more difficult to test against NaN;

People also ask

Is null false in JavaScript?
Null is not considered false in JavaScript, but it is considered falsy. This means that null is treated as if it’s false when viewed through boolean logic. However, this is not the same thing as saying null is false or untrue.
🌐
builtin.com
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
What is a null check?
In JavaScript, null represents an intentional absence of a value, indicating that a variable has been declared with a null value on purpose. On the other hand, undefined represents the absence of any object value that is unintentional. A null check determines whether a variable has a null value, meaning a valid instance of a type exists.
🌐
builtin.com
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
What is a strict null check?
StrictNullChecks is a feature that treats null and undefined as two separate types, reducing errors and making it easier to find coding bugs. It also has stronger measures for defining variables as null or undefined, ensuring variables are declared as null only when it’s safe to do so.
🌐
builtin.com
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › null-in-javascript
Null in JavaScript - GeeksforGeeks
June 5, 2024 - In JavaScript, `null` indicates the deliberate absence of any object value. It's a primitive value that denotes the absence of a value or serves as a placeholder for an object that isn't present.
🌐
Programiz
programiz.com › javascript › null-undefined
JavaScript null and undefined
Note: null is not the same as NULL or Null. In JavaScript, undefined and null are treated as false values.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › null
`null` in JavaScript - Mastering JS
The primary difference is purely semantic: undefined means the variable has not been assigned a value yet, whereas null means the variable has been explicitly defined as null. For most practical purposes, null and undefined are often interchangeable ...
🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-null
Everything about null in JavaScript
null in JavaScript is a special value that represents a missing object.
🌐
web.dev
web.dev › learn › javascript › data-types › null-undefined
null and undefined | web.dev
This page describes the two most common ways: the null and undefined data types. The null keyword represents an intentionally defined absence of value. null is a primitive, although the typeof operator returns that null is an object.
Find elsewhere
🌐
JavaScript Tutorial
javascripttutorial.net › home › an essential guide to javascript null
An Essential Guide to JavaScript null
September 29, 2020 - JavaScript null is a primitive type that contains a special value null.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
The JavaScript primitive type null represents an intentional absence of a value. It’s usually set on purpose to indicate that a variable has been declared but not yet assigned any value. null is different from the similar primitive value ...
Published   August 4, 2025
🌐
Matiashernandez
matiashernandez.dev › blog › post › como-revisar-si-un-string-es-vacio-o-null-en-javascript
¿Cómo revisar si un string es vacío o null en Javascript?
Ahora, que está claro que null y un string vacío no son lo mismo: Ya sabes que un string vació es efectivamente eso, un string que no contiene carácteres, para comprobar esto basta con utilizar el operador === ... ¿Pero que ocurre si el string contiene espacios en blanco? ¿Consideras estos “blanks” como un string vacío? En efecto, los espacios en blanco " " son caracteres por lo que la comparación no resultará.
🌐
Luis Llamas
luisllamas.es › inicio › cursos › curso javascript
What is null and undefined in JavaScript and how to use them
December 6, 2024 - That is to say, as we see, the difference between the two is that undefined is automatic, and null is explicit. undefined is a primitive value in JavaScript.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-check-for-null-in-javascript
JS Check for Null – Null Checking in JavaScript Explained
November 7, 2024 - Null and undefined are very similar in JavaScript and are both primitive types. A variable has the type of null if it intentionally contains the value of null. In contrast, a variable has the type of undefined when you declare it without initiating ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-check-for-null-values-in-javascript
How to check for null values in JavaScript ? - GeeksforGeeks
July 23, 2025 - This contrasts null from the similar primitive value undefined, which is an unintentional absence of any object value. That is because a variable that has been declared but not assigned any value is undefined, not null. ... By this operator, we will learn how to check for null values in JavaScript by the (===) operator.
🌐
Reddit
reddit.com › r/javascripttips › why does javascript have both null and undefined?
r/JavaScriptTips on Reddit: Why does JavaScript have both null and undefined?
November 11, 2022 -

Most programming languages have a single value to indicate the absence of something, which is often called null and is used to represent a variable that has no value associated with it.

But JavaScript is different. Someone who is just starting out with JavaScript or coming from a different language usually finds it hard to understand, why there are two values that indicate absence: null and undefined

Check out the post to learn how these two are different.

🌐
SheCodes
shecodes.io › athena › 142857-understanding-the-values-null-and-undefined-in-javascript
[JavaScript] - Understanding the values null and undefined in JavaScript
Black Friday Sale 🎉 30% off on ... 1st Ending in 5 days Get Deal Get This Deal NOW ... Learn the meaning of null and undefined in JavaScript and how they are used to represent the absence of a value. ... Write a function that takes in a single number. It should return the string even if the number is even, and ...
🌐
The Trevor Harmon
thetrevorharmon.com › blog › loose-null-checks-in-javascript
Loose null checks in JavaScript | The Trevor Harmon
I have observed that JavaScript ... this, like in the exec() method of the regular expression object). null indicates the intentional absence of a value....
🌐
CSS { In Real Life }
css-irl.info › handling-null-undefined-and-zero-values-in-javascript
CSS { In Real Life } | Handling Null, Undefined and Zero Values in JavaScript
javascript · Wed Nov 08 2023 · Day 8 of National Blog Posting Month #NaBloPoMo · In JS, it’s easy to get caught out when determining if a variable is null, undefined, or has a value of zero. I do a lot of data visualisation, and quite often I’ll need to filter out null values from an array of data.
🌐
Scaler
scaler.com › topics › javascript-check-null
JavaScript Program to Check for Null - Scaler Topics
December 14, 2022 - In JavaScript programming language, there is a primitive data type known as 'null', which represents the empty value inside a variable. Although there is one more data type known as 'undefined', it does not represents the null value.
🌐
Syncfusion
syncfusion.com › blogs › post › null-vs-undefined-in-javascript
Null vs. Undefined in JavaScript | Syncfusion Blogs
December 10, 2024 - The primitive type null indicates the intentional absence of a value. Therefore, in JavaScript, programmers often assign null to a variable to denote that the variable is declared and initialized and currently doesn’t hold a value.