Skip to content

Commit

Permalink
Docs: more accurate yoda-speak (#6497)
Browse files Browse the repository at this point in the history
* more accurate yoda-speak

* tightening up the yoda-speak to avoid confusion

* remove ellipses
  • Loading branch information
tonylukasavage authored and nzakas committed Jun 22, 2016
1 parent 3b0ab0d commit b7d8c7d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/rules/yoda.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ if ("red" === color) {
}
```

This is called a Yoda condition because it reads as, "red is the color", similar to the way the Star Wars character Yoda speaks. Compare to the other way of arranging the operands:
This is called a Yoda condition because it reads as, "if red equals the color", similar to the way the Star Wars character Yoda speaks. Compare to the other way of arranging the operands:

```js
if (color === "red") {
// ...
}
```

This typically reads, "color is red", which is arguably a more natural way to describe the comparison.
This typically reads, "if the color equals red", which is arguably a more natural way to describe the comparison.

Proponents of Yoda conditions highlight that it is impossible to mistakenly use `=` instead of `==` because you cannot assign to a literal value. Doing so will cause a syntax error and you will be informed of the mistake early on. This practice was therefore very common in early programming where tools were not yet available.

Expand Down

0 comments on commit b7d8c7d

Please sign in to comment.