Test your JavaScript Skills : Boolean() Object

Part 25

Namaste, In this blog I will discuss 8 code scenarios on Boolean() Object and Boolean() function.

  1. Identify the output of the below program

     let ob = Boolean();
     console.log(ob);
    

    a.true

    b.false

    c.null

    d.undefined

    e.error

    Answer: b

    Reason: The boolean() function returns false

  2. Identify the output of the below program

     let ob = new Boolean();
     console.log(ob);
    

    a.Boolean(false)

    b.false

    c.true

    d.undefined

    e.error

    Answer: a

    Reason: The boolean() object for empty value returns Boolean(false)

  3. Identify the output of the below program

     let ob = new Boolean(false);
     console.log(ob);
    

    a.true

    b.false

    c.undefined

    d.Boolean(false)

    e.error

    Answer: d

    Reason: The boolean() object returns Boolean(false)

  4. Identify the output of the below program

     let ob = new Boolean(false);
     if (ob)
         console.log("true");
     else
         console.log("false");
    

    a.true

    b.false

    c.error

    d.undefined

    e.Boolean(false)

    Answer: a

    Reason: The ob is an object hence "true" is printed

  5. Identify the output of the below program

     let ob = new Boolean("JS");
     console.log(ob);
    

    a.Boolean(false)

    b.false

    c.true

    d.Boolean(true)

    e.error

    Answer: d

    Reason: The new boolean("JS") object returns Boolean(true)

  6. Identify the output of the below program

     let ob = Boolean(false);
     if (ob)
         console.log("true");
     else
         console.log("false");
    

    a.false

    b.true

    c.undefined

    d.Boolean(false)

    e.true

    Answer: a

    Reason: ob is a boolean primitive with value false, not an object

  7. Identify the output of the below program

     let ob = Boolean(false);
     console.log(typeof ob);
    

    a.object

    b.boolean

    c.string

    d.number

    e.error

    Answer: b

    Reason: The Boolean() function returns a boolean value

  8. Identify the output of the below program

     let ob = new Boolean(false);
     console.log(typeof ob);
    

    a.object

    b.boolean

    c.string

    d.number

    e.error

    Answer: a

    Reason: When new is used an object is created.

Did you find this article valuable?

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