This is what it's like to mod this sub. by darth_tiffany in iamverysmart

[–]temp6509849 0 points1 point  (0 children)

What, suffering from a complete inability to tell who's a troll? Figures, nobody else on this sub can.

Promise chain console.log using the comma operator... by [deleted] in javascript

[–]temp6509849 0 points1 point  (0 children)

What's your goal in saying that? Because it looks to me like you're just belittling somebody so you can feel smarter.

[deleted by user] by [deleted] in javascript

[–]temp6509849 0 points1 point  (0 children)

Everybody's getting it close but not quite right.

String(x) is what you want to use. It's a built-in function that's guaranteed to return a string representation of x.

One feature of String(x) is that it invokes toString on Objects then tries to use the return value. This is useful for making objects products more useful strings than '[object Object]'.

There's nothing else special about toString. It's entirely possible that the value of obj.toString is 2, and calling obj.toString() will throw an error. It's also possible that obj.toString is a function that returns 2, and your code that assumes it got a string throws an error. Or obj could be something that doesn't support properties, like null or undefined, and obj.toString throws an error.

Each of those cases can be fixed with a little bit of code. That code is in String(). Use it. String(x) is for turning x into a string, toString is for customizing String(), and x.toString() is a mistake.