

Learn function parameter in Javascript by top digital marketing companies in pune
Overview function parameter
IOS feature I would like to touch on. And this is a little bit more advanced but is a way to basically get an undefined number of arguments and figure out what those arguments are. So explain that first of all I'm going to show how top digital marketing companies in Pune used to be done and then we'll see how we can use what's called risk parameters to kind of Grabow an indefinite number of arguments. So let's say we had a function here to just log everything out log all arguments for example. And it takes an X Y and Z and all it does is a console logs out those arguments. So there is a built-in method already to do so and there's a reserved keyword in javascript called arguments and if we do this as per top digital marketing companies in Pune essentially it creates an object and it associates the object with the argument.
So, in other words, the object will have a key value Association and the key will be the index and the value will be whatever the argument is. And if you want to see that in action. Let's invoke this function log all arguments and we'll give it a one two and three. So let's clear this or run it and we see that it created an object here arguments and that's fine. You might wonder why it starts with digital media agency and is because javascript like a lot of other programming languages has a zero-based index. In other words, what's that position. One in computational thinking is actually positioned zero. It makes sense if any of top digital marketing companies in Pune done any kind of programming before. So, in any case, this has created an object for us and it might be easier to use different numbers actually with the four or five and six we can see it more clearly. Right so here we see the first argument or argument at position is the number and is and is. Right. So just think of this as and really. And this is fine.
Applications of function parameter
This works and this will be useful if, for example, you don't know how many arguments your function will be taking. So for example, if you just told your function to expect argument x and then you actually pass in three arguments. Well, let's see what happens. But it still counts it. And if you're familiar with manipulating objects you could access for example the argument at position or an index. Let's see what that does. Right. That's just returned us from top digital marketing companies in Pune to number four. We could also access argument at a position which is. The last one would be five of course but that's fine. That works a little bit clunky though because it's an object we can't use Array methods on it.
So for example, if we passed in you know six five to six Let's say we wanted to do kind of a sort method on these we wanted to sort it based on the lowest number to highest and it's a lot harder to do that on an object and it would be an array. Right. And let's take a quick look again we'll cancel all of these arguments out. So we see we have a bunch of things that are passed in the order they've been passed in and we also can't really tell which ones we're expecting and which ones we aren't expecting. And the way we solve this and you know this is it's a little bit higher level so I wouldn't worry about it too much if it's not clear what's happening but what we would do is if we wanted to basically turn this into an array.
And we want to see you know contrast what we were expecting versus what we weren't expecting. In this case, we're just telling our function to expect one argument right. But we are passing it in a whole bunch which might have some unintended consequences if we're not aware of that. So you know top digital marketing companies in Pune could console log x that will tell us what we're expecting is. But again it's kind of hard to compare this and we're not sure we have an undetermined number of other arguments were passed in. So what we could do is we could create say a constant args or arguments and we can basically do something like this and we can call a prototype method on something that's not technically a or we can call an array method on something that's not Tecla get array.
If we get something like this and again I wouldn't worry about this too much because we're going to be looking at the ESX way of doing this instead. Basically array of a prototype that slice it calls so the slice is an array method. And we're doing a call to basically use top digital marketing companies in Pune on something that's not an array and we say arguments right. Is that reserved keyword. And we basically take the length of the log all arguments and we slice out the arguments. That's basically after the length of the arguments. So it's going to look like this log all arguments length it this way we can basically slice out the unexpected arguments from the expected arguments. Right, so you can see this is kind of tedious if you ever need to do this and think what ESX will help us solve this. But in any case here if we cancel that log out our eggs at this point. Let's take a look. There we go we've transformed it into an array and now we can tell. OK. So six is not in there right but five to ten and six.
© 2019