- script.js
JavaScript
var string = '123';
var number = 123;
if (string == number) {
console.log('The values are equal!');
} else {
console.log('The values are not equal.');
}
Result
Goalscompleted
Let’s convert the second value to a string.
- Replace
==with===in the condition. Strict equality does not convert types, so the condition will be false. - Replace
numberin the condition withnumber.toString(). Both values are now strings, so the condition should be true.
Comments