This is the 29th day of my participation in the August More Text Challenge


typeof

Typeof is an operator that follows a unary expression to the right and returns the data typeof that expression. The result returned is represented as an all-lowercase string of that type

Typeof works, but if you use it to look at null or array types, you’ll flip over

Because typeof only returns number, Boolean, string, undefined, Object, function, ES, and symbol

Object.prototype.toString…

ToString () is a prototype method for Object that, by default, returns the current Object’s [[Class]]. For Object objects, toString() directly returns [Object Object]. For other objects, call is required to return the correct type information.

Object.prototype.toString.call(arr/obj)

Return a string that shows you exactly what type it is, one to one, no pressure, perfect, okay

Since.call works, I have tried bind and apply and found that it works too. Rest assured use!

Object.prototype.toString.apply(arr/obj) Object.prototype.toString.bind(arr/obj)()

instanceof

Instanceof is used to determine whether A is an instanceof b. the expression is: A instanceof B, true if A is an instanceof B, false otherwise. Instanceof detects prototypes, and the internal mechanism is to determine whether there are types of prototypes in an object’s prototype chain.

This is very weak, very useless.

  1. Because the return value of this is a Boolean. You have to guess and test for yourself. Or Object. The prototype. ToString. XXX works, the somebody else return string directly, see more intuitive, and accurate.

  2. Because it can’t judge the basic data types, you can see that all six basic data types are overturned.

    If you ask me why I don’t write c instanceof null d instanceof undefined, because it will return an error!

constructor

When a function is defined, the JS engine adds a Prototype to it and then adds a constructor attribute to prototype. The constructor property of a function points to itself.

This is also super invincible weak, null and undefined directly error

But fortunately, other data types can be determined


I’m girl Ann, and it’s been a hard day, too