Search⌘ K
AI Features

Discussion: Do You Trust Your Eyes?

Explore how JavaScript compares strings with visually identical characters that differ in encoding. Understand why such comparisons return false and learn to apply the normalize() method effectively. This lesson helps you grasp string normalization forms and improve precision in string handling for more robust JavaScript coding.

Verifying the output

Now, it’s time to execute the code and observe the output.

Javascript (babel-node-es2024)
// Two strings containing similar characters
const str1 = "Château";
const str2 = "Château";
console.log(str1 === str2);

Understanding the output

Some characters may seem identical to our eyes, but the JavaScript engine has its own special way of looking at things. The reason this code outputs false is because the two words Château and Château are not exactly the same when it comes to how they’re written, even though they look pretty similar.

In the first ...