Files
30-seconds-of-code/snippets/getType.md
30secondsofcode 2cb8819913 Travis build: 1892
2020-04-16 20:04:29 +00:00

397 B

title, tags
title tags
getType type,beginner

Returns the native type of a value.

Return 'undefined' or 'null' if the value is undefined or null. Otherwise, use Object.prototype.constructor.name to get the name of the constructor.

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