Michael Reynald Michael Reynald - 1 year ago 85
Javascript Question

Logical if difference

Recently, I came across a code like this:

if (0 === $something) { }


Is there any difference between the code above with:

if ($something === 0) { }

Answer Source

Actually there is no difference in both performance wise or in functional perspective. I can say it's a personal choice of coding style often called that as Yoda Style

In programming jargon, Yoda conditions (also called Yoda notation) is a programming style where the two parts of an expression are reversed in a conditional statement.

I prefer the later way as the first way kills the readability of code (at least for me)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download