Quick A: Because it catches most cases where you accidentally wrote =
instead of ==
.
From SO:
Reason for using '5 == myValue' in conditionals
I've come across some code that flips how a condition is checked and was wondering why this would be done aside from a weird personal quirk. I've never seen any text books use it nor have I seen any sample code done this way.
// why do it this way? if (5 == myValue) { // do something } // instead of: if (myValue == 5) { // do something }I've only seen this way for
==
operand but not for any other operands.
Add a Comment
Comments are closed.