Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Understand the types of numbers JavaScript can work with; how to store numbers in variables; and why numbers in web forms aren't really numbers.

0:00
[MUSIC]

0:04
In the last stage, I talked about strings.

0:07
A string is a series of letters, numbers and

0:09
other characters enclosed in quote marks.

0:12
Strings are one type of data you'll work with in JavaScript.

0:16
Another type of information you'll encounter frequently is a number.

0:20
You use numbers to perform calculations,

0:22
like determining the total cost of items in a shopping cart.

0:26
Or adding points to a player's score in a game.

0:29
Or keeping track of the number of seconds passed since the visitor

0:32
performed a certain action.

0:34
In JavaScript, numbers can be whole numbers called integers,

0:39
like [SOUND] five, zero, negative 100, 9,999.

0:44
Or numbers with decimal points to represent fractions of a whole number,

0:50
like 3.14 or negative 9.88888 or 0.0000009.

0:55
Numbers like these with decimal points are also called floating point numbers.

1:00
JavaScript even lets you use scientific notation to represent really large or

1:06
really small numbers.

1:07
Just [SOUND] as with string values, you can put a number in a variable or

1:11
assign a number to a variable using the equal sign.

1:14
[SOUND] Unlike strings, however, you don't put quote marks around a number.

1:21
If you do, then you have a string, not a number.

1:24
This is a confusing part of working with strings and numbers.

1:27
So in this line of code,

1:29
the value stored in the variable aString isn't the number 10.

1:33
It's a string made up of the character 1 followed by 0.

1:38
This [SOUND] can lead to some weird and

1:40
confusing behavior, like making some math operations not work as expected.

1:44
We'll look at how to convert a string containing a number into

1:48
an actual number in a later video in this stage.

1:51
But just keep this in mind, a number inside quotes isn't really a number.
You need to sign up for Treehouse in order to download course files.
Sign up