I was given this code:
if (num == 100 && num== 200 && num==300) {
console.log('it works!');
}
the condition needs to be true so that it prints "It works!" in the console.
I got these codes here and would really like to know how it works. Also, what's the difference between valueOf and toString?
Any explanation would be much appreciated. Thanks!
const num = {
value: 0,
valueOf: function() {
this.value += 100;
return this.value;
}
}
if (num == 100 && num== 200 && num==300) {
console.log('it works!');
}
-
const num = {
value: 0,
toString: function() {
this.value += 100;
return this.value;
}
}
if (num == 100 && num== 200 && num==300) {
console.log('it works!');
}