Kylie Soderblom3,377 Points
What is the functional difference between Array.prototype.join() and Array.prototype.toString() ?
inStock.join(", ") does make a comma and a space between array elements while inStock.toString(", ") ignores the space and only has a comma between array elements.
Is there any other reason to use join instead of toString?
The biggest difference is that toString() just builds a string from an array with elements separated by only a single comma (and no spaces). In other words, there are no options.
With join(), you can specify ANY separator of your choice.
Keep in mind, however, join() and toString() would give the same result (when join is called without an argument).
var cars = ["Saab", "Volvo", "BMW"]; console.log( cars.join("---") );
Would log the string:
to the console.
I hope that helps.
Stay safe and happy coding!