1
function construct(head, tail) {
  return cat([head], _.toArray(tail));
}

I'd like to know the role of '[' and ']' above. Is it an operator? Is it the array initialize literal?

This question is answered here and on the previous QnA(Use of [square brackets] around JavaScript variables).

I felt this weird because I am not used to javascript. But this is not a matter any more. I thought wrong and this is explained. Thanks!

Community
  • 1
  • 1
Jumogehn
  • 1,102
  • 3
  • 11
  • 29
  • 1
    I googled it for you - https://www.bing.com/search?q=javascript+what+square+brackets+mean - http://stackoverflow.com/questions/1629539/use-of-square-brackets-around-javascript-variables. – Alexei Levenkov Dec 19 '15 at 05:59
  • @Alexi Levenkov, I originally asked two questions. Previous QnA thread is ,yes, answers for my 1st question. But the other question is not answered there. You didn't googled. You bingged! *^^* – Jumogehn Dec 19 '15 at 07:20
  • 1
    You should not ask two questions in one post. Also most languages you've mentioned allow array initialization with variable like `int[] foo = {myVariable}` - so you may want to rewrite your second question if you decide to ask separate one for that. – Alexei Levenkov Dec 19 '15 at 07:34
  • 1
    Side note: please avoid using quote/code formatting for coloring - if it is your own text and not quote from some other source use plain text. – Alexei Levenkov Dec 19 '15 at 07:35
  • @Alexi Levenkov, I agree that in C/C++ variables can be placed in the array size expression. So it is common between C/C++ and Javascript. – Jumogehn Dec 19 '15 at 10:24

1 Answers1

1

It is initializing a 1 element array to pass to cat here. Brackets can be used to access elements on objects and arrays, and to represent an array literal like you have here.

Catalyst
  • 3,143
  • 16
  • 20