Empty variable example in Javascript. Undefined variable example in Javascript. How to declare a variable with no value in javascript. How to declare an empty variable in JS.
Undefined Variable in Javascript
An undefined variable in Javascriptis a variable that is declared but not assigned.
eg: let username;
In the above example, the variable username is an undefined variable. Because it is declared as a let variable but at the same time no value is assigned to this variable. And Only declaration is done.
Empty Variable or No-value variable in Javascript
An empty variable in Javascriptis a variable that is declared and assigned an empty or null value.
eg: let username = null ;
An empty value should be assigned in order to be considered as an empty variable in JS. In the above example we have assigned null value to the variable username.
Difference between undefined and empty variables in javascript commonly asked as a javascript interview question. Above we have discussed and learned about no value variable and undefined variable of JS in detail.