Difference Between == & === in JavaScript Last Updated : 21 Jun, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In JavaScript, comparison operators like == (double equals) and === (triple equals) are used to compare values, but they behave differently. The == operator is known as the loose equality operator. It compares two values for equality after performing type coercion, meaning it converts the values to the same type before comparing them.The === operator is called the strict equality operator. It checks for equality without type conversion, meaning both the value and the type must be exactly the same for the comparison to return true.Differences Between == and ===Here is the difference between == and === :== (Double Equals)=== (Triple Equals)Performs type coercion (converts values to a common type before comparison).No type coercion. Values must be of the same type and value to be equal.Compares only values after converting them to the same type.Compares both value and type exactly.Used when you want JavaScript to automatically convert types for you.Used for strict comparisons when you want to ensure that both type and value are identical.'5' == 5 returns true (because it converts '5' to 5).5' === 5 returns false (different types: string vs number).true == 1 returns true (because true is converted to 1).true === 1 returns false (different types: boolean vs number).null == undefined returns true.null === undefined returns false.Objects or arrays are compared by reference (not content).Objects or arrays are compared by reference (not content).How Double Equals (==) Works in JavaScriptHere is how double equals works :Type Coercion: == compares values after converting them to a common type.Same Type: If the values are the same type, it compares them directly.Different Types: If the values are different types, JavaScript converts one or both to a common type before comparison.Special Cases: null and undefined are equal to each other but not to other values.Now let's understand this with the help of example: JavaScript let s = "10"; // String let n = 10; // Number console.log(s == n); Outputtrue In this example"10" (string) is converted to 10 (number).The comparison becomes 10 == 10, which is true.How Triple Equals (===) Works in JavaScriptHere is how triple equals works:Strict Comparison: The === (triple equals) operator checks both the value and type of the operands.No Type Coercion: Unlike ==, === does not perform type coercion. If the operands are of different types, the comparison will return false.Same Type and Value: For === to return true, both the value and the type must be exactly the same.Objects and Arrays: Objects and arrays are compared by reference, meaning they must point to the same instance in memory to be considered equal.Let's understand this with the help of example: JavaScript console.log(5 === 5); console.log('5' === 5); console.log(true === 1); console.log(null === undefined); Outputtrue false false false Best Practices for Using == and === in JavaScriptUse === by default for strict comparisons (value and type must be the same).Avoid == unless you specifically need type coercion (e.g., comparing null and undefined).Be cautious with == when comparing values of different types (e.g., strings and numbers).Use === to prevent unexpected behavior from JavaScript’s automatic type conversion.Only use == when you understand how type coercion works and it's intentional.ConclusionIn JavaScript, == performs type coercion and compares values after converting them to a common type, while === checks both value and type without coercion. It’s best to use === for more predictable and reliable comparisons. Use == only when type coercion is intentional and necessary. Comment More infoAdvertise with us Next Article Difference between != and !== operator in JavaScript P prashanth_santhanaraman Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League JavaScript-Questions Geeks Premier League 2023 +1 More Similar Reads Difference between != and !== operator in JavaScript != operatorThe inequality operator (!=) is the logical opposite of the equality operator. It means "Not Equal" and returns true whereas equality would return false and vice versa. Like the equality operator, the inequality operator will convert data types of values while comparing. For example 1 != 2 min read Difference Between && and || Operators in javaScript In JavaScript, logical operators && (AND) and || (OR) are used to perform the logical operations on values. These operators are commonly used in the control flow and decision-making within the programs. Understanding the differences between these operators is essential for writing efficient 2 min read Difference between a || b < 0 and a < 0 || b < 0 in JavaScript ? Both expression almost looks the same when we focused on the || (Or) operator, but both expressions are different from each other. To know the final conclusion, we have to get the knowledge of the || (Or) operator first. JavaScript || (Or) Operator: The âORâ operator is the opposite of the âANDâ ope 2 min read Difference between the (=), (==), and (===) operators in PHP In PHP, the '=' operator is used for assignment, while the '==' operator is used for loose equality comparison, meaning it checks if two values are equal without considering their data types. On the other hand, the '===' operator is used for strict equality comparison, meaning it checks if two value 3 min read What is the difference between == and === in PHP ? In this article, we will discuss the differences between '==' and '===' operators in PHP. Both are comparison operators used to compare two or more values. == Operator: This operator is used to check the given values are equal or not. If yes, it returns true, otherwise it returns false. Syntax: oper 2 min read Difference between double equal vs triple equal JavaScript Double equal: The double equal('==') operator tests for abstract equality i.e. it does the necessary type conversions before doing the equality comparison. Triple equal: The triple equal('===') operator tests for strict equality i.e it will not do the type conversion hence if the two values are not 2 min read Like