Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions eslint/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const foo = 42
let bar
console.log("Hello World")
if (foo == "42") {
console.log("Loose equality!")
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use strict equality instead of loose equality.

Replace the loose equality operator (==) with strict equality (===) to avoid unexpected type coercion behavior. This prevents potential bugs and aligns with JavaScript best practices.

-if (foo == "42") {
-    console.log("Loose equality!")
+if (foo === 42) {
+    console.log("Strict equality!");
+}

Alternatively, if you specifically need to compare with a string, convert the number to string:

-if (foo == "42") {
-    console.log("Loose equality!")
+if (foo.toString() === "42") {
+    console.log("String comparison!");
+}

Also add a semicolon after the console.log statement:

-    console.log("Loose equality!")
+    console.log("Loose equality!");

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In eslint/test.js around lines 4 to 6, replace the loose equality operator (==)
with the strict equality operator (===) to prevent type coercion issues. Also,
add a semicolon after the console.log statement to follow JavaScript syntax best
practices.