Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct terminology for Array functions on own line

I'm having a hard time trying to find the right term for a function like:

var array = [1, 2, 3];

array.pop();

return array; // returns [1, 2];

And:

var array = [1, 2, 3].pop();

return array; // returns 3

I personally just call the first example "Indirect" because you are indirectly triggering the function on the array and modifying it.

The second example I call, you guessed it, "Direct" because you are directly chaining the function to the array.

Sounds kinda silly, I know.

However, I am very well interested in the actual terminology for these specific pieces of code, if there is one.

like image 897
Shawn31313 Avatar asked Dec 15 '25 14:12

Shawn31313


1 Answers

In the second case you're doing:

[1,2,3].pop();

In the first case you're doing:

var array = [1, 2, 3];
array.pop();

This is simply called variable assignment.

What is creating some confusion in your question is that in the second example you assign the value 3 to a variable called "array", which should really be called something else.

like image 159
Christophe Avatar answered Dec 17 '25 05:12

Christophe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!