Hey! Thanks for your article 😃
I knew most of them, except the last one. By the way, I was wondering : in which case : const nums = Array.of(1, 2, 3, 4, 5, 6);
is better than : const nums = [1, 2, 3, 4, 5, 6];
?
I think it's more likely to compare it to the array constructor. According to MDN
The difference between Array.of() and the Array constructor is in the handling of integer arguments: Array.of(7) creates an array with a single element, 7, whereas Array(7) creates an empty array with a length property of 7 (Note: this implies an array of 7 empty slots, not slots with actual undefined values).
It's the same, but one is a function whereas the other is a syntactical form. You could have a situation where you pass it as a parameter or in a variable, i.e.
f = Array.of
...
a = f(1,2,3)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey! Thanks for your article 😃
I knew most of them, except the last one. By the way, I was wondering : in which case :
const nums = Array.of(1, 2, 3, 4, 5, 6);
is better than :
const nums = [1, 2, 3, 4, 5, 6];
?
I think it's more likely to compare it to the array constructor. According to MDN
I didn't know this method either!
He asked about [1, 2, 3, 4, 5, 6] and not Array(7), is it the same?
it is essentially the same, I just pointed out what is a better comparison case with quote from the mdn docs
Thanks, I didn't know about that !
It's the same, but one is a function whereas the other is a syntactical form. You could have a situation where you pass it as a parameter or in a variable, i.e.
f = Array.of
...
a = f(1,2,3)