Type coercion in JavaScript

Javascript

Public Domain

Induces a NaN value if the variable is not a number.

Download (right click, save as, rename as appropriate)

Embed

1
2
3
if (!isNaN(variable - 0)) { // if the response is a number:
    alert('The variable is a number')
    };