Today #day32 of #100daysofcode, I have completed 4.26 and 4.27 lessons and two practice programs in JS course. @Sololearn
1. Using multiple parameters with Functions
i. Multiple Parameters
- You can define a function with 2 parameters separated by, inside the parenthesis.
- Syntax: function myFunc(x, y) { // some code }
Note:
- These parameters cane be used inside the function's definition.
- Function parameters are the names listed in the function definition.
- when you call the function, make sure to mention the parameters in the order where you defined them in the function definition.
If you pass more arguments than you defined, the access arguments will be assigned to an array.
Ex: How to use these extra arguments,
function sayHello(name, age) { document.write( name + " is " + age + " years old."+arguments[2]); } sayHello("John", 20,7)
Note:
- you can call the function as many times as you needed.
- JavaScript function do not check the number of arguments received.
- if the number of arguments passed are less than that of the parameters defined then the access parameter will be set undefined.
2. The return statement
ii. Function Return
- A function can have an optional return statement it will return value to function.
- this return statement is useful when making calculations to return a result.
- JavaScript stops executing a function when it reaches the return statement.
- use the return statement to return a value.
- if you did not return anything from function it will return undefined.
Images of lesson completed
Conclusion
- Using multiple parameters with Functions
- The return statement
- Function Return
- quiz
- code
My Code:
Morethanoneparameter [code]