'Why is process.env.WHATEVER !== undefined if I set to undefined after it is set?

I have the following test script....

> process.env.SOMETHING === undefined
true
> process.env.SOMETHING = "asdsad";
'asdsad'
> process.env.SOMETHING === undefined
false
> process.env.SOMETHING = undefined
undefined
> process.env.SOMETHING === undefined
false
> process.env.SOMETHING == null
false
> !process.env.SOMETHING
false
> process.env.SOMETHING === "undefined"
true

Why does it get converted to a string?



Solution 1:[1]

Because that's what Node requires., at least for now.

Assigning a property on process.env will implicitly convert the value to a string. This behavior is deprecated. Future versions of Node.js may throw an error when the value is not a string, number, or boolean.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1