Which comparison operator to use in JavaScript: == or ===?
Hi everyone! I just started learning JavaScript and ran into some confusion. Some tutorials say to use `==`, while others say to use `===`. I tried both, and they seem to work the same way, but then I came across some strange behavior.\n\nHere's an example:\n```javascript\nconsole.log(5 == "5"); // true\nconsole.log(5 === "5"); // false\n```\n\nWhy is that? After all, 5 is a number and "5" is a string. I expected both to return false, but the first one says true. Even stranger:\n```javascript\nconsole.log(false == 0); // true\nconsole.log(false === 0); // false\nconsole.log(null == undefined); // true\nconsole.log(null === undefined); // false\n```\n\nIt seems to me that `===` is stricter and more predictable, but I've seen a lot of code on GitHub where `==` is used. Which one is considered correct?
No answers yet.
Log in to leave an answer