By
using ‘undefined’, you can check whether a variable has a value or not.
HelloWorld.js
function do_something() { var x = 100; if(x === undefined){ console.log("x is undefined"); }else{ console.log("Value of x is : " + x); } var y; if(y === undefined){ console.log("y is undefined"); }else{ console.log("Value of y is : " + y); } } do_something();
Output
Value
of x is : 100
y
is undefined
No comments:
Post a Comment