Answers for "instanceof vs typeof"

2

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
Posted by: Guest on May-09-2021

Browse Popular Code Answers by Language