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

How the null behaves in boolean and numeric context?

'null' behaves as false in Boolean context.

HelloWorld.js
var x = null;

if(x){
console.log("null is Evaluated to true in boolean context");
}else{
console.log("null is evaluated to false in boolean context");
}


Output

null is evaluated to false in boolean context

'null' is evaluated to 0 in numeric context.

HelloWorld.js
var x = null;

var y = x + 10;

console.log("Value of y is : " + y);


Output

Value of y is : 10





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 the null behaves in boolean and numeric context?

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×