Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed JavaScript Numbers!
You have completed JavaScript Numbers!
Preview
Learn how treating strings like numbers can lead to unexpected behavior.
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
For example, the prompt command you used
in a previous course returns a string.
0:00
That is, whatever the user types
into the prompt dialog box.
0:00
Even if you ask for users' age and
they type the number 32,
0:03
JavaScript still treats
it as a string of text.
0:07
It returns a string
with two numbers in it.
0:10
This is also true when
working with web forms.
0:13
Say you had a text field in a form
that asked someone to type the number
0:15
of times they've been to
the movies this year.
0:18
If they type 1, 10, 100 or 200,
0:21
JavaScript will still treat the value
inside that text field as a string value.
0:24
So let me show you how treating strings
like numbers can lead to weird and
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up