Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active December 18, 2017 19:36
Show Gist options
  • Save daliborgogic/10e4f3b34717f44ddcbd35bc9adbaad5 to your computer and use it in GitHub Desktop.
Save daliborgogic/10e4f3b34717f44ddcbd35bc9adbaad5 to your computer and use it in GitHub Desktop.
Check variable type
/**
* Check variable type
* @return {Boolean}
*/
export const isType = (type, val) => !!(val.constructor && val.constructor.name.toLowerCase() === type.toLowerCase())
@daliborgogic
Copy link
Author

daliborgogic commented Dec 18, 2017

isType('array', [])
true
isType('array', {})
false
isType('string', '')
true
isType('string', 1)
false
isType('number', '')
false
isType('number', 1)
true
isType('boolean', 1)
false
isType('boolean', true)
true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment