Mahir freeCodeCamp • top-learn-data-types-and-conditionals

Learn Data Types and Conditionals Lesson G

Ringkasan Pelajaran

JavaScript also has the ability to compare types and values using the strict equality operator `===`. This operator checks if the two values are equal and of the same type. For example:

JavaScript also has the ability to compare types and values using the strict equality operator ===. This operator checks if the two values are equal and of the same type. For example:

let x = 5;
let y = "5";

let result = x === y;

console.log(result); // false

In this example, the result variable will contain false because x is a number and y is a string. But if you use the == operator, the result will be true because JavaScript will convert the string to a number and compare the values.

This operator is called the strict equality operator because it checks for both value and type equality. It is often recommended to use the === operator to avoid unexpected results when comparing values.

There is also a strict inequality operator !== that checks if the two values are not equal and of the same type.

There are a lot of ways to use the strict equality operator, and it’s important to understand how it works.