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 trialJose Gutiérrez
9,370 PointsIs there any difference in the order of elements inside the if statement, I mean, is the same if(a===b) and If (b===a)?
Have I to follow any rule in the order of the elements when i make a comparaison inside an If statement?
1 Answer
Alexander Davison
65,469 PointsNope. a === b
is the same as b === a
. :)
A good example:
Let's say a
is 3 and b
is 3, too.
Our code is just a === b
, and when we run the program, JavaScript behind the scenes changes a
to 3 (that's a
's value) and b
to 3, too (also b
's value). That means JavaScript replaces a
and b
both with 3:
3 === 3
Also, if our code was b === a
, then it will also change to the code above since a
and b
are the same.
It's the same if a
and b
are different :) Order doesn't matter if you are using ===
, ==
, !==
, or !=
. However, with >
and <
, it could cause a difference since 1 > 2 isn't the same as 2 > 1
.
I hope this post helps you.
Good luck! ~Alex
Jose Gutiérrez
9,370 PointsJose Gutiérrez
9,370 PointsVery helpfulThanks!!!
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsNo problem :)