├── index.html
├── script.js
└── style.css
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
Q1 : Create one function with zero parameter having a console statement;
18 |
ANS :-
19 |
20 | function question(){
21 | console.log("This is Zero peremeter Function")
22 | }
23 | question();
24 |
25 |
Output :- This is Zero peremeter Function
26 |
27 |
28 |
29 |
Q2 : Create one function which takes two values as a parameter and print the sum of them as "Sum of 3, 4 is 7"
30 |
ANS :-
31 |
32 | function question2(a,b){
33 | let sum = a+b;
34 | console.log(sum)
35 | }
36 | question2(3,4)
37 |
38 |
Output :- 7
39 |
40 |
41 |
42 |
Q3 : Create one arrow function
43 |
ANS :-
44 |
45 | const arrow=()=>{
46 | console.log("This is arrow function ");
47 | }
48 | arrow();
49 |
50 |
Output :- This is arrow function
51 |
52 |
53 |
54 |
Q4 : print Output
55 |
56 | var x = 21;
57 | var girl = function () {
58 | console.log(x);
59 | var x = 20;
60 | };
61 | girl ();
62 |
63 |
Output :- undefined
64 |
NOTE :-
65 |
within the function scope x gets hoisted and since it is of var type, we get the output as undefined
66 |
67 |
68 |
69 |
70 |
Q5 : print Output
71 |
72 | var x = 21;
73 | girl ();
74 | console.log(x)
75 | function girl() {
76 | console.log(x);
77 | var x = 20;
78 | };
79 |
80 |
Output :-
81 |
undefined
82 |
83 | 21
84 |
85 |
NOTE :-
86 |
Due to hoisting of the variable within the function scope, first we get the output as undefined. x has been initialized as 21 already and that is printed when console.log(x) is executed
87 |
88 |
89 |
90 |
91 |
Q6 : Print Output
92 |
93 | var x = 21;
94 | a();
95 | b();
96 | function a() {
97 |
98 | x = 20;
99 | console.log(x);
100 | };
101 | function b() {
102 |
103 | x = 40;
104 | console.log(x);
105 | };
106 |
107 |
Output :-
108 |
20
40
109 |
NOTE :-
110 |
value of x is initialized as 20 within the function scope of a() and output is 20. value of x is initialized as 40 within the function scope of b(), so the output is 40.
111 |
112 |
113 |
114 |
115 |
Q7 : Write a function that accepts parameter n and returns factorial of n
116 |
117 | const fact=(num)=>{
118 | ans=1
119 | if(num>0){
120 | for (let i=1; i<=num;i++){
121 | ans=ans*i
122 | }
123 | console.log(ans)
124 | }
125 | else{
126 | console.log("enter a postive no")
127 | }
128 | }
129 |
130 | fact(5)
131 |
132 |
Output :- 120
133 |
134 |
135 |
136 |
137 |
138 |
141 |
142 |
Q1 : Guess The Output
143 |
144 | function FindSum(a, b){
145 | return a + b;
146 | }
147 |
148 | function DisplayData(data, batch){
149 | console.log(`i am from ${data} and My batch is EA${batch}`)
150 | }
151 |
152 | DisplayData("PrepBytes", FindSum(10, 13));
153 |
154 |
Output :- i am from PrepBytes and My batch is EA23
155 |
NOTE :-
156 |
The 1st parameter "data" gets the value of the string "Prepbytes" from the 1st argument. Function FindSum is the 2nd argument and it gets executed, value 19 is returned and it goes to "batch" the 2nd parameter.
157 |
158 |
159 |
160 |
161 |
Q2 : Guess the Output
162 |
163 | Abc();
164 | const Abc = function(){
165 | let value = 20;
166 | console.log(value);
167 | }
168 |
169 |
Output :- ReferenceError
170 |
NOTE :-
171 |
We get this error because Abc has not been initialized before
172 |
173 |
174 |
175 |
176 |
Q3 : Guess the output
177 |
178 | var a = 10;
179 | (function (){
180 | console.log(a);
181 | var a = 20;
182 | })();
183 |
184 |
Output :- undefined
185 |
NOTE :-
186 |
Before declaration in memory allocation the a value wants to be printed.
187 |
188 |
189 |
190 |
191 |
Q4 : Guess the Output
192 |
193 | const greet = function(name){
194 | return function(m){
195 | console.log(`Hi!! ${name}, ${m}`);
196 | }
197 | }
198 | const greet_message = greet('EAC-01');
199 | greet_message("Welcome To PrepBytes")
200 |
201 |
Output :- Hi!! EAC-01, Welcome To PrepBytes
202 |
NOTE :-
203 |
it will directly to come const greet_message, in this the greet is assigned with argument EA19, which will make connection to greet variable in const, and name will be printed as EA19. Same goes to function of m.
204 |
205 |
206 |
207 |
208 |
209 |
--------------------------------------------------------------------------------
/script.js:
--------------------------------------------------------------------------------
1 | // Question :1
2 | function question() {
3 | console.log("This is Zero peremeter Function");
4 | }
5 | question();
6 |
7 | // Question :2
8 | function question2(a, b) {
9 | let sum = a + b;
10 | console.log(sum);
11 | }
12 | question2(3, 4);
13 |
14 | // Question :3
15 |
16 | const arrow = () => {
17 | console.log("This is arrow function ");
18 | };
19 | arrow();
20 |
21 | // question :4
22 | // Print output:
23 | var x = 21;
24 | var girl = function () {
25 | console.log(x);
26 | var x = 20;
27 | };
28 | girl();
29 |
30 | // Question :5
31 | var x = 21;
32 | girl();
33 | console.log(x);
34 | function girl() {
35 | console.log(x);
36 | var x = 20;
37 | }
38 |
39 | // Question :6
40 | var x = 21;
41 | a();
42 | b();
43 |
44 | function a() {
45 | x = 20;
46 | console.log(x);
47 | }
48 | function b() {
49 | x = 40;
50 | console.log(x);
51 | }
52 |
53 | //question :7
54 | const fact = (num) => {
55 | ans = 1;
56 | if (num > 0) {
57 | for (let i = 1; i <= num; i++) {
58 | ans = ans * i;
59 | }
60 | console.log(ans);
61 | } else {
62 | console.log("enter a postive no");
63 | }
64 | };
65 |
66 | fact(5);
67 |
68 | /* ============================================= Day :- 2 ======================================================== */
69 |
70 | // question: 1
71 | function FindSum(a, b) {
72 | return a + b;
73 | }
74 |
75 | function DisplayData(data, batch) {
76 | console.log(`i am from ${data} and My batch is EA${batch}`);
77 | }
78 |
79 | DisplayData("PrepBytes", FindSum(10, 13));
80 |
81 | // Question :2
82 | Abc();
83 | const Abc = function () {
84 | let value = 20;
85 | console.log(value);
86 | };
87 |
88 | // Question :3
89 | var a = 10;
90 | (function (){
91 | console.log(a);
92 | var a = 20;
93 | })();
94 |
95 | // Question :4
96 | const greet = function(name){
97 | return function(m){
98 | console.log(`Hi!! ${name}, ${m}`);
99 | }
100 | }
101 | const greet_message = greet('EAC-01');
102 | greet_message("Welcome To PrepBytes")
103 |
--------------------------------------------------------------------------------
/style.css:
--------------------------------------------------------------------------------
1 | *{
2 | margin: 0;
3 | padding: 0;
4 | box-sizing: border-box;
5 | }
6 | .Heading{
7 | margin-top: 20px;
8 | font-size: 35px;
9 | text-align: center;
10 | font-weight: 800;
11 | color: blueviolet;
12 | }
13 | hr{
14 | background-color: grey;
15 | height: 4px;
16 | width: 100%;
17 | margin-top: 40px;
18 | }
19 | .mainContanier{
20 | margin-left: 50px;
21 | margin-right: 50px;
22 | }
23 | .bold{
24 | font-weight: 700;
25 | margin: 20px 0;
26 | font-size: 20px;
27 |
28 | }
29 | .ansBold{
30 | font-weight: 600;
31 | color: blue;
32 | }
33 | .code{
34 | color: red;
35 | }
36 | .green{
37 | color: green;
38 | font-weight: 600;
39 | font-size: 18px;
40 | }
--------------------------------------------------------------------------------