Numbers
In JavaScript there are no 'types' of numbers. However, decimal points do add precision to a degree. 'Integer' (non-decimal) values are accurate up to 15 digits, while decimals are accurate up to 17 digits.
Floating point arithmetic can be inaccurate:
var x = 0.1 + 0.2; // 0.30000000000000004
NaN¶
The worst name in all of programming goes to NaN.
NaN (not-a-number) is a number type. NaN results from operations in which the result is non-numerical, like trying to divide a number by a string.
var x = 5/"Banana"; // NaN
Skill Drill¶
In the Chrome developers console, practice declaring and initializing variables.
Declare a variable
num.- Assign
numthe value of4/0. Type the variable name (num) into the console and press 'return'. What is the value ofnum?- What is
num - 5?- What is
num - num?NaNis a valid number in JavaScript, but what happens when you subtract a number from it? (NaN -4)