Javascript setting variable to undefined

By default when we create a variable without assigning anything, the variable will be undefined

Once we assigned it a value its harder to set it back to undefined as now it has a type and value for it.

We can do in following way using

var a; //a is undefined here
a=5; // a is 5
a = void(0); //a is undefined again here

Here void states that the variable is of no type and 0 assigns to no value.

Scroll to Top