We have used isNaN() function for validation of the textfield for numeric value only. Text-field data is passed in the function and if passed data is number then isNan() returns true and if data is not number or combination of both number and alphabets then it returns false.
The Number() function converts the object argument to a number that represents the object’s value. If the value cannot be converted to a legal number, NaN is returned. Note: If the parameter is a Date object, the Number() function returns the number of milliseconds since midnight January 1, 1970 UTC.
Is Infinity a JS?
- typeof : This checks whether the value is one of the primitive data types. It will return a string specifying the type — “undefined” / “string” / “number” / “boolean” / “object” etc.
- instanceof : This checks the “kind” of an object.