Write getType(value) that returns a precise type name, telling null, arrays, and dates apart.
getType(value) returns "null" for null.
For every other primitive, and for functions, it returns what typeof returns: "number", "string", "function", and so on.
For other objects, it returns the name of the built-in type in lowercase, like "array", "date", "regexp", or "map". Plain objects and class instances give "object".
function getType(value) {
// your code
}
// getType(null); // "null"
// getType(NaN); // "number"
// getType(() => {}); // "function"
// getType([1, 2]); // "array"
// getType(new Date()); // "date"
// getType(new Map()); // "map"
// getType({}); // "object"
// getType(new (class Point {})()); // "object"
The answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…