What is === in JavaScript?

Hey! I'm Logan, building the open-source LeetCode alternative TechBlitz with a focus on creating a personalized platform to help aspiring developers learn to code! So what is '==='? The triple equals operator (===) in JavaScript is a strict equality comparison operator that checks both value and type equality. Unlike its more lenient cousin, the double equals operator (==), triple equals doesn't perform type coercion before making the comparison. This makes it more predictable and generally safer to use in your code. Understanding Double Equals vs Triple Equals: // Double equals (==) with type coercion console.log(5 == "5"); // true console.log(1 == true); // true // Triple equals (===) without type coercion console.log(5 === "5"); // false console.log(1 === true); // false In this example, we can see how double equals (==) performs type coercion, converting the string "5" to a number before comparison. Triple equals (===), however, checks both value and type, resulting in false when comparing different types. The callback function takes the current element as its parameter (num in this case) and returns true if the number is even (num % 2 === 0). Filter creates a new array containing only the elements for which the callback returned true.

Feb 8, 2025 - 12:33
 0
What is === in JavaScript?

Hey! I'm Logan, building the open-source LeetCode alternative TechBlitz with a focus on creating a personalized platform to help aspiring developers learn to code!

So what is '==='?

The triple equals operator (===) in JavaScript is a strict equality comparison operator that checks both value and type equality. Unlike its more lenient cousin, the double equals operator (==), triple equals doesn't perform type coercion before making the comparison. This makes it more predictable and generally safer to use in your code.

Understanding Double Equals vs Triple Equals:

// Double equals (==) with type coercion
console.log(5 == "5");    // true
console.log(1 == true);   // true

// Triple equals (===) without type coercion
console.log(5 === "5");   // false
console.log(1 === true);  // false

In this example, we can see how double equals (==) performs type coercion, converting the string "5" to a number before comparison. Triple equals (===), however, checks both value and type, resulting in false when comparing different types.

The callback function takes the current element as its parameter (num in this case) and returns true if the number is even (num % 2 === 0). Filter creates a new array containing only the elements for which the callback returned true.