typeof instanceof code example
Example 1: instanceof vs typeof
For JS/TS:
instanceof checks the proptype chain and typeof compares against string literal labels.
- use instanceof for custom types
- use typeof for simple built in types
- Use instanceof for complex built in types
if in doubt go with instanceof, tbh
Example 2: instanceof javascript
var color = "red";
var color2 = {};
color instanceof String // will return true
color2 instanceof Object // will return true