Avatar ·

Difference between == and === in JavaScript

Hello everyone! I recently started learning JavaScript and Node.js, and I encountered a misunderstanding of the difference between the == and === operators. They both seem to be used for comparison, but the results sometimes differ.

Here's a simple example that confused me:

console.log(5 == '5');   // true\nconsole.log(5 === '5');  // false\n\nconsole.log(null == undefined);  // true\nconsole.log(null === undefined); // false\n\nconsole.log(false == 0);  // true\nconsole.log(false === 0); // false

I understand that === is a strict operator, and == is a loose operator, but I don't fully grasp how this works in practice. I tried reading the documentation on MDN, but I would like to hear an explanation from experienced developers.

I expect to get clarification: