Test your JavaScript Skills: Fundamentals-3

Part 3

Introduction

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

Video Tutorial

  1. Identify the output of the below program

     let mydata = null +1;
     console.log("mydata", mydata);
    

    a.error

    b.null

    c.undefined

    d.1

    e.2

    Answer:d

    Reason: The null is coerced to a number which is 0 hence 0+1 is 1.

  2. Identify the output of the below program

     let mydata="ram" + 2;
     console.log("mydata", mydata);
    

    a.NaN

    b.ram2

    c.error

    d. undefined2

    e.null

    Answer:b

    Reason: When the + operator is used with a string it performs concatenation. Hence 2 is coerced to a string.

  3. Identify the output of the below program

     let mydata=true/false;
     console.log("mydata", mydata);
    

    a.1

    b.0

    c.error

    d. Infinity

    e.undefined

    Answer:d

    Reason: Here true is coerced into 1 and false to 0 hence 1/0 is Infinity in Javascript.

  4. Identify the output of the below program

     let mydata= null+undefined;
     console.log("mydata", mydata);
    

    a.error

    b.0

    c.NaN

    d. nullundefined

    e.undefined

    Answer:c

    Reason: Here null is coerced into 0 and undefined to NaN. Hence 0 + NaN is NaN.

  5. Identify the output of the below program

     let mydata = false/true;
     console.log("mydata", mydata);
    

    a.0

    b.1

    c.NaN

    d. Infinity

    e.error

    Answer: a

    Reason: Here false is coerced into 0 and true into 1 hence 0/1 in Javascript is 0.

  6. Identify the output of the below program

     let mydata = true + 1;
     console.log("mydata", mydata);
    

    a.1

    b.true

    c.2

    d. NaN

    e.true1

    Answer:c

    Reason: Here true is coerced to a number which results in 1 hence 1+1 is 2.

  7. Identify the output of the below program

     let mydata = undefined + 1;
     console.log("mydata", mydata);
    

    a.undefined

    b.undefined1

    c.1

    d. error

    e.NaN

    Answer:e

    Reason: The undefined is coerced to a number which results in NaN hence NaN+1 is NaN.

Video Tutorial

Did you find this article valuable?

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