JavaScript Data Type: Numbers

By: Dusty Arlia
Published on August 9, 2012
Last Updated on Saturday, July 11, 2015 at 6:50 PM
Total Updates: 7

There is only one number data type in JavaScript: number. The number data type can represent both floating-point numbers (like 1.3) and integers (like 1). Numbers are frequently used in JavaScript programs. The numbers you use can be positive, negative, whole, or fractional. Here are some examples of numbers you can use with JavaScript: 1, 2.5, 3.333333, and -44. When you use a negative number, you have to include the subtraction operator (-) before the number.

Along with numbers, you will use mathematical operators. You will use your numbers and mathematical operators to perform calculations. For example, if you buy a $10 T-shirt with a $5 shipping cost, you can print your total to the screen using this JavaScript statement: document.write(10+5);

Using the JavaScript document.write() method, this program adds 10 and 5 together and prints the results to the screen.

Comments:

Ad: