JavaScript Example

JavaScript Numbers

Numbers can be written with or without a decimal point
Numbers that are too large or too small can be written using exponential notation
Numbers are rounded to 15 digits
Floating-point arithmetic is not always 100% precise
However, this problem can be solved by multiplying and dividing by 10
Adding two numbers will produce a new number
Adding two number strings will produce a concatenated string
Adding a number and a number string will also produce a concatenated string
Adding a number string and a number will also produce a concatenated string
Common mistakes when adding strings and numbers 1
Common Error 2: Adding a string and a number
JavaScript will try to convert strings to numbers in division operations
JavaScript will try to convert strings to numbers in multiplication operations
JavaScript will try to convert strings to numbers in subtraction operations
JavaScript will not convert strings to numbers in addition operations
The number divided by a string is no longer a number
Dividing a number by a number string results in a number
The global JavaScript function isNaN() determines whether a value is a number
Using NaN in mathematical operations will always return NaN
Using NaN in mathematical string operations will concatenate NaN
The type of NaN is number (no, typeof NaN returns number)
If a number outside the maximum possible number is calculated, it will return infinity (Infinity)
Division by zero will generate Infinity
Infinity is also a number (typeof Infinity returns number)
Constants prefixed with 0x are interpreted as hexadecimal
The toString() method can output numbers in hexadecimal, octal, or binary
Numbers can be objects
Numbers and objects cannot be safely compared
Objects and objects cannot be safely compared

Example Explanation: Numbers