66 < style >
77 body {
88 margin : 0 ;
9- font-family : "Comic Sans MS" , sans-serif;
9+ font-family : "Comic Sans MS" , sans-serif;
1010 }
1111 h2 {
1212 background-color : lightgreen;
1313 text-align : center;
1414 padding : 10px ;
1515 }
1616 div {
17- background-color : seagreen ;
18- padding : 10 px ;
17+ background-color : orange ;
18+ color : black ;
1919 text-align : center;
20- color : white ;
20+ padding : 10 px ;
2121 }
2222 </ style >
2323</ head >
@@ -31,40 +31,110 @@ <h1 id="display"></h1>
3131</ body >
3232
3333< script >
34-
3534 //creation of a simple function with no args and execute a function
35+ var output = "" ;
36+ //function Declaration / Definition
37+ function greet ( ) {
38+ output = "Hey! Iam a function" ;
39+ console . log ( output ) ;
40+ document . getElementById ( 'display' ) . innerHTML = output ;
41+ }
3642
43+ // Function Execution
44+ greet ( ) ;
3745
3846 //creation of a simple function with args
39-
47+ function greetArgs ( name ) {
48+ output = "Good Morning " + name ;
49+ console . log ( output ) ;
50+ document . getElementById ( 'display' ) . innerHTML = output ;
51+ }
52+ greetArgs ( "Naveen" ) ;
4053
4154 // executing a function with less number of params
42-
55+ function greetLessArgs ( name , age ) {
56+ output = "Hello! Mr. " + name + " you are " + age + " Years Old!" ;
57+ console . log ( output ) ;
58+ document . getElementById ( 'display' ) . innerHTML = output ;
59+ }
60+ greetLessArgs ( "John" ) ;
4361
4462 //executing a function with more number of params
45-
63+ function greetMoreArgs ( name , age ) {
64+ output = "Hello! Mr. " + name + " you are " + age + " Years Old!" ;
65+ console . log ( output ) ;
66+ document . getElementById ( 'display' ) . innerHTML = output ;
67+ }
68+ greetMoreArgs ( 'Smith' , 35 , "Manager" ) ;
4669
4770 //function overloading is not possible here
4871
49-
5072 // functions with return values
51-
73+ function greetWithReturn ( name ) {
74+ output = "Good Evening " + name ;
75+ return output ;
76+ }
77+ var greetMessage = greetWithReturn ( "Naveen" ) ;
78+ console . log ( greetMessage ) ;
79+ document . getElementById ( 'display' ) . innerHTML = greetMessage ;
5280
5381 //function with empty return /no return
54-
82+ function greetWithEmptyReturn ( name ) {
83+ output = "Hey! " + name ;
84+ return ;
85+ }
86+ var greetReturn = greetWithEmptyReturn ( "Naveen" ) ;
87+ console . log ( greetReturn ) ;
88+ document . getElementById ( 'display' ) . innerHTML = greetReturn ;
5589
5690 // function Expressions with name and execution
57-
91+ var greetMsg = function greet ( ) {
92+ output = "I am a Function Expression" ;
93+ console . log ( output ) ;
94+ document . getElementById ( 'display' ) . innerHTML = output ;
95+ } ;
96+ greetMsg ( ) ;
5897
5998 // Anonymous Function Expression and execution
60-
99+ var greetMe = function ( ) {
100+ output = "I am an anonymous Function Expression" ;
101+ console . log ( output ) ;
102+ document . getElementById ( 'display' ) . innerHTML = output ;
103+ } ;
104+ greetMe ( ) ;
61105
62106 // Functions as arguments without args
63-
64-
107+ function greet1 ( ) {
108+ output = "Iam greet1 Function " ;
109+ console . log ( output ) ;
110+ document . getElementById ( 'display' ) . innerHTML = output ;
111+ }
112+ function greet2 ( ) {
113+ output = "Iam greet2 Function " ;
114+ console . log ( output ) ;
115+ document . getElementById ( 'display' ) . innerHTML = output ;
116+ }
117+ function greetEngine ( fName ) {
118+ fName ( ) ;
119+ }
120+ greetEngine ( greet2 ) ;
65121
66122 // Functions as arguments with args args
67-
123+ function greet1Args ( name ) {
124+ output = "Hey! " + name + " Iam from greet1Args Function" ;
125+ console . log ( output ) ;
126+ document . getElementById ( 'display' ) . innerHTML = output ;
127+ }
128+ function greet2Args ( name ) {
129+ output = "Hey! " + name + " Iam from greet2Args Function" ;
130+ console . log ( output ) ;
131+ document . getElementById ( 'display' ) . innerHTML = output ;
132+ }
133+
134+ function greetArgsEngine ( fName , name ) {
135+ fName ( name ) ;
136+ }
137+ greetArgsEngine ( greet1Args , "Naveen" ) ;
68138
69139 // Functions in Objects and Execution
70140
@@ -79,8 +149,9 @@ <h1 id="display"></h1>
79149 */
80150
81151
152+
82153 // Default Function Arguments (arguments)
83154
84155
85156</ script >
86- </ html >
157+ </ html >
0 commit comments