From 38e9d9499e98717c9f034064e26abca91317db00 Mon Sep 17 00:00:00 2001 From: "deepsource-dev-autofix[bot]" <61578317+deepsource-dev-autofix[bot]@users.noreply.github.com> Date: Thu, 3 Aug 2023 06:54:14 +0000 Subject: [PATCH] refactor: fix Yoda conditions Yoda conditions are named so because the literal value of the condition comes first while the variable comes second. For instance, ```js if ("red" === color) { // ... } ``` Yoda condition is fixed by switching the literal and variable. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 58ccb924..9022718e 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ function isNumber(num) { console.log("Number is false"); } else if (!!x) { console.log(`Number: ${x}`); - } else if (2 == x) { + } else if (x == 2) { } } @@ -63,7 +63,7 @@ let result = isFooAvailable({ function checkYoda() { let yoda = true; - if (true == yoda) { + if (yoda == true) { console.log("I am yoda"); } }