๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Operators โ€บ null
null - JavaScript | MDN
Unlike undefined, JSON.stringify() can represent null faithfully. 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.
๐ŸŒ
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
For example, ... In JavaScript, == compares values by performing type conversion. Both null and undefined return false. Hence, null and undefined are considered equal. However, when comparing null and undefined with strict equal to operator ===, the result is false.
๐ŸŒ
TutorialsTeacher
tutorialsteacher.com โ€บ javascript โ€บ javascript-null-and-undefined
Difference between null and undefined in JavaScript
A null means the absence of a value. You assign a null to a variable with the intention that currently this variable does not have any value but it will have later on. It is like a placeholder for a value.
๐ŸŒ
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. JavaScript uses the null value to represent the intentional absence of any object value. If you find a variable or a function that returns null, it means that the expected ...
๐ŸŒ
Dmitri Pavlutin
dmitripavlutin.com โ€บ javascript-null
Everything about null in JavaScript
null, alongside false, 0, '', undefined, NaN, is a falsy value. If a falsy value is encountered in conditionals, then JavaScript coerces falsy to false. ... typeof value operator determines the type of value.
๐ŸŒ
Mastering JS
masteringjs.io โ€บ tutorials โ€บ fundamentals โ€บ null
`null` in JavaScript - Mastering JS
In JavaScript, null is a value that represents the intentional absence of any object value. It is technically a primitive type, although in some cases it behaves as an object. Here's what you need to know about null: You can check whether a ...
๐ŸŒ
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 ยป
๐ŸŒ
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
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;

๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ javascript-null-check
How to Check for Null in JavaScript | Built In
Finally, to check if a value has ... out there and check for null with confidence. In JavaScript, null represents an intentional absence of a value, indicating that a variable has been declared with a null value on purp...
Published ย  August 4, 2025
๐ŸŒ
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;
๐ŸŒ
FoxLearn
foxlearn.com โ€บ home โ€บ javascript โ€บ what is null in javascript
What is null in Javascript
December 18, 2024 - undefined typically means a variable ... of any value or object. undefined is a primitive value automatically assigned to a variable that has been declared but not assigned a value....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ undefined-vs-null-in-javascript
Undefined Vs Null in JavaScript - GeeksforGeeks
July 23, 2025 - ... let x; // variable declared ... Output: undefined ... null is a special value in JavaScript that represents the deliberate absence of any object value....
๐ŸŒ
Syncfusion
syncfusion.com โ€บ blogs โ€บ post โ€บ null-vs-undefined-in-javascript
Null vs. Undefined in JavaScript | Syncfusion Blogs
December 10, 2024 - Since undefined is the default value assigned by JavaScript to uninitialized variables, if you want to indicate the absence of a deal explicitly, always use null instead of undefined to avoid confusion. To check if a variable has any value before proceeding further in a program, you can use the loose equality ==null to check for either null or undefined.For example, in the following program, the function assignVal() checks whether the num is undefined or null and assigns the value given by the user only if the variable num is not initialized to any value.
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ javascript โ€บ null-and-undefined-in-javascript
Null and Undefined in JavaScript - Scaler Topics
April 21, 2022 - When we assign null as a value to any variable, it means that it is empty or blank. It is to show that the variable has no value. Also, null is an object in JavaScript. When it gets assigned to a variable, it represents no value. The setting of the value must be done manually by the user as ...
Top answer
1 of 16
1532
(name is undefined)

You: What is name? (*)
JavaScript: name? What's a name? I don't know what you're talking about. You haven't ever mentioned any name before. Are you seeing some other scripting language on the (client-)side?

name = null;

You: What is name?
JavaScript: I don't know.

In short; undefined is where no notion of the thing exists; it has no type, and it's never been referenced before in that scope; null is where the thing is known to exist, but it's not known what the value is.

One thing to remember is that null is not, conceptually, the same as false or "" or such, even if they equate after type casting, i.e.

name = false;

You: What is name?
JavaScript: Boolean false.

name = '';

You: What is name?
JavaScript: Empty string


*: name in this context is meant as a variable which has never been defined. It could be any undefined variable, however, name is a property of just about any HTML form element. It goes way, way back and was instituted well before id. It is useful because ids must be unique but names do not have to be.

2 of 16
147

The difference can be summarized into this snippet:

alert(typeof(null));      // object
alert(typeof(undefined)); // undefined

alert(null !== undefined) //true
alert(null == undefined)  //true

Checking

object == null is different to check if ( !object ).

The latter is equal to ! Boolean(object), because the unary ! operator automatically cast the right operand into a Boolean.

Since Boolean(null) equals false then !false === true.

So if your object is not null, but false or 0 or "", the check will pass because:

alert(Boolean(null)) //false
alert(Boolean(0))    //false
alert(Boolean(""))   //false