Boolean objets

var x = new Boolean(false);
if (x) {
  // this code is executed
  console.log('Hi Airas');

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
 return console.log(arr.filter(function(x){
    var a = new Boolean(x);
      return x;

bouncer([7, "ate", "", false, 9]);

Hey guys I am having some difficulty in understanding boolean objects that why even we use this “new Boolean()” thing. Also it was written in javascript documentation that “any object of which the value is not undefined or null, including a Boolean object whose value is false, evaluates to true when passed to a conditional statement”. So the first code is testing this statement and yeah this statement seems to be true.

Now second code is removing all falsy values from array but it is also contradicting the above statement which I highlited in inverted commas. Like when array’s false value will come in filter method it will be var a=new Boolean(false), now according to that statement when a passed to conditional statement it should return that false array value because code will be executed inside that conditional block and should return x which is false value. But instead it is not returning it, even the code is doing what it meant to but why it is contradicting that statement. I hope you guys understand my point here.


bouncer is returning a function that is yet to be invoked.

var bounce = bouncer([7, "ate", "", false, 9]);


or simply,

bouncer([7, "ate", "", false, 9])();

Perhaps the intention was to invoke it immediately, but that was omitted?