js check if string is integer
snippet in javascript

js check if string is integer

user1440

var myString     =  "abc123";
var otherString  =  "123";
/* isInterger() checks if an value repersents an int  */

isInteger(myString);    //returns false
isInteger(otherString); //returns true

javascript is number an integer

user5679

Number.isInteger(value)

//returns a Boolean

javascript is variable a string

user634

if (typeof myVar === 'string'){
    //I am indeed a string
}

js check if string is number

user4205

isNaN(num)         // returns true if the variable does NOT contain a valid number

isNaN(123)         // false
isNaN('123')       // false
isNaN('1e10000')   // false (This translates to Infinity, which is a number)
isNaN('foo')       // true
isNaN('10px')      // true

js check if string is integer

user9965

function isInt(str) {
  return !isNaN(str) && Number.isInteger(parseFloat(str));
}