Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active December 18, 2017 19:36
Show Gist options
  • Select an option

  • Save daliborgogic/10e4f3b34717f44ddcbd35bc9adbaad5 to your computer and use it in GitHub Desktop.

Select an option

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

daliborgogic commented Dec 18, 2017

Copy link
Copy Markdown
Author
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