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 things. Usually undefined is the result when something has had no value assigned to it, whereas null has a value, and the value is explicitly set to "nothing".

Answer from loganfsmyth on Stack Overflow
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
🌐
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 - 2. Final Comparison: — Since `null` is not `0` and does not convert to `0` in this context, `0 == null` evaluates to `false`. Relational Comparison (`>=`): When `0 >= null` is evaluated, JavaScript first converts `null` to a number.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-null-check
How to Check for Null in JavaScript | Built In
The typeof keyword returns "object" for null, so that means a little bit more effort is required. Comparisons can be made: null === null to check strictly for null or null == undefined to check loosely for either null or undefined.
Published   August 4, 2025
🌐
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.
🌐
Colt Steele
coltsteele.com › tips › comparing-null-and-undefined-in-javascript
Comparing null and undefined in JavaScript | Colt Steele
August 23, 2023 - If you're trying to determine whether a value is specifically set to null, your best option is not to use typeof or ==. You should always compare to null with ===. For example audioInputDevice === null will only be true if audioInputDevice is ...
🌐
Adripofjavascript
adripofjavascript.com › blog › drips › equals-equals-null-in-javascript.html
Equals Equals Null in JavaScript - A Drip of JavaScript
Despite the fact that null is a falsy value (i.e. it evaluates to false if coerced to a boolean), it isn't considered loosely equal to any of the other falsy values in JavaScript. In fact, the only values that null is loosely equal to are undefined and itself. Because of this interesting property, it has become somewhat conventional to use == null as a more concise way of checking whether a given value is "nothing" (null/undefined) or "something" (anything else).
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 = null; ...
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Equality_comparisons_and_sameness
Equality comparisons and sameness - JavaScript | MDN
In all other cases an object is never loosely equal to undefined or null. In most cases, using loose equality is discouraged. The result of a comparison using strict equality is easier to predict, and may evaluate more quickly due to the lack of type coercion.
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-2-0.html
TypeScript: Documentation - TypeScript 2.0
Non-null and non-undefined type guards may use the ==, !=, ===, or !== operator to compare to null or undefined, as in x != null or x === undefined. The effects on subject variable types accurately reflect JavaScript semantics (e.g.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Comparisons
Comparisons (1) and (2) return false because undefined gets converted to NaN and NaN is a special numeric value which returns false for all comparisons. The equality check (3) returns false because undefined only equals null, undefined, and ...
🌐
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 whether a variable is not null is an important step to ensure that your code runs smoothly. We explored various methods such as using if-else statements, Lodash's _.isNull() method, the typeof operator, and the strict ...
🌐
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.
🌐
Medium
medium.com › @gajjar.parth1811 › null-behavior-comparison-in-javascript-20601d2e89a0
NULL behavior comparison in javascript | by Gajjar Parth | Medium
March 20, 2023 - Similarly, when using comparison operators (<, >, <=, >=) with null, there are some nuances to the behavior that can impact your code. For example, the less than and greater than operators require both operands to be numbered, but null is not a number, so they cannot be compared using these operators without first converting them to a number. Understanding the behavior of null JavaScript can be important for writing reliable and predictable code.
🌐
SitePoint
sitepoint.com › javascript
Could someone explain why "" != null? - JavaScript - SitePoint Forums | Web Development & Design Community
October 14, 2016 - Isn’t that exactly what it was since invention of first programming languages? When you do not provide a comparison, the condition checks to see if the boolean result is true or false.
🌐
Medium
medium.com › @harshitkishor2 › unpacking-javascripts-weird-comparison-rules-with-null-2c22718b9d28
Unpacking JavaScript’s Weird Comparison Rules with null | by Harshit Kishor | Medium
May 24, 2025 - This is a relational comparison. According to the spec, when comparing values of different types using < or >, JavaScript converts them to numbers: ... This one is trickier. The == operator uses loose equality rules, but it doesn’t convert null to 0. Instead, null is only loosely equal to undefined: ... This one feels like a contradiction — but it’s not if you read the spec.