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:

  1. Use typeof for primitive types
  2. Check if the value is not null
  3. Use instanceof for objects
  4. Execute the appropriate action