篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown instanceof vs typeof相关的知识,希望对你有一定的参考价值。
## typeof
Unary operator that returns a string indicating the type of the unevaluated operand.
```javascript
const a = "I'm a string primitive";
const b = new String("I'm a String Object");
typeof a; --> returns 'string'
typeof b; --> returns 'object'
```
## instanceof
Binary operator, accepting an object and a constructor.
It returns a boolean indicating whether or not the object has the given constructor in its prototype chain.
```javascript
const a = "I'm a string primitive";
const b = new String("I'm a String Object");
a instanceof String; --> returns false
b instanceof String; --> returns true
```
以上是关于markdown instanceof vs typeof的主要内容,如果未能解决你的问题,请参考以下文章