Created
May 23, 2018 07:55
-
-
Save rao123dk/63a75ee0a0f8bfb1fa82cb1b0c833943 to your computer and use it in GitHub Desktop.
Get the exact type of JavaScript Variables.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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