0

Let's say I have a variable x and I want to check if x equals string 'y'.

Is there any difference if I did either of:

  • x === 'y'
  • 'y' === x

Or let's say that I want to check if y is bigger than x:

  • x < y
  • y > x

The difference can be anything, in terms of how the code is executed, and which is preferable, not only in terms of performance, if any, but also readability.

yaserso
  • 2,638
  • 5
  • 41
  • 73
  • 2
    maybe you have a look to [Yoda conditions](https://en.wikipedia.org/wiki/Yoda_conditions) – Nina Scholz Jul 16 '19 at 08:40
  • 1
    Possible duplicate of [Logical if difference](https://stackoverflow.com/questions/45334353/logical-if-difference) and [Javascript: Order of operands in comparison operator](https://stackoverflow.com/questions/38035875) and [Checking for null - what order?](https://stackoverflow.com/questions/10983573) – adiga Jul 16 '19 at 08:44
  • 1
    Usually it doesn't matter, unless either side is another expression, the left-handed side expression will always execute first. – Hao Wu Jul 16 '19 at 08:45

0 Answers0