0

Is there a difference other than preference between performing evaluations forwards rather than backwards?

For instance, say we wanted to check if a value was an empty string (poorly in this example, admittedly) we could do one of two things:

"" === myValue

or

myValue === ""

Is one of these more correct than the other? I personally prefer the second way as it is more semantic and easier to read, but I've noticed a lot of Java developers who write small bits of JavaScript tend to write it the first way.

Also please let me know if there is a better place to ask this, I couldn't find one but I am happy to re-post this in a different board.

StephenRios
  • 1,992
  • 2
  • 23
  • 38
  • 3
    Here is the answer you're looking for : https://softwareengineering.stackexchange.com/questions/74086/if-constant-variable-vs-if-variable-constant – MrGeek Sep 05 '17 at 18:54
  • It's good practice to put the boolean first, but preferential. – zfrisch Sep 05 '17 at 18:56
  • @zfrisch: preferential, yes, but that might depend upon who's signing the paychecks and what the established "coding standards" might be. I have seen a couple of people get fired over failing to follow the established coding standards -- especially when a major bug causes customer or other financial loss. – Paul T. Sep 05 '17 at 19:02
  • @PaulT. You're right, but I view that as a different thing. If my boss asked me to put the boolean after, even though it was bad practice, I would do it. Established workplace "coding standards" should always be followed however outdated, correct or incorrect they might be. – zfrisch Sep 05 '17 at 19:04

0 Answers0