current position:Home>How the front end judges the data type

How the front end judges the data type

2022-06-24 09:43:32You are far from it.

1. typeof

It is mainly used to judge the basic data type
Cannot determine reference data type

2.instanceof

It is mainly used to judge the reference data type
Cannot judge basic data type

principle : Determine whether an instance object is an instance of this constructor

One thing to note :
If you judge arrays and objects , You need to judge the type of array first

 console.log([] instanceof Object);  // true
 console.log({
    } instanceof Object);  // true

Why is it all printed true
In fact, the ancestors of arrays and objects are Object

3. Object.prototype.toString.call()

Used to judge all data types

copyright notice
author[You are far from it.],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/175/202206240824353688.html

Random recommended