Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Refined Type Of

Fundamentals: Part 1easy

Course · Section 2: JavaScript Fundamentals – Part 1 · Lecture 11: Data Types

Implement `getType(value)` returning `array` for arrays, `null` for null, and otherwise the result of `typeof value`.

Sample tests

Input: getType([])
Output: "array"
Input: getType(null)
Output: "null"

+ 2 hidden tests run on Submit.

Hints

Common pitfalls
  • typeof null returns 'object', a long-standing JavaScript quirk.
  • Arrays report typeof 'object', so they need a separate check.

Learning resources

  • MDN: typeof
Visualize this concept: Data Types and Coercion →
Approach & explanation (try first)

typeof cannot distinguish null or arrays from plain objects, so you special-case those two before falling back to typeof.

Loading...
⌘/Ctrl + Enter

Run your code to see results.