- 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 onlynumber
in the comparison. - In the comparison, replace the variable
string
with theparseInt(string, 10)
command.
Comments