markdown instanceof vs typeof

Posted

tags:

篇首语:本文由小常识网(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的主要内容,如果未能解决你的问题,请参考以下文章

每日一博 - instanceof vs isInstance vs isAssignableFrom

每日一博 - instanceof vs isInstance vs isAssignableFrom

JavaScript instanceof vs typeof

JS == vs ===, typeof vs instanceof

Uncaught TypeError: Right-hand side of 'instanceof' is not callable(markdown-scroll-sync)(示例

instanceof vs isAnX()