isNaN
Checks if a value is a an illegal number (Not-a-Number). The function attempts to convert the tested value to a number before checking it. Therefore, a numeric value in string format, for instance, will not be identified as an illegal number.
Syntax
function isNaN(value: any): boolean
| Parameter | Description |
|---|---|
value
|
Value you wish to evaluate if it is an illegal number. |
Return Value
- true – The supplied value is an illegal number.
- false – The supplied value is not an illegal number.
Examples
In this example:
- We check if an input variable is an invalid number.
- If true, we display the following message: Invalid. Please enter a valid number.
- Otherwise, we display a Success message.
- For details on how to display messages, see setMessage.
if(isNaN(input)) {
setMessage('Invalid. Please enter a valid number');
} else {
setMessage('Success.');
};