+ 5
how to access argument/parameters?
If I pass more arguments than are defined, how to access those arguments? your answer is easy. use arguments [index_number] ; yeah you are right. there is my question. if I named a parameter "arguments" then how to access those arguments which is not defined. for example: function f(x, y){ return x+y+arguments; } f("HELLO ", " SHAKIB ", " HASSAN "); this f unction can access arguments which is not defined. function g(x, arguments) { return x+arguments+arguments [1]; } g("HELLO ", " SHAKIB ", " HASSAN"); this g function is not working like f function. so in this case how to access the arguments which is not defined? with out using rest operator.
6 odpowiedzi
+ 4
is there another way? with out using rest operator. Abhay
+ 1
Using rest operator !
function g(x,...arguments) {
return x+arguments[0]+arguments [1];
}
+ 1
KAZI MD SHAKIB HASSAN sorry but i don't know. Why would you want to do it anyway ? It's like asking if i override the behaviour for console.log , then how can i access the original console.log functionality ? I mean you just need to know the syntax of language and so you will never try to include arguments as a argument.
+ 1
In the function, all arguments are kept in an *object*: In my example I cast the arguments objects values to an array and output the array.
https://code.sololearn.com/Wj5J364yLluH/?ref=app
0
Je pense que JavaScript a fonction et multi paramètres peut mieux faire l'affaire.