r/coding • u/yangzhou1993 • Jun 20 '21
3 Uses of the Three Dots in JavaScript
https://medium.com/techtofreedom/3-uses-of-the-three-dots-in-javascript-8d6b83f179ce24
u/KeytarVillain Jun 20 '21 edited Jun 20 '21
In C or C++, we need to define an array at first and then use a for loop to iterate all characters and add them into the array one by one.
Uhh, no?
std::string author = "Yang";
std::vector<char> authorChar(author.begin(), author.end());25
u/FIuffyRabbit Jun 20 '21
I wonder how much of /r/coding is people posting their own articles and their own articles that are paywalled.
0
Jun 20 '21
[deleted]
4
u/KeytarVillain Jun 20 '21
Yeah, depends on what they mean by "array", but I was assuming one that you can manipulate like a js array.
3
u/kag0 Jun 20 '21
Mmm, is the "JavaScript article using loose C++ knowledge to contrast JS syntax" trope not run out?
That aside, I don't love the ellipsis syntax. I recognize its necessity in some cases for a typed language, but it can be cryptic and unnecessary in JS.
I know that's a bit vague, I can elaborate if anyone cares.
4
u/fearofcorners Jun 20 '21
OP, I think you should update this to use other ES6 features like arrow functions and the
letkeyword in your code examples. New JS developers (to whom this is presumably aimed?) do not generally understand the difference between things likevarandlet, and they're better off using the more predictable ES6 versions. Thanks for posting!