js string is int code example

Example 1: js check if string is integer

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

Example 2: js check if string is int

function isNumeric(str) {

	// Check if input is string
	if (typeof str != "string")
    	return false

	// Use type coercion to parse the _entirety_ of the string
    // (`parseFloat` alone does not do this).
	// Also ensure that the strings whitespaces fail
	return !isNaN(str) && 
		!isNaN(parseFloat(str)) 
}

Example 3: how to check if a string is an integer javascript

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