STRINGS AND NUMBERS
In the last lesson, you learned about getting strings and numbers as user input; however, before moving on to conditions and loops, look a little more closely at using strings and numbers.
A number is either an integer (whole number, no decimal point) or a floating-point number (includes a decimal point and values to the right of the decimal point).
JavaScript allows you to work with values in decimal (base 10), hexadecimal (base 16), and octal (base 8).
The following are a few rules:
- Decimal values can't begin with a leading zero. Your script must strip the leading zeroes from the input string or use a number parsing function, such as parseInt(), before performing any math calculations on the input. (More details on parseInt() are presented later in this lesson).
- Hexadecimal integers begin with a leading 0x or 0X (that's zero, not an O). Hex code for color is a hexadecimal triplet (three hex values), but not all hex values are in this form. For example, 0X2B, 0X1a, 0xcc are all valid hex values.
- Octal values begin with a leading zero followed by any digits between 0 and 7.
Because JavaScript is weakly typed, it's important to understand how JavaScript converts from strings to numbers and vice versa.
