- script.js
JavaScript
var string = '123';
var number = 123;
if (string == number) {
console.log('The comparison is working!');
} else {
console.log('I cannot compare');
}
Result
Goalscompleted
Let’s give the second value to the string type.
- Replace
==
with===
in the condition. The cast will stop working and the condition will not be met. - Replace
number
in the condition withnumber.toString()
. The condition should start working.
Comments