this will do the trick for you

if (!!val) {
    alert("this is not null")
} else {
    alert("this is null")
}
๐ŸŒ
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 JavaScript, checking if a variable is not null ensures that the variable has been assigned a value and is not empty or uninitialized.
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 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
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
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Operators โ€บ null
null - JavaScript | MDN
Unlike undefined, which is a global variable, null is not an identifier but a syntax keyword. ... Like undefined, accessing any property on null throws a TypeError instead of returning undefined or searching prototype chains. Like undefined, null is treated as falsy for boolean operations, ...
๐ŸŒ
DEV Community
dev.to โ€บ wolfhoundjesse โ€บ null-checking-in-javascript-lc4
Null-checking in JavaScript - DEV Community
April 11, 2019 - As others have said, if (value) will already check for empties and nulls and stuff. However, people (aka me) tend to forget or get confused about how truthy and falsy work in Javascript, or sometimes I need to check that a variable is not null or undefined, but 0 is an acceptable value.
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ javascript-null-check
How to Check for Null in JavaScript | Built In
The double equality == operator confirms the absence of any value and does not directly check for null. But one way to check for null in JavaScript is to check if a value is loosely equal to null using the double equality == operator:
Published ย  August 4, 2025
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Operators โ€บ Nullish_coalescing
Nullish coalescing operator (??) - JavaScript | MDN
const count = 0; const text = ""; const qty = count || 42; const message = text || "hi!"; console.log(qty); // 42 and not 0 console.log(message); // "hi!" and not "" The nullish coalescing operator avoids this pitfall by only returning the second operand when the first one evaluates to either null or undefined (but no other falsy values): ... const myText = ""; // An empty string (which is also a falsy value) const notFalsyText = myText || "Hello world"; console.log(notFalsyText); // Hello world const preservingFalsy = myText ??
Find elsewhere
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ javascript-check-if-variable-is-a-undefined-or-null
JavaScript: Check if Variable is undefined or null
March 29, 2023 - In this short guide, we've taken a look at how to check if a variable is null, undefined or nil in JavaScript, using the ==, === and typeof operators, noting the pros and cons of each approach.
๐ŸŒ
web.dev
web.dev โ€บ learn โ€บ javascript โ€บ data-types โ€บ null-undefined
null and undefined | web.dev
The strict equality operator considers operands of different data types to be unequal. null == undefined > true null === undefined > false ยท Unlike the reserved keyword null, undefined is a property of the global object.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-check-for-null-in-javascript
JS Check for Null โ€“ Null Checking in JavaScript Explained
November 7, 2024 - Null is a primitive type in JavaScript. This means you are supposed to be able to check if a variable is null with the typeof() method. But unfortunately, this returns โ€œobjectโ€ because of an historical bug that cannot be fixed. let userName ...
๐ŸŒ
Dmitri Pavlutin
dmitripavlutin.com โ€บ javascript-null
Everything about null in JavaScript
The good way to check for null is by using the strict equality operator: ... If the variable contains a non-null value, like an object, the expression existingObject === null evaluates to false. null, alongside false, 0, '', undefined, NaN, ...
๐ŸŒ
Luasoftware
code.luasoftware.com โ€บ tutorials โ€บ javascript โ€บ javascript-check-if-not-null-and-not-empty-string
Javascript Check if Not Null and Not Empty String
The following is not perfect, but work for most common circumstances. ... You can use lodash isEmpty. _.isEmpty(null); // true_.isEmpty(''); // true_.isEmpty('hello') // false_.isEmpty([]) // true_.isEmpty([1]) // false_.isEmpty({}) // true_.isEmpty({test: true}) // false
๐ŸŒ
Javatpoint
javatpoint.com โ€บ how-to-check-if-a-variable-is-not-null-in-javascript
How to check if a variable is not NULL in JavaScript - javatpoint
How to check if a variable is not NULL in JavaScript with javascript tutorial, introduction, javascript oops, application of javascript, loop, variable, objects, map, typedarray etc.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-check-for-null-values-in-javascript
How to check for null values in JavaScript ? - GeeksforGeeks
July 23, 2025 - 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.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ check-if-string-is-empty-or-null-javascript
How to Check if a String is Empty or Null in JavaScript โ€“ JS Tutorial
November 7, 2024 - In this example, we're first using the trim method to remove any leading or trailing whitespace characters from the str variable, then checking whether the resulting string has zero length. If it does, then we know that the string is empty. Otherwise, we know that the string is not empty. Here are some best practices to follow when checking for empty or null strings in JavaScript:
๐ŸŒ
LogRocket
blog.logrocket.com โ€บ home โ€บ how to check for null, undefined, or empty values in javascript
How to check for null, undefined, or empty values in JavaScript - LogRocket Blog
February 14, 2025 - Checking for null can be nerve-wracking for both new and seasoned JavaScript developers. Itโ€™s something that should be very simple, but still bites a surprising amount of people. The basic reason for this is that in most languages, we only have to cater to null.