Hello and welcome to another new episode of learning simplified.
In this episode we are going to understand function with parameters.
In our previous episode of learning functions without parameters we have seen
that in case of calling a function we have to declare that here is the function, and
we have initiated starting bracket and a closing bracket; but there's nothing inside.
Inside this curly brackets or parentheses, we have used something that should be printed
into your HTML document.
Now after that all we have to do the remaining step is to
call your function into- either into head part or into the body part.
And of course within a script tag.
And here comes the result.
If we just reload, this is the result.
If we wanted to use the variable here then all we
did we just called in the variable name and we had assigned something here; for say this
whole bunch of things we have we have used it over here.
Here it goes.
And all we just did we just called in the particular variable
over here.
In the next step we just called in the function and if we press Control +
S and get back to our project and reload and we can see that the
effect is same; there is absolutely no problem.
We are now going to use some parameters.
Now in the first case when we will be using some particular parameters, for say, we are
using here only one, a single parameter- no need to declare here any variable; we are
just writing something over here for say we are just writing -
now the things to be considered over here or that we have called in a
string and we have concatenated that string with the parameter that we have used over
here so far; and now we are just writing here world.
Now you just press control + s and get back to our project and reload then we
can see that 'hello my cruel world' is the thing which is appearing as an output check
on it in our web code we can see over here that this is the string ' hello my cruel'
and then comes to parameter that has been mentioned inside this particular function
name and there we can see that we have called in the function, and then we have provided
some information - the string which is practically passed on into this particular
parameter and the same thing is executed into your web page.
Now in case if we now use..
And another thing, we are now concatenating another string
here - there it goes.
Now Press control + s, get back to your project and reload and you
can see that all those three strings those had been written over here - Hello world -
world enemy and intentions - all those things are practically being executed over here.
And another thing we give some particular space.
We absolutely need them.
Back to our project and reload and we can see that the
space is on.
All those particulars strings those have been defined into this segment that means when
we are calling these function names in this particular string of words or text or
anything that information that you are providing over here, those information I
practically getting passed to the same parameter that you have declared previously and
the exact same thing is being displayed into your web page.
So this is the thing that we call a function with parameters which actually
gather some information that has been provided to it and then it passes on the argument
and the same thing is now displayed into your web page.
Now the question is if we use more than one parameters, what will be the outcome?
When we are using two parameters over here x and
y - we are now providing and alert function over here that means at this time there will
be a popup dialogue box into your web page and it will be saying...
Here it is.
Now all we have to do we have to call in the function name; we have to provide this particular
information..
So here it is.
What should be the outcome in this particular case?
All we can see over here that we have practically assigned two parameters- x and
y and we provided an alert function this particular parameters and along with that
string - here comes the last parameter x and y.
We are passing on some information such as - 'apple-red', 'cat-white', 'bull-strong',
'tiger-stronger' - that means all those information this will be passed on to this
parameter accordingly; that means x will be passed on with the information - apple,cat,
bull and tiger and y will be passed on with the information - 'red', 'White', 'strong',
and 'stronger'.
And then there will be an alert box which will be suggesting this first
parameter x, then this parameter will be concatenated with the string and then this
particular string will intern be concatenated with with this particular parameter y.
So let's get back to your project and reload and here comes the first alert box apple
is red,then comes the second alert box cat is white, bull is strong and then comes this
tiger is stronger.
So here goes the thing that we have learnt in this tutorial.
Hope you guys have liked this tutorial.
If you guys have like this tutorial then do not hesitate to hit
that red subscribe button down below.
Hope to see you guys in our next tutorial.
Till then, bye.
Không có nhận xét nào:
Đăng nhận xét