EasyPythonJavaScriptTypeScript
Precise typeof Checker
FunctionsObjects
The native typeof operator is famously coarse: it reports 'object'
for arrays, null, dates, regexes and plain objects alike. Implementsolve(value) that returns the precise lowercase type tag for any
JavaScript value.
Expected outputs
solve(null)→'null'solve([])→'array'solve(new Date())→'date'solve(/abc/)→'regexp'solve({})→'object'solve('hi')→'string'solve(undefined)→'undefined'solve(42)→'number'
The result must always be a non-empty lowercase string.
Sample tests
Test #1Number literal
Input: [42]
Output: "number"
Test #2String literal
Input: ["hello"]
Output: "string"
Test #3Plain object
Input: [{"a":1}]
Output: "object"
Test #4Arrays are not "object"
Input: [[1,2,3]]
Output: "array"
Test #5null is not "object"
Input: [null]
Output: "null"