+ 16

What is the difference between toString() and valueOf()?

var x =123; (100+23).toString() //returns 123 (100+23).valueOf() //returns 123 this two method what exactly define?

6th Apr 2019, 9:23 AM
Ahad
Ahad - avatar
3 Antworten
+ 13
thank you ☺
6th Apr 2019, 3:52 PM
Ahad
Ahad - avatar
+ 2
toString() coherses the data to a string and valueOf() returns the value of the string (if used in the context of the example) so toString() will return “123” and valueOf() will return 123
8th Apr 2019, 8:33 AM
Luke
Luke - avatar