Test Your JavaScript Skills : ES12  (JavaScript 2021) - 38

Photo by RetroSupply on Unsplash

Test Your JavaScript Skills : ES12 (JavaScript 2021) - 38

Part 38

Table of contents

Introduction

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

  1. Identify the output of the below program

     let str = "Namaste Java";
     let str2 = str.replaceAll("Java", "Javascript");
     console.log(str2);
    

    a.Namaste Java

    b.Namaste Javascript

    c.undefined

    d.null

    e.error

    Answer:b

    Reason:The string Java is replaced by Javascript.

  2. Identify the output of the below program

     let a=true;
     a &&= false;
     console.log(a);
    

    a.true

    b.undefined

    c.null

    d.false

    e.error

    Answer:d

    Reason:The logical and assignment operator evaluates to false in the above scenario.

  3. Identify the output of the below program

     let num= 1_0_0_0;
     console.log(num);
    

    a.1

    b.10

    c.1000

    d.100

    e.error

    Answer:c

    Reason:Numeric separator enhances code readability.

  4. Identify the output of the below program

     let a=false;
     a ||= true;
     console.log(a);
    

    a.false

    b.true

    c.undefined

    d.error

    e.null

    Answer:b

    Reason:The expression evaluates to true.

  5. Identify the output of the below program

     let a=true;
     a ||= false;
     console.log(a);
    

    a.true

    b.false

    c.undefined

    d.null

    e.error

    Answer:a

    Reason:The expression evaluates to true.

  6. Identify the output of the below program

     let a=false;
     a &&= false;
     console.log(a);
    

    a.true

    b.false

    c.error

    d.undefined

    e.error

    Answer:b

    Reason:The expression evaluates to false.

  7. Identify the output of the below program

     let str = "Java Java";
     console.log(str.replaceAll("Java", "Javascript"));
    

    a.Javascript Javascript

    b.Java Java

    c.Javascript

    d.Java

    e.error

    Answer: a

    Reason: The string Java is replaced by Javascript at all places.

  8. Identify the output of the below program

     let x;
     let y = 10;
     x ??= y;
     console.log(x);
    

    a.undefined

    b.null

    c.10

    d.true

    e.false

    Answer:c

    Reason:Since x is undefined value 10 is assigned to it.

  9. Identify the output of the below program

     let x=2;
     let y = 10;
     x ??= y;
     console.log(x);
    

    a.2

    b.10

    c.false

    d.true

    e.error

    Answer:a

    Reason:Since x is already initialized the value of y is not initialized.

  10. Identify the output of the below program

    let str = "Namaste Java";
    let str2 = str.replaceAll("Java", "Javascript");
    console.log(str);
    

    a.Namaste Java

    b.Namaste Javascript

    c.error

    d.null

    e.undefined

    Answer:a

    Reason:The host string is not updated by replaceAll() function.

Did you find this article valuable?

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