Episode 6: undefined vs not defined in JS 🤔
IMPORTANT POINTS
-
When JS is in memory allocation phase, it allocates each variable to a placehold. That placeholder is known as undefined.
-
undefined is like allocating memory but not provided value yet.
-
If a JS variable/object is not even found in memory allocation phase, it is never assigned as undefined also. So if tried to accessed, it shows error: NOT DEFINED as it is never allocated.
-
undefined is not empty; it takes up memory. It stays undefined until it gets a value assigned to it.
-
JavaScript is a loosely-typed/weakly-typed language.
-
One can assign a number to it initially and can change whenever required to string, boolean etc.
-
NEVER assign undefined to any variable. Let it be used for its purpose only!