Explorer
Node.js

Write a function `checkType(val)` that returns the type of the given value as a string. Use the `typeof` operator. For `null`, return `"null"` (not `"object"`).

Problem Statement

Write a function `checkType(val)` that returns the type of the given value as a string. Use the `typeof` operator. For `null`, return `"null"` (not `"object"`).

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: The typeof operator returns a string like "number", "string", etc. šŸ’” Hint 2: typeof null returns "object" which is a known JavaScript bug. Handle this edge case. šŸ’” Hint 3: Check if val === null first before using typeof. āœ… Solution: ```javascript function checkType(val) { if (val === null) return "null"; return typeof val; } ```

Check Data Type

Easy
Write a function `checkType(val)` that returns the type of the given value as a string. Use the `typeof` operator. For `null`, return `"null"` (not `"object"`).
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
["number","string","boolean","null","undefined","object"]