Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to check a variable has a value or not?

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



Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

How to check a variable has a value or not?

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×