- script.js
JavaScript
var string = '123';
var number = 123;
if (string === number.toString()) {
console.log('The comparison is working!');
} else {
console.log('I cannot compare');
}
Result
Goalscompleted
Now let’s compare the numerical values of both variables.
- Remove the
.toString()command, leaving onlynumberin the comparison. - In the comparison, replace the variable
stringwith theparseInt(string, 10)command.
Comments