js judges what type a value is

What are the ways to determine what type a value is?

typeof 运算符
instanceof 运算符
Object.prototype.toString 方法
const a=true;
typeof(a);
a instanceof Number;
Object.prototype.toString.call(a);

Note:
typeof() will make an error when judging the array, and it will be judged as an object.
When instanceof judges arrays and functions, it judges that Object is also true.
Object.prototype.toString is accurate.

insert image description here
insert image description here

insert image description here
insert image description here
insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/weixin_53125679/article/details/127689428