+ 3
What is the output of this code and how?
Number.prototype.reverse=function(){ let bar = this+""; let eggs=""; for(let i in bar){ eggs+=bar.charAt(bar.length-i-1) } return eggs; } var a =32,b=77; console.log(a.reverse()+b.reverse);
1 Antwort
+ 1
*b.reverse()
Basically you implemented a method to return the reversed of this integer when invoked
But that returned value is a string
Therefore the "+" operator will only concatenate the two values. To add them you need to convert them to an integer
You can use pareInt() for that purpose
var a =32,b=45;
console.log(parseInt(a.reverse()) + parseInt(b.reverse()));