Functions
- Particular Business Logic called as Function.
- Functions are used to reuse the business logic.
- We can Declare the Functions with the help of "function" keyword.
- We Have Two Types of Functions.
1) Named functions
2) Anonymous Functions
Named functions
---------------
- The Function with the name called as Named function.
Syntax.
-------
function definition
-------------------
function function_name([arguments with datatype]):return type{
//Business Logic
}
//function calling
function_name();
Ex_1:
create the following function
@fun_one
"fun_one" return "Welcome...!"
call the fun_one.
Ex_2:
=> create the folowing function with 3 arguments
@fun_one
=> argumnets are string type.
=> call the fun_one.
Ex_3:
=> create the two functions
@fun_one
@fun_two
=> "fun_one" return "fun_two" definition.
=> "fun_two" retrurn "welcome" message.
=> call "fun_one"
Ex_4:
create the following functions.
@fun_one
@fun_two
pass "fun_two" definition to "fun_one" as argument.
"fun_one" displays the argument.
"fun_two" return "welcome...!".
Ex_5:
create the following function with two arguments.
@fun_one
@arg1 - string type.
@arg2 - Array of Hetrogeneous Elements.
pass "fun_two" & "fun_three" to fun_one as array
Assignment:
-----------
create the following functions.
@fun_one
@fun_two
@fun_three
@fun_four
@fun_five
"fun_two" return "fun_three" definition.
"fun_three" return "Hello...!" message.
"fun_four" return "fun_five" definition.
"fun_five" return "Hi....!" message.
pass "fun_two" & "fun_four" definitions to "fun_one" as arguments.
"fun_one" calling should display "Hello...!" & "Hi...!" message
- Particular Business Logic called as Function.
- Functions are used to reuse the business logic.
- We can Declare the Functions with the help of "function" keyword.
- We Have Two Types of Functions.
1) Named functions
2) Anonymous Functions
Named functions
---------------
- The Function with the name called as Named function.
Syntax.
-------
function definition
-------------------
function function_name([arguments with datatype]):return type{
//Business Logic
}
//function calling
function_name();
Ex_1:
create the following function
@fun_one
"fun_one" return "Welcome...!"
call the fun_one.
Ex_2:
=> create the folowing function with 3 arguments
@fun_one
=> argumnets are string type.
=> call the fun_one.
Ex_3:
=> create the two functions
@fun_one
@fun_two
=> "fun_one" return "fun_two" definition.
=> "fun_two" retrurn "welcome" message.
=> call "fun_one"
Ex_4:
create the following functions.
@fun_one
@fun_two
pass "fun_two" definition to "fun_one" as argument.
"fun_one" displays the argument.
"fun_two" return "welcome...!".
Ex_5:
create the following function with two arguments.
@fun_one
@arg1 - string type.
@arg2 - Array of Hetrogeneous Elements.
pass "fun_two" & "fun_three" to fun_one as array
Assignment:
-----------
create the following functions.
@fun_one
@fun_two
@fun_three
@fun_four
@fun_five
"fun_two" return "fun_three" definition.
"fun_three" return "Hello...!" message.
"fun_four" return "fun_five" definition.
"fun_five" return "Hi....!" message.
pass "fun_two" & "fun_four" definitions to "fun_one" as arguments.
"fun_one" calling should display "Hello...!" & "Hi...!" message
No comments:
Post a Comment