var x = “12”; // Variable is a string

var y = x * 4;

What do you think the assigned value of variable y will be? Undefined? Not quite. The variable gets assigned a special, reserved word in JavaScript. It gets assigned to ‘NaN’, which is an abbreviation of ‘not a number’. When a variable is rendered ‘NaN’, you lose the ability to perform any arithmetic operations on the variable. The variable is effectively useless at this stage until you redefine it.

You can check whether a value is a number or not by using one of the built-in ‘global functions’ of JavaScript, called ‘isNaN()’. This function will accept a parameter and return either true or false depending if the parameter is a number or not. This probably sounds a bit more confusing than it actually is, so let’s see this in action: