frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

489 - Detect Data Type - javascript

Open jsartisan opened this issue 2 months ago • 0 comments

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 };

jsartisan avatar Sep 27 '25 08:09 jsartisan