Skip to content

Instantly share code, notes, and snippets.

@naoxink

naoxink/getType.js

Last active Sep 26, 2018
Embed
What would you like to do?
Utility to check variable types easy
function getType(x){
return Object.prototype.toString.call(x).toLowerCase().replace(/\[(.*)\s|\]$/g, '')
}
// Types (all strings):
//
// number
// string
// boolean
// date
// array
// object
// null
// undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment