Sunday, 9 December 2018

JavaScript: Primitive boolean vs Boolean

What is the output of below program.

HelloWorld.js
var b = new Boolean(false);
if (b){
  console.log("b is evaluated to true");
}else{
  console.log("b is evaluated to false");
}

Many people confused between primitive boolean with Boolean object. In Javascript primitive boolean false variable is evaluated to false, but not the Boolean false object. In the above case "b is evaluated to true" is printed.

Previous                                                 Next                                                 Home

No comments:

Post a Comment