Boolean VS boolean

Javascript boolean: primitive type - const disabled: boolean = false;
javascript: Boolean object - const boolean = new Boolean(false);

const b = Boolean("hi");
console.log(b); // true
console.log(typeof(b)) // boolean


var foo = true;
var bar = new Boolean(false);

console.log(typeof(foo)); // boolean
console.log(typeof(bar)); // Object

console.log(foo instanceof Boolean); // false
console.log(bar instanceof Boolean); // true

在这里插入图片描述
It is recommended that you use the Boolean() function to convert a value of a different type to a Boolen
type but you should never use the Boolean as a wrapper object of a primitive boolean value.

猜你喜欢

转载自blog.csdn.net/qq_33495944/article/details/87915330
今日推荐