andy973
andy973

Reputation: 11

What do square brackets after function call mean?

I'm trying to understand the purpose of the [0] in the function call I came across and what value is returned to x?

x = my_function(var1, var2)[0];

function my_function(v1, v2){
  var v3, v4

  v3 = v1 * 3;
  v4 = v2 * 7;

  return( [v3, v4] );
}

Upvotes: 1

Views: 310

Answers (1)

Ricardo Aranguren
Ricardo Aranguren

Reputation: 610

They mean that the function returns an array and you only need the first element of that array.

return is not a function, by the way. You don't need the parenthesis.

Upvotes: 1

Related Questions