Intro
JavaScript has so many built-in data types - custom types not even considered - that it would be nearly impossible to keep an up-to-date list of potential return values for getType()
. The aim of the following pages is to give you look-up tables for the most common types. There isn't a is<Type>()
equivalent for everything; I rather tried to cover those that I considered most useful. The functions lean more towards browser implementations than NodeJS, but the code is fully functional under NodeJS as well. You won't find things like isBuffer()
or isDirectory()
though. Contributions are welcome (License: MIT).
Let's start with primitive types - or at least some of them.
Primitive Types (some)
Input value | getType() returns |
is<Type>() function(s) |
---|---|---|
true |
Boolean |
isBoolean() |
false |
Boolean |
isBoolean() |
null |
Null |
isNull() |
undefined |
Undefined |
isUndefined() |
Symbol("bar") |
Symbol |
isSymbol() |
Common Types that didn't fit anywhere else
Input value | getType() returns |
is<Type>() function(s) |
---|---|---|
new Date() |
Date |
isDate() |
new Blob(...) |
Blob |
isBlob() |
/a/g |
RegExp |
isRegExp() |
new RegExp(...) |
RegExp |
isRegExp() |
new Error() |
Error |
isError() |