frontend-challenges
frontend-challenges copied to clipboard
489 - Detect Data Type - javascript
index.js
/**
* Detect the data type of any JavaScript value.
* @param {any} value - Value to detect type of
* @returns {string} Lowercase type name
*/
function detectType(data) {
if (data === null) {
return 'null';
}
if (data === undefined) {
return 'undefined'
}
return data.constructor.name.toLowerCase();
}
export { detectType };