this will do the trick for you

if (!!val) {
    alert("this is not null")
} else {
    alert("this is null")
}
Discussions

javascript - How to check if a variable is not null? - Stack Overflow
It has some nice tips for JavaScript in general but one thing it does mention is that you should check for null like: ... It also mentions what's considered 'falsey' that you might not realise. More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to check if a value is not null and not empty string in JS - Stack Overflow
Is there any check if a value is not null and not empty string in Javascript? More on stackoverflow.com
🌐 stackoverflow.com
What is the best method to check if a variable is not null or empty?
It depends what you mean by empty, or how strict you want to be. These values will coerce to false: undefined null '' (empty string) 0 NaN Everything else coerces to true. So, if you are OK with rejecting all of those values, you can do: if(PostCodeInformation) { } If you want to make sure that PostCodeInformation is really an object value (and not a number or boolean, etc): if(typeof PostCodeInformation === 'object' && PostCodeInformation !== null) { } You have to do the null-check there, because in JavaScript typeof null returns 'object'. So dumb. If you want to make sure that PostCodeInformation has some property that you really need: if(PostCodeInformation && PostCodeInformation.myCoolProperty) { } Etc, etc More on reddit.com
🌐 r/javascript
18
3
August 2, 2015
What’s the best way to use JavaScript if not null to check if a variable is not null? - LambdaTest Community
What’s the best way to use JavaScript if not null to check if a variable is not null · This solution is the most general and checks if myVar is a truthy value. It works for any value that is not falsy, including null, undefined, false, 0, NaN, and "". It’s useful if you want to ensure ... More on community.lambdatest.com
🌐 community.lambdatest.com
0
April 1, 2025
🌐
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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › null
null - JavaScript | MDN
October 28, 2025 - 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.
Find elsewhere
🌐
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.
🌐
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.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Optional_chaining
Optional chaining (?.) - JavaScript | MDN
The optional chaining (?.) operator accesses an object's property or calls a function. If the object accessed or function called using this operator is undefined or null, the expression short circuits and evaluates to undefined instead of throwing an error.
🌐
Sentry
sentry.io › sentry answers › javascript › how do i check for an empty/undefined/null string in javascript?
How do I Check for an Empty/Undefined/Null String in JavaScript? | Sentry
To check that a value is not an empty string, null, or undefined, you can create a custom function that returns true if a value is null, undefined, or an empty string and false for all other falsy values and truthy values:
🌐
LambdaTest Community
community.lambdatest.com › general discussions
What’s the best way to use JavaScript if not null to check if a variable is not null? - LambdaTest Community
April 1, 2025 - What’s the best way to use JavaScript if not null to check if a variable is not null · This solution is the most general and checks if myVar is a truthy value. It works for any value that is not falsy, including null, undefined, false, 0, NaN, and "". It’s useful if you want to ensure ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Nullish_coalescing
Nullish coalescing operator (??) - JavaScript | MDN
Like the 'OR' and 'AND' logical operators, the right-hand side expression is not evaluated if the left-hand side proves to be neither null nor undefined.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
Comparisons can be made: null === ... objects are truthy, so typeof maybeNull === "object" && !maybeNull is an easy way to check to see that a value is not null....
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 - 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 = null; ...
🌐
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 undefined value is actually implemented in JavaScript by a special Undefined object, which only has one instance (it's a singleton). Horace has an SSN property, because he's a U.S. citizen, but he forgot what it was — so we assigned a null for him (Horace is a null kinda guy, actually). Note that difference between null and undefined: the former indicates that the property is there, but it doesn't refer to any value at the moment; the latter says the property isn't even there.
🌐
Hacker News
news.ycombinator.com › item
Intent to stop using 'null' in my JS code | Hacker News
November 3, 2020 - Arguing that all `null`s should be replaced with `undefined`s in JS code also kind of implies to me that JSON should replace the `null` keyword with `undefined`, which just sounds crazy to me. Why store "undefined" values in serialized data? If it's not defined, don't define it...
🌐
TutorialsPoint
tutorialspoint.com › how-do-i-check-for-null-values-in-javascript
How do I check for null values in JavaScript?
July 22, 2022 - 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.
🌐
SitePoint
sitepoint.com › javascript
Could someone explain why "" != null? - JavaScript - SitePoint Forums | Web Development & Design Community
October 14, 2016 - Not quite - if you declare a variable without assigning a value, its value will be undefined. ... @fretburner Yes you are correct that is a caveat in javascript i tend to overlook the everything is an object crap. But what i was refering to is how the interpreter most of the time in many languages uses just memory to check the value. 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.