Skip to content

Instantly share code, notes, and snippets.

@aGuyNamedJonas
Created June 9, 2016 20:09
Show Gist options
  • Save aGuyNamedJonas/375f9f4441dfccb850bbf58ef181e7d6 to your computer and use it in GitHub Desktop.
Save aGuyNamedJonas/375f9f4441dfccb850bbf58ef181e7d6 to your computer and use it in GitHub Desktop.
Reliably determine the type of a variable in node.js
function getType (thing) {
switch (Object.prototype.toString.call(thing)) {
case '[object Object]':
return 'object'
break
case '[object Array]':
return 'array'
break
case '[object String]':
return 'string'
break
case '[object Number]':
return 'number'
break
case '[object Boolean]':
return 'number'
break
case '[object Null]':
return 'null'
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment