2

What's the difference between the following declarations:

  1. var num1: [number];
  2. var num2: number[];
  3. var num3: Array<number>;

It seems that num2 and num3 are interchangeable, but what about num1?

Which declaration should I use when?

3
  • Can you make your question title do more than just name a language and a feature? With 8.69 million questions on Stack Overflow, it is helpful when titles really describe the question. Commented Jan 18, 2015 at 11:23
  • 1
    @LightnessRacesinOrbit I am here because of google where I searched for almost the exact same string as this title and ended up here. So disagree. Commented Jan 19, 2015 at 10:00
  • @Clark: You got lucky. You're also but a single sample. The benefits of a good, unique question title are both well-documented and self-evident. Commented Jan 19, 2015 at 17:46

1 Answer 1

4

1 is a tuple type, so in this case num1 must be a 1-element array containing a number. If you declare it as var num1: [number, string, string]; then num1 must be a 3-element array containing a number, a string and another string in that order.

2 and 3 are identical; it doesn't matter which one you use.

Sign up to request clarification or add additional context in comments.

1 Comment

Compare the dry pages of documentation to the first 2 lines of this answer. I came here to see the difference between [] and <> for arrays, and ended up understanding tuple types. Awesome.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.