ITP

BSc IT - Web Designing

Difference between "==" and "===" operators in JavaScript with example.

In : BSc IT Subject : Web Designing

In JavaScript, both == and === are comparison operators used to check if two values are equal, but they differ in how they compare those values.

  == (Loose Equality Operator)

  • Compares values only , not the data types .

  • It performs type coercion , meaning it converts the data types of the values to match before comparing them.

Example: 

console.log(5 == "5"); // true
Here, JavaScript converts the string "5" into a number before comparing, so the result is true.

 === (Strict Equality Operator)

  • Compares both value and data type .

  • Does not perform type coercion , so the values must be the same type and value to return true.

Example:

console.log(5 === "5"); // false
 
Even though the values look the same, their types are different (number vs. string), so the result is false.

About us

A truly open platform where you may ask questions and get answers. We also provide comprehensive and easy-to-understand answers to question papers.  discover...

Site status

Flag Counter

Privacy Policy

Sitemap