Test your JavaScript Skills: Fundamentals-4

Photo by Andrew Neel on Unsplash

Test your JavaScript Skills: Fundamentals-4

Part 4

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 = "ram" + false;
     console.log("mydata", mydata);
    

    a.error

    b.ram0

    c.ramfalse

    d. truefalse

    e.NaN

    Answer:c

    Reason: Here since one of the operands is a string and the + operator is used, the other operand will be coerced to string hence the output will be ramfalse.

  2. Identify the output of the below program

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

    a.error

    b.NaN

    c.undefined

    d. 1

    e.0

    Answer:d

    Reason: Here null coerced into 0 and true to 1 hence the result is 1.

  3. Identify the output of the below program

     console.log("mydata", typeof break);
    

    a.error

    b.NaN

    c.undefined

    d. string

    e.null

    Answer: a

    Reason: It is a keyword hence cannot be used with typeof.

  4. Identify the output of the below program

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

    a.error

    b.NaN

    c.true

    d.0

    e.1

    Answer:d

    Reason: Here null is coerced to 0 hence 0+0 is 0.

  5. Identify the output of the below program

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

    a.NaN

    b.0

    c.1

    d.error

    e.undefined

    Answer: a

    Reason: Here null is coerced to the number which is 0 and false is coerced to the number which is 0 hence 0/0 in Javascript is NaN

  6. Identify the output of the below program

     let mydata=null+"ram";
    

    a.NaN

    b.error

    c.0ram

    d. nullram

    e.ramnull

    Answer:d

    Reason: Here since one of the operands is a string hence null is coerced to a string and concatenated with string therefore the result is nullram.

  7. Identify the output of the below program

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

    a.NaN

    b.Infinity

    c.Error

    d. 0

    e.1

    Answer:b

    Reason: Here true is coerced to a number which is 1 and null is also coerced to a number which is 0 hence 1/0 in Javascript is Infinity.

Video Tutorial

Did you find this article valuable?

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