I am new to js, so please be careful with me :)
I want to understand where we can use the point operator for some variable (in this case, an array), and when we cannot. consider the following code:
function f1(x) {
return x*x;
}
console.log(map(f1, [1,2,3,4,5]));
console.log([1,2,3,4,5].map(f1));
function f2(arr) {
return arr;
}
console.log(f2([1,2,3,4,5]));
console.log([1,2,3,4,5].f2());
I know that the examples are quite different, but still - in example 1, both printing works (and prints the same) - even when using the syntax array.function(..), while in example 2 the second print causes an error. basically, what is the difference between them and why does it work only in example 1?
and in general - can I apply this method to various types of variables (numbers, Booleans, etc.)?