Test your JavaScript Skills:Fundamentals-18

Photo by Bram Naus on Unsplash

Test your JavaScript Skills:Fundamentals-18

Part 18

Introduction

Namaste, In this blog I will discuss 7 code scenarios on Javascript fundamentals.

  1. Identify the output of the below program

     class mycls{}
     var mycls=2;  
     console.log("type", typeof mycls);
    

    a.2

    b.class mycls{}

    c.function

    d.error

    e.undefined

    Answer: d

    Reason: Because of re-declaration there is an error.

  2. Identify the output of the below program

     function fx(){}
     class fx{}
     console.log("type", typeof fx);
    

    a. function

    b.class

    c.undefined

    d.number

    e.error

    Answer: e

    Reason: Because of re-declaration there is an error.

  3. Identify the output of the below program

    
     function fx() { console.log("fx");}
     function fx() { console.log("fx-2");}
     fx();
    

    a.fx

    b.fx-2

    c.error

    d.no-output

    e.null

    Answer:b

    Reason: Since fx is hoisted there is no error.

  4. Identify the output of the below program

     console.log("value", i); 
     i=10;
    

    a.10

    b.undefined

    c.error

    d.null

    e.no-output

    Answer:c

    Reason: The variable is not hoisted.

  5. Identify the output of the below program

     console.log(typeof console);
    

    a.null

    b.class

    c.function

    d.object

    e.string

    Answer:d

    Reason: The typeof of 'console' is object.

  6. Identify the output of the below program

     if ( 10 > (let i=3)) {
         i=11;
     }else {
         i=10;
     }
     console.log("value", i);
    

    a. 3

    b.11

    c.10

    d.undefined

    e.error

    Answer: e

    Reason: Invalid syntax i.e. declaration of 'i' is invalid.

  7. Identify the output of the below program

     fx()
     function fx() {
      console.log("fx");
     }
    

    a.fx

    b.error

    c.undefined

    d.null

    e.no-output

    Answer: a

    Reason: Function fx is hoisted.

Did you find this article valuable?

Support Programming with Mahavir by becoming a sponsor. Any amount is appreciated!