Returns the type of a value as a string. This function uses Object.prototype.toString to determine the type of the value. It returns a lowercase string representing the type, such as "string", "number", "boolean", etc.
Object.prototype.toString
getType('hello'); // 'string'getType(42); // 'number'getType(true); // 'boolean'getType([]); // 'array'getType({}); // 'object'getType(null); // 'null'getType(undefined); // 'undefined'getType(new Date()); // 'date'getType(/regex/); // 'regexp'getType(new Map()); // 'map'getType(new Set()); // 'set'getType(new Promise(() => {})); Copy
getType('hello'); // 'string'getType(42); // 'number'getType(true); // 'boolean'getType([]); // 'array'getType({}); // 'object'getType(null); // 'null'getType(undefined); // 'undefined'getType(new Date()); // 'date'getType(/regex/); // 'regexp'getType(new Map()); // 'map'getType(new Set()); // 'set'getType(new Promise(() => {}));
Returns the type of a value as a string. This function uses
Object.prototype.toString
to determine the type of the value. It returns a lowercase string representing the type, such as "string", "number", "boolean", etc.