You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DESCRIPTION
Yoda conditions are named so because the literal value of the condition comes first while the variable comes second.
For instance,
if ("red" === color) {
// ...
}
Yoda condition is fixed by switching the literal and variable.
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:
if (color === "red") {
// ...
}
This typically reads, "if the color equals red", which is arguably a more natural way to describe the comparison.
BAD PRACTICE
if ("red" === color) {
// ...
}
if (true == flag) {
// ...
}
if (5 > count) {
// ...
}
if (-1 < str.indexOf(substr)) {
// ...
}
RECOMMENDED
if (color === "red") {
// ...
}
let listingCondition;
if (rating && rating === 5) {
listingCondition = 'Awesome';
} else if (4 <= rating && rating < 5) {
listingCondition = 'Good';
} else if (3 <= rating && rating < 4) {
listingCondition = 'Average';
Expected literal to be on the right side of <= src/UI/Rating/Rating.js
listingCondition = 'Awesome';
} else if (4 <= rating && rating < 5) {
listingCondition = 'Good';
} else if (3 <= rating && rating < 4) {
listingCondition = 'Average';
} else if (2 <= rating && rating < 3) {
listingCondition = 'Bad';
Expected literal to be on the right side of <= src/UI/Rating/Rating.js
DESCRIPTION
Yoda conditions are named so because the literal value of the condition comes first while the variable comes second.
For instance,
if ("red" === color) {
// ...
}
Yoda condition is fixed by switching the literal and variable.
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:
if (color === "red") {
// ...
}
This typically reads, "if the color equals red", which is arguably a more natural way to describe the comparison.
BAD PRACTICE
if ("red" === color) {
// ...
}
if (true == flag) {
// ...
}
if (5 > count) {
// ...
}
if (-1 < str.indexOf(substr)) {
// ...
}
RECOMMENDED
if (color === "red") {
// ...
}
if (flag === true) {
// ...
}
if (count < 5) {
// ...
}
if (str.indexOf(substr) > -1) {
// ...
}
Find it here:
Expected literal to be on the right side of <=
src/UI/Rating/Rating.js
let listingCondition;
if (rating && rating === 5) {
listingCondition = 'Awesome';
} else if (4 <= rating && rating < 5) {
listingCondition = 'Good';
} else if (3 <= rating && rating < 4) {
listingCondition = 'Average';
Expected literal to be on the right side of <=
src/UI/Rating/Rating.js
} else if (4 <= rating && rating < 5) {
listingCondition = 'Good';
} else if (3 <= rating && rating < 4) {
listingCondition = 'Average';
} else if (2 <= rating && rating < 3) {
listingCondition = 'Bad';
Expected literal to be on the right side of <=
src/UI/Rating/Rating.js
} else if (3 <= rating && rating < 4) {
listingCondition = 'Average';
} else if (2 <= rating && rating < 3) {
listingCondition = 'Bad';
} else if (rating >= 1) {
listingCondition = 'Terrible';
The text was updated successfully, but these errors were encountered: