Here’s the JavaScript equivalent:

var i = null;
var j = i || 10; //j is now 10

Note that the logical operator || does not return a boolean value but the first value that can be converted to true.

Additionally use an array of objects instead of one single object:

var options = {
    filters: [
        {
            name: 'firstName',
            value: 'abc'
        }
    ]
};
var filter  = options.filters[0] || '';  // is {name:'firstName', value:'abc'}
var filter2 = options.filters[1] || '';  // is ''

That can be accessed by index.

Answer from Gumbo 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 - As you can see, it only returns true when a null variable is compared with null, and an undefined variable is compared with undefined. Object.is() is an ES6 method that determines whether two values are the same.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › null
null - JavaScript | MDN
The null keyword refers to the null primitive value, which represents the intentional absence of any object value. function getVowels(str) { const m = str.match(/[aeiou]/gi); if (m === null) { return 0; } return m.length; } console.log(getVowels("sky")); // Expected output: 0
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
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Nullish_coalescing
Nullish coalescing operator (??) - JavaScript | MDN
c()); // Logs "b was called" then "false" // as b() returned false (and not null or undefined), the right // hand side expression was not evaluated · The nullish coalescing operator treats undefined and null as specific values. So does the optional chaining operator (?.), which is useful to access a property of an object which may be null or undefined. Combining them, you can safely access a property of an object which may be nullish and provide a default value if it is.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
So, when programming to check if a variable has any value at all before trying to process it, you can use == null to check for either null or undefined. Some JavaScript programmers prefer everything to be explicit, and there is nothing wrong ...
Published   August 4, 2025
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-replace-a-value-if-null-or-undefined-in-javascript
How to Replace a value if null or undefined in JavaScript? - ...
July 12, 2025 - Using the logical OR (||) operator in JavaScript, you can assign a default value if the original value is null or undefined. This approach also covers other falsy values like 0 or an empty string.
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;

Find elsewhere
🌐
Scaler
scaler.com › topics › javascript-check-null
JavaScript Program to Check for Null - Scaler Topics
December 14, 2022 - In this approach, we will use the strict equality operator '===' to check if the variable contains null or not. If the value of x is null, then the statement inside the If block will be printed.
🌐
TutorialsPoint
tutorialspoint.com › how-do-i-check-for-null-values-in-javascript
How do I check for null values in JavaScript?
The typeof operator may be used to determine the data type of a JavaScript variable. Here we use the typeof operator with the null operator. The (!variable) means the value is not null and if it is checked with the typeof operator variable which has the data type of an object then the value is null.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-check-for-null-values-in-javascript
How to check for null values in JavaScript ? - GeeksforGeeks
July 23, 2025 - Checking undeclared variable: true ... null nor undefined: true false is neither null nor undefined: true · Lodash _.isNull() method is used to find whether the value of the object is null....
🌐
UsefulAngle
usefulangle.com › post › 281 › javascript-default-value-if-null-or-undefined
Set Default Values to Variables if null or undefined (Javascript)
The nullish coalescing operator (??) can be used to give default values to variables in Javascript if they are either null or undefined.
🌐
Position Is Everything
positioniseverything.net › home › javascript check if null: learn about null values with examples
JavaScript Check if Null: Learn About Null Values With Examples - Position Is Everything
3 weeks ago - While the JavaScript check for null is in process, we use the strict equality operator where the boolean expression is used to see the results. If the result is true, then there is a null value; if the result is false, it means there are falsy ...
🌐
JavaScript Tutorial
javascripttutorial.net › home › an essential guide to javascript null
An Essential Guide to JavaScript null
September 29, 2020 - JavaScript uses the null value to represent a missing object. Use the strict equality operator (===) to check if a value is null.
🌐
DEV Community
dev.to › wolfhoundjesse › null-checking-in-javascript-lc4
Null-checking in JavaScript - DEV Community
April 11, 2019 - Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript! ... Looking at this block of code... if ( tokenInfo && tokenInfo !== undefined && tokenInfo !== null && tokenInfo !== "" ) { } If the first check... ... ... is undefined, null, or "", or any other falsy valuue... then the if will short circuit and not perform any of the other checks.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-check-if-a-variable-is-not-null-in-javascript
How to check if a Variable Is Not Null in JavaScript ? - GeeksforGeeks
August 5, 2025 - In this approach, we are using the library of javascript. we are using the _.isNull() method which returns true or false according to the given value. If the value is not null then it will return false.
🌐
W3Resource
w3resource.com › javascript-exercises › fundamental › javascript-fundamental-exercise-196.php
JavaScript fundamental (ES6 Syntax): Return true if the specified value is null, false otherwise - w3resource
// Define a function 'isNull' that checks if the given value 'val' is null const isNull = val => // Check if 'val' is strictly equal to null val === null; // Test cases to check if the values are null console.log(isNull(null)); // true (the value is null) console.log(isNull(123)); // false (the value is not null) ... See the Pen javascript-basic-exercise-196-1 by w3resource (@w3resource) on CodePen.
🌐
Coderanch
coderanch.com › t › 734748 › languages › check-variable-null-JavaScript
Is there a better way to check if variable is null value or not in JavaScript? (Server-Side JavaScript and NodeJS forum at Coderanch)
A very recent addition (check your environment for compatibility) is called nullish coalescing and goes like so: ... whose value is a if a is not null and not undefined, b otherwise.
🌐
Codedamn
codedamn.com › news › javascript
How to check if value is undefined or null in JavaScript
June 8, 2023 - The easiest way to check if a value is either undefined or null is by using the equality operator (==). The equality operator performs type coercion, which means it converts the operands to the same type before making the comparison.