The Boolean()
constructor can create Boolean objects.
new Boolean([value])
var myFalse = new Boolean(false); // initial value of false var g = Boolean(myFalse); // initial value of true var myString = new String('Hello'); // string object var s = Boolean(myString); // initial value of true
let a = new Boolean("true"); console.log(a);/*from ww w. j av a 2 s. c o m*/ a = new Boolean("1"); console.log(a); a = new Boolean("false"); console.log(a); a = new Boolean({}); console.log(a); a = new Boolean(true); console.log(a); a = new Boolean(false); console.log(a);
Creating Boolean objects with an initial value of false
var bNoParam = new Boolean(); var bZero = new Boolean(0); var bNull = new Boolean(null); var bEmptyString = new Boolean(''); var bfalse = new Boolean(false);
Creating Boolean objects with an initial value of true
var btrue = new Boolean(true); var btrueString = new Boolean('true'); var bfalseString = new Boolean('false'); var bSuLin = new Boolean('asdf'); var bArrayProto = new Boolean([]); var bObjProto = new Boolean({});
Do not use a Boolean object in place of a Boolean primitive.