What happens when you assign undefined in JavaScript?

Consider the following code:

var x = undefined; 

This is the most controversial line of code. Is x determined or not? Do JavaScript implementations remove the variable x from memory or set it to undefined ?

+6
source share
1 answer

There is the difference between an unoccupied variable and undefined:

 var x; //x is equal to *undefined* alert(y); //error, y is undeclared 

This does not contradict each other, but it is redundant:

 var x = undefined; 

Think of undefined as just the value that the variable has if it was not initialized, or the value that the property of the object has when it was not initialized or declared.

+5
source

Source: https://habr.com/ru/post/985031/


All Articles