Skip to content

Instantly share code, notes, and snippets.

@rao123dk
Created May 23, 2018 07:55
Show Gist options
  • Save rao123dk/63a75ee0a0f8bfb1fa82cb1b0c833943 to your computer and use it in GitHub Desktop.
Save rao123dk/63a75ee0a0f8bfb1fa82cb1b0c833943 to your computer and use it in GitHub Desktop.
Get the exact type of JavaScript Variables.
function typeChecker(_input){
if([undefined, null, NaN].includes(_input)){
return _input;
}else if(_input === 'true' || _input === 'false'){
return "Boolean";
}else if(new RegExp(".*[a-zA-Z]+.*").test(_input) || _input === ''){
return typeof _input;
}else{
return Number.isInteger(+_input) ? 'integer' : 'flaot';
}
}
console.log(typeChecker(undefined));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment