Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Foundations Numbers Review of Comparisons

Nicholas Lee
Nicholas Lee
12,474 Points

10=="ten" ? True or False

I got this questions in a quiz. Why is the answer false?

I thought that the two equal signs will change the value of "ten" slightly to its numerical value of 10 and then returning true. I know === compare based on its exact format. I thought == compares based more on its "value".

3 Answers

Roberto Alicata
PLUS
Roberto Alicata
Courses Plus Student 39,959 Points

10 == "10" is true

double equal signs get a numerical value from a string, but it is not so smart to understand that the word "ten" means the number 10

Check out these guys: "Source Decoded" on JS https://www.youtube.com/watch?v=84dZddrmZu8

Jason Saba
PLUS
Jason Saba
Courses Plus Student 3,862 Points

10 == "10" is false because they're different types. "10" is a string a whereas 10 is a number, so when you test the equality of one against the other it will return false because they're different types so technically they're not equal to one another.

Andrew Kiernan
Andrew Kiernan
26,892 Points

10 == '10' (double equals) is actually true, because javascript will use type coercion to get them into the same data type (I believe turning them both to strings). 10 === '10' (triple equals) will return false because it does a strict comparison which also compares data type, so if they are different data types the comparison will be false.