Day :- 1


Q1 : Create one function with zero parameter having a console statement;

ANS :-

                function question(){
                    console.log("This is Zero peremeter Function")
                }
                question();
            

Output :- This is Zero peremeter Function


Q2 : Create one function which takes two values as a parameter and print the sum of them as "Sum of 3, 4 is 7"

ANS :-

                function question2(a,b){
                    let sum = a+b;
                    console.log(sum)
                }
                question2(3,4)
            

Output :- 7


Q3 : Create one arrow function

ANS :-

                const arrow=()=>{
                    console.log("This is arrow function ");
                }
                arrow();
            

Output :- This is arrow function


Q4 : print Output

                var x = 21;
                var girl = function () {
                    console.log(x);
                    var x = 20;
                };
                girl ();
            

Output :- undefined

NOTE :-

within the function scope x gets hoisted and since it is of var type, we get the output as undefined


Q5 : print Output

                var x = 21;
                girl ();
                console.log(x)
                function girl() {
                    console.log(x);
                    var x = 20;
                };
            

Output :-

undefined
21

NOTE :-

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


Q6 : Print Output

                var x = 21;
                a();
                b();
                function a() {
    
                    x = 20;
                   console.log(x);
                 };
                  function b() {
                     
                     x = 40;
                    console.log(x);
                 };
            

Output :-

20
40

NOTE :-

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.


Q7 : Write a function that accepts parameter n and returns factorial of n

                const fact=(num)=>{
                    ans=1
                    if(num>0){
                        for (let i=1; i<=num;i++){
                            ans=ans*i
                        }
                        console.log(ans)
                    }
                    else{
                        console.log("enter a postive no")
                    }
                }
                
                fact(5)
            

Output :- 120

Day :- 2


Q1 : Guess The Output

                function FindSum(a, b){
                    return a + b;
                }
                
                function DisplayData(data, batch){
                    console.log(`i am from ${data} and My batch is EA${batch}`)
                }
                
                DisplayData("PrepBytes", FindSum(10, 13));
            

Output :- i am from PrepBytes and My batch is EA23

NOTE :-

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.


Q2 : Guess the Output

                Abc();
                const Abc = function(){
                    let value = 20;
                    console.log(value);
                }
            

Output :- ReferenceError

NOTE :-

We get this error because Abc has not been initialized before


Q3 : Guess the output

                var a = 10;
                (function (){
                    console.log(a);
                    var a = 20;
                })();
            

Output :- undefined

NOTE :-

Before declaration in memory allocation the a value wants to be printed.


Q4 : Guess the Output

                const greet =  function(name){
                    return function(m){
                        console.log(`Hi!! ${name}, ${m}`);
                    }
                }
                const greet_message = greet('EAC-01');
                greet_message("Welcome To PrepBytes")
            

Output :- Hi!! EAC-01, Welcome To PrepBytes

NOTE :-

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.