Friday, February 2, 2018

What is the difference between toString() and join() in JavaScript

There is a very subtle difference. Example codes below explain much better than lengthy paragraphs.

I am using Node command terminal to work on the example(cleared earlier commands using ctrl+l).

The example in the order of execution from the command prompt:
1. Assign an array of integers to a variable x.
2. Display the content of variable
3. Use of toString()
4. Use of toJoin() - we can see there is no difference in the result. However, join function can take parameter defining the type of delimiter. The default parameter is ",".
5-7. Use of different delimiters







No comments:

Post a Comment