A JavaScript variable returns undefined when it has not been assigned a value.For example:var a = "Test String"; // defined var b; // undefinedif (a === undefined) {var1 = "a is undefined"; } else {var1 = "a is defined"; }if (b === undefined) {var2 = "b is undefined"; } else {var2 = "b is defined"; }res = var1 + ", " + var2;The result of res will be:a is defined, b is undefined
In JavaScript, undefined means a variable has been declared but has not yet been assigned a value, such as: var TestVar; alert(TestVar); //shows undefined alert(typeof TestVar); //shows undefined. null is an assignment value.
if we didnt assign the value for the given input
variable has declared but didnot assign yet