Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

verify if something is a number javascript

// parseInt is one of those things that you say wtf javascript?
//if you pass to it any argument with number first and letters after, it
// will pass with the first numbers and say yeah this a number wtf?
let myConvertNumber = parseInt('12wtfwtfwtf');
console.log(myConvertNumber);
// the result is 12 and no error is throw or something
//but this
let myConvertNumber = parseInt('wtf12wtf');
console.log(myConvertNumber);
// is NaN wtf?
//if you truly want an strict way to know if something is really a real number
// use Number() instead
let myConvertNumber = Number('12wtf');
console.log(myConvertNumber);
// with this if the string has any text the result will be NaN
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #verify #number #javascript
ADD COMMENT
Topic
Name
9+3 =