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, 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.
🌐
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
🌐
DEV Community
dev.to › wolfhoundjesse › null-checking-in-javascript-lc4
Null-checking in JavaScript - DEV Community
April 11, 2019 - I get it—we need to prevent things from going wrong, but the sight of it brings helicopter parenting to mind. Also, it's not really null-checking, but also undefined- and empty-string-checking. This is another benefit you can gain from TypeScript—the peace of mind that it won't compile if you're sending the wrong information.
🌐
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
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-check-if-variable-is-not-null
Check if a Variable is Not NULL in JavaScript | bobbyhadz
Use the strict inequality (!==) operator to check if a variable is not null, e.g. `myVar !== null`.
🌐
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 ...
🌐
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.
🌐
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.
🌐
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
🌐
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, ...
🌐
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.
🌐
Medium
medium.com › @maxwellarmah01 › understanding-javascript-comparisons-why-0-is-null-and-not-null-372d84d65284
Understanding JavaScript Comparisons: Why 0 is null and not null | by Maxwell Armah | Medium
June 10, 2024 - Loose Equality (`==`): For `0 == null`, JavaScript does not perform the same type conversion. Instead, it treats `null` and `undefined` as loosely equal to each other and not to any other types, including numbers. This special handling ensures that `null` is only equal to `undefined` and not to `0`.
🌐
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: