Test your JavaScript Skills: Fundamentals-13

Photo by RetroSupply on Unsplash

Test your JavaScript Skills: Fundamentals-13

Part 13

Introduction

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

  1. Identify the output of the below program

     let sym = Symbol();
     if (sym) 
        console.log("true"); 
      else
        console.log("false");
    

    a.undefined

    b.null

    c.true

    d. false

    e.error

    Answer: c

    Reason: Symbol is a truthy value.

  2. Identify the output of the below program

     if (function fx(){})
       console.log("true"); 
     else
       console.log("false");
    

    a.false

    b.error

    c.undefined

    d. true

    e.null

    Answer: d

    Reason: A function is a truthy value.

  3. Identify the output of the below program

     if (Object)
       console.log("true");
     else
       console.log("false");
    

    a.false

    b.error

    c.null

    d. undefined

    e.true

    Answer: e

    Reason: The Object is pre-defined and any object is truthy.

  4. Identify the output of the below program

     if ("  ") 
        console.log("true"); 
      else
        console.log("false");
    

    a.error

    b.true

    c.false

    d.undefined

    e.null

    Answer:b

    Reason: String with space is truthy.

  5. Identify the output of the below program

     let fx = function(){}
    
     if (fx)
       console.log("true"); 
     else
       console.log("false");
    

    a.false

    b.error

    c.true

    d. undefined

    e.0

    Answer: c

    Reason: A function is a truthy value.

  6. Identify the output of the below program

     console.log( typeof "");
    

    a. undefined

    b.null

    c.string

    d. NaN

    e.error

    Answer: c

    Reason: Empty double quotes are a string type.

  7. Identify the output of the below program

      let cls = class My{};
    
     if (cls)
       console.log("true"); 
     else
       console.log("false");
    

    a.error

    b.undefined

    c.false

    d. true

    e.null

    Answer: d

    Reason: A class is a truthy value.

Did you find this article valuable?

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