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
🌐
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 a value. // This is null let firstName = null; // This is undefined let lastName;
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › null
null - JavaScript | MDN
October 28, 2025 - 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.
Discussions

How do I check for null values in JavaScript? - Stack Overflow
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats. Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... How can I check for null values in JavaScript... More on stackoverflow.com
🌐 stackoverflow.com
Why does JavaScript have both null and undefined?
Null is a defined value, while undefine is not. This link can help explain why null was created in JS: https://flexiple.com/javascript/undefined-vs-null-javascript/ More on reddit.com
🌐 r/JavaScriptTips
2
12
November 11, 2022
Could someone explain why "" != null? - JavaScript - SitePoint Forums | Web Development & Design Community
Where I tried to find out if field is empty and I checked against null, where it failed, then I replaced it with "" (nothing) and it started working as intended… why does null not work? ... I’m not really into javascript, but in php "" is setting the variable to an empty string, with emphasis ... More on sitepoint.com
🌐 sitepoint.com
0
October 14, 2016
What is the difference between null and ""?
What is the difference between “” and null in Javascript? I have always thought that “” === null. But this question says there are 5 falsy values, i.e. false , null , 0 , "" , undefined , and NaN . Hence, I am wondering if there if there might be difference between the two More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
September 6, 2022
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.
🌐
W3Schools
w3schools.com › typescript › typescript_null.php
TypeScript Null & Undefined
Optional chaining is a JavaScript feature that works well with TypeScript's null handling. It allows accessing properties on an object that may or may not exist, using compact syntax. It can be used with the ?. operator when accessing properties. interface House { sqft: number; yard?: { sqft: number; }; } function printYardSize(house: House) { const yardSize = house.yard?.sqft; if (yardSize === undefined) { console.log('No yard'); } else { console.log(`Yard is ${yardSize} sqft`); } } let home: House = { sqft: 500 }; printYardSize(home); // Prints 'No yard' Try it Yourself »
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;

🌐
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
🌐
ServiceNow Community
servicenow.com › community › in-other-news › undefined-null-and-oh-my › ba-p › 2291977
undefined, null, ==, !=, ===, and !== - Oh My! - ServiceNow Community
June 3, 2024 - The null is the absence of a reference in a reference. If you're of a certain age, you might naturally think of this as pointer containing a zero — a pointer that points to nothing. JavaScript's use of null is generally consistent with this, with one exception that I know of — if you execute ...
🌐
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.

🌐
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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Glossary › Null
Null - Glossary | MDN
July 11, 2025 - In JavaScript, null is marked as one of the primitive values, because its behavior is seemingly primitive.
🌐
Medium
medium.com › weekly-webtips › null-and-undefined-in-javascript-d9bc18acdaff
Null and Undefined in Javascript. What’s the difference between null and… | by Megan Lo | Webtips | Medium
February 17, 2021 - Quick Note: As mentioned earlier, null and undefined are both primitive values, but interestingly enough, if we test out in typeof , they gave us different result: All other values in Javascript are objects ({}, [], functions…). So, this is generally regarded as a mistake when Javascript is first created.
🌐
SheCodes
shecodes.io › athena › 142857-understanding-the-values-null-and-undefined-in-javascript
[JavaScript] - Understanding the values null and undefined in JavaScript
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 string odd if the number is odd.
🌐
DEV Community
dev.to › sduduzog › null-vs-undefined-what-to-choose-what-to-use-11g
null vs undefined? What to choose? What to use? - DEV Community
August 23, 2023 - With JavaScript you can travel back in time to make a variable not assigned a value. "But black dynamite, assigning null to a variable does the same thing" see that's where you'd be wrong. Here's an analogy for you. We can say null is like loading a webpage and just getting a blank screen, but undefined is a '404 not found' error.
🌐
JavaScript Tutorial
javascripttutorial.net › home › an essential guide to javascript null
An Essential Guide to JavaScript null
September 29, 2020 - Summary: in this tutorial, you’ll learn about the JavaScript null and how to handle it effectively. JavaScript null is a primitive type that contains a special value null.
🌐
SitePoint
sitepoint.com › javascript
Could someone explain why "" != null? - JavaScript - SitePoint Forums | Web Development & Design Community
October 14, 2016 - [quote=“jgetner, post:8, topic:240030, full:true”]Since null is a primitive type object in javascript undefined and null are different in terms of how memory see’s them that is a great point.
🌐
Quora
quora.com › Why-is-null-considered-an-object-in-JavaScript
Why is null considered an object in JavaScript? - Quora
Answer: ‘Null’ is a basic building block in JavaScript thus why it is referred to as a primitive data type and provides built-in support. Other primitive data type include strings, numbers, booleans, null and undefined. Then, there are object data types(or non-primitive data types).
🌐
Programiz
programiz.com › javascript › null-undefined
JavaScript null and undefined
Note: Usually, null is used to assign 'unknown' or 'empty' value to a variable. Hence, you can assign null to a variable. In JavaScript, null is a special value that represents an empty or unknown value.
🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-null
Everything about null in JavaScript
September 21, 2020 - null in JavaScript is a special value that represents a missing object.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › null
`null` in JavaScript - Mastering JS
December 2, 2020 - 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 ...
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
What is the difference between null and ""? - JavaScript - The freeCodeCamp Forum
September 6, 2022 - What is the difference between “” and null in Javascript? I have always thought that “” === null. But this question says there are 5 falsy values, i.e. false , null , 0 , "" , undefined , and NaN . Hence, I am wondering…