What do square brackets after function call mean?

Viewed 31

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] );
}
1 Answers

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.

Related