What is the output of this code and how? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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);

18th May 2020, 2:25 PM
Arjun Lahare
Arjun Lahare - avatar
1 Answer
+ 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()));
18th May 2020, 5:28 PM
Mind To Machine 💻🕆
Mind To Machine 💻🕆 - avatar