4

The Boolean type has two literal values: true and false.

Do not confuse the primitive Boolean values true and false with the true and false values of the Boolean object. The Boolean object is a wrapper around the primitive Boolean data type. See Boolean Object for more information.

What does this mean? What's the difference between the Boolean object and the Boolean data type??

DarkLightA
  • 14,980
  • 18
  • 49
  • 57

4 Answers4

3

This is a boolean value:

true

This is a Boolean object wrapping the value:

new Boolean(true);

Having the object adds a level of indirection. Try this to see the difference:

var a = true;
var b = true;
var c = new Boolean(true);
var d = new Boolean(true);

alert(a == b); // true - two `true` values are equal.
alert(c == d); // false - they are not the same object.

See also:

Community
  • 1
  • 1
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
  • Thanks for the answer, but I still don't understand when you'd want to use one rather than the other. – DarkLightA Dec 25 '10 at 22:19
  • @DarkLightA: I suggest you look at this question: http://stackoverflow.com/questions/856324/what-is-the-purpose-of-javascript-new-boolean – Mark Byers Dec 25 '10 at 22:22
2

I want to add to other answers that a Boolean object can also be null, but a boolean value cannot.

0

The boolean data type is a value that can only be true or false. The Boolean object is an object that represents a boolean value.

Jeff Hubbard
  • 9,822
  • 3
  • 30
  • 28
0

The Boolean Data Type is the 'boolean' (TRUE or FALSE) whereas the Boolean Object is an object that translates values INTO boolean data

You'll find an explanation here

w3schools

NightOwlPrgmr
  • 1,322
  • 3
  • 21
  • 31
Mantar
  • 2,710
  • 5
  • 23
  • 30