Files
30-seconds-of-code/snippets/getType.md
Angelos Chalaris 8281457945 Updated examples
Removed duplicate and unnecessary examples.
2018-01-04 14:22:56 +02:00

319 B

getType

Returns the native type of a value.

Returns lowercased constructor name of value, "undefined" or "null" if value is undefined or null

const getType = v =>
  v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
getType(new Set([1, 2, 3])); // 'Set'