Test Your JavaScript Skills : ES10 (JavaScript 2019) - 43

Part 43

Introduction

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

  1. Identify the output of the below program

     let text = '   Namaste    ';
     let trimmedStart = text.trimStart();
     console.log(trimmedStart);
    

    a.Namaste

    b. Namaste

    c.error

    d.undefined

    e.null

    Answer:a

    Reason:The spaces from starting are removed.

  2. Identify the output of the below program

     let text = '   Namaste    ';
     const trimmedEnd = text.trimEnd(); 
     console.log(trimmedEnd);
    

    a.Namaste

    b. Namaste

    c.Namas te

    d.undefined

    e.error

    Answer:b

    Reason:The spaces from end are removed.

  3. Identify the output of the below program

     const entries = [['a', 1]];
     const obj = Object.fromEntries(entries);
     console.log(obj);
    

    a.['a','1']

    b.{a:1}

    c.{1:a}

    d.['1':'a']

    e.error

    Answer:b

    Reason:The array is converted to object.

  4. Identify the output of the below program

     const entries = ['a', 1];
     const obj = Object.fromEntries(entries);
     console.log(obj);
    

    a.error

    b.{a:1}

    c.{1:a}

    d.{'a':'1'}

    e.undefined

    Answer:a

    Reason:The input is invalid hence error.

  5. Identify the output of the below program

     const map = new Map([
         ["Lang", "JS"],    
       ]);
     let obj2 = Object.fromEntries(map);
     console.log(obj2);
    

    a.{'Lang':'JS'}

    b.{Lang:JS}

    c.{Lang:'JS'}

    d.{0:'JS'}

    e.error

    Answer:c

    Reason:The Map is converted to an object.

  6. Identify the output of the below program

     const map = new Map(
         ["Lang", "JS"]    
       );
     let obj2 = Object.fromEntries(map);
     console.log(obj2);
    

    a.{'Lang':'JS'}

    b.{Lang:JS}

    c.{Lang:'JS'}

    d..{0:'JS'}

    e.error

    Answer:e

    Reason:The input is invalid.

  7. Identify the output of the below program

     let mySymbol = Symbol('Database');
     console.log(mySymbol.description);
    

    a.Database

    b.Symbol

    c.Object

    d.Symbol(Object)

    e.error

    Answer:a

    Reason:The description property has value Database.

  8. Identify the output of the below program

     const entries = [['data', false]];
     const obj = Object.fromEntries(entries);
     console.log(obj);
    

    a.['data', false]

    b.{'data', false}

    c.['data', false]

    d.{data: false}

    e.undefined

    Answer:d

    Reason:The array is converted to an object.

Did you find this article valuable?

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