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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With