About 11,600,000 results
Open links in new tab
  1. How do I check for null values in JavaScript? - Stack Overflow

    Jan 4, 2024 · @HunanRostomyan Good question, and honestly, no, I do not think that there is. You are most likely safe enough using variable === null which I just tested here in this JSFiddle.

  2. JavaScript checking for null vs. undefined and difference between ...

    Feb 24, 2011 · But if you then assign a = null; then a will now be null. In JavaScript null is an object (try typeof null in a JavaScript console if you don't believe me), which means that null is a value (in fact even undefined is a value). Example: var a; typeof a; # => "undefined" a = null; typeof null; # => "object" This can prove useful in function ...

  3. javascript - When should I use ?? (nullish coalescing) vs || (logical ...

    ) in JavaScript only considers null or undefined as "nullish" values. If the left-hand side is any other value, even falsy values like "" (empty string), 0 , or false , it will not use the right-hand side:

  4. Comparing to null - !== vs != in JavaScript - Stack Overflow

    Apr 25, 2013 · Your global.User is undefined, not null. When using == they evaluate to equal, but with === the items you are comparing need to be the same type. undefined has the type undefined and null has the type object. undefined and null are very similar, but they generally mean two very different

  5. How do I check for an empty/undefined/null string in JavaScript?

    As many know, (0 == "") is true in JavaScript, but since 0 is a value and not empty or null, you may want to test for it. The following two functions return true only for undefined, null, empty/whitespace values and false for everything else, such as numbers, Boolean, objects, expressions, etc.

  6. javascript - Why is null an object and what's the difference …

    Apr 29, 2009 · null is also a primitive value in JavaScript. It indicates the intentional absence of an object value. null in JavaScript was designed to enable interoperability with Java. typeof null returns "object" because of a peculiarity in the design of the language, stemming from the demand that JavaScript be interoperable with Java.

  7. What is the difference between null and undefined in JavaScript?

    Feb 22, 2011 · It's worth noting that while this comment was true in '11, with the advent of optional function params, emergence of type-checking systems like Flow, and pervasiveness of React (all of which treat undefined and null very differently), the old wisdom of generally using null rather than undefined no longer holds so strictly. undefined is actually preferable to null in many cases where you want ...

  8. JavaScript null check - Stack Overflow

    May 21, 2013 · It's probably supposed to be data !== null && data !== undefined, which is equivalent to data != null which is equivalent to data != undefined. The former form tends to be favored as it's more explicit about the conditions, whereas it'd be easy to overlook that both null and undefined are being checked with the later two conditions. –

  9. How to check for an undefined or null variable in JavaScript?

    Checking for null/undefined in JavaScript. 3132. Is there a standard function to check for null, undefined ...

  10. javascript - What's the difference between a == null and a

    a === null is true if the value of a is null. See The Strict Equality Comparison Algorithm in the specification: 1. If Type(x) is different from Type(y), return false. 2. If Type(x) is Undefined, return true. 3. If Type(x) is Null, return true. So, only if Type(a) is Null, the comparison returns true.

Refresh