Put in order · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects
Type Checking Flow
Arrange the steps of checking a variable's type in production code:
Items to put in order
- Check if the value is not null
- Execute the appropriate action
- Use instanceof for objects
- Use typeof for primitive types
Show the answer
Correct order:
- Use typeof for primitive types
- Check if the value is not null
- Use instanceof for objects
- Execute the appropriate action