A variable that is undefined does not exist. Yes, you can use somefunction(variable_you_have_not_declared_yet) - but I would argue that the variable_you_have_not_declared_yet which has a "value" of undefined lacks any form of non-implicit existence.
On the other hand, an uninitialized variable is an existing variable which doesn't have value. It can have no value for two reasons:
it wasn't assigned a value at the moment of creation, and will be assigned later, like let a;
it was assigned with the result of an operation which can return null-value, like let a = array[0]; (undefined in case of JS)
In my opinion, the destination between null and undefined is over-complication. They both represent the absence of value. undefined was introduced for historical reasons, I believe this is just an oversight in the language design (see the post by Dr. Axel Rauschmayer). The same way as Tony Hoar says that null was a mistake in AlgolW design.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A variable that is undefined does not exist. Yes, you can use
somefunction(variable_you_have_not_declared_yet)
- but I would argue that thevariable_you_have_not_declared_yet
which has a "value" ofundefined
lacks any form of non-implicit existence.To make sure we use the same terminology
A variable that doesn't exist is an error of a different kind, this is not the same as an uninitialized variable. For example JS:
Flow:
TypeScript:
On the other hand, an uninitialized variable is an existing variable which doesn't have value. It can have no value for two reasons:
let a;
let a = array[0];
(undefined
in case of JS)In my opinion, the destination between
null
andundefined
is over-complication. They both represent the absence of value.undefined
was introduced for historical reasons, I believe this is just an oversight in the language design (see the post by Dr. Axel Rauschmayer). The same way as Tony Hoar says that null was a mistake in AlgolW design.