Test Your JavaScript Skills: ES14 - 34

Photo by RetroSupply on Unsplash

Test Your JavaScript Skills: ES14 - 34

Part 34

Table of contents

Introduction

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

  1. Identify the output of the below program

     let arr = [11,29,7,11];
     let idx = arr.findLastIndex(arg => arg>9);
     console.log(idx);
    

    a.2

    b.1

    c.0

    d.3

    e.error

    Answer:d

    Reason:The number 11 is the last value greater than 9 which is located at index 3.

  2. Identify the output of the below program

     let scores = [11, 22, 33, 41, 95];
     let arr = scores.toSpliced(0, 2); 
     console.log(arr);
    

    a.[11,22,33,41,95]

    b.[22,33,41,95]

    c.[33,41,95]

    d.[41,95]

    e.error

    Answer:c

    Reason:From index 0, 2 values are removed.

  3. Identify the output of the below program

     let scores = [11, 22];
     let arr = scores.toSpliced(0, 0, 1, 2); 
     console.log(arr);
    

    a.[1,2,11,22]

    b.[2,11,22]

    c.[11,22,1,2]

    d.[11,22]

    e.error

    Answer:a

    Reason:From index 0 onwards remove 0 values and insert 1,2 values.

  4. Identify the output of the below program

     let scores = [11, 22];
     let arr = scores.toSpliced(0, 2, 1, 2); 
     console.log(arr);
    

    a.[11,22]

    b.[1,2]

    c.[2,1,2]

    d.[1,2,11,22]

    e.error

    Answer:b

    Reason:From index 0 remove 2 values and insert 1,2 values.

  5. Identify the output of the below program

     let ky = Symbol('mykey');
     let wkmap = new WeakMap();
     wkmap.set(ky, 'myvalue');
     console.log(wkmap.get(ky));
    

    a.myvalue

    b.error

    c.no output

    d.mykey

    e.Symbol

    Answer:a

    Reason:The output is myvalue.

  6. Identify the output of the below program

     let scores = [11, 22, 33, 41, 95];
     let arr = scores.toSpliced(1, 2); 
     console.log(arr);
    

    a.[11,22,33,41,95]

    b.[11,,33,41,95]

    c.[11,22,33,41]

    d.[11,41,95]

    e.error

    Answer:d

    Reason: From index 1 onwards 2 values are removed.

  7. Identify the output of the below program

     let scores = [11, 22,33];
     let arr = scores.toSpliced(1, 2, 1, 2); 
     console.log(arr);
    

    a.[11,22,33]

    b.[11,1,2]

    c.[22,1,2]

    d.[22,33,1]

    e.[1,2]

    Answer:b

    Reason:From index 1 remove 2 values and insert 1,2 values.

  8. Identify the output of the below program

     let scores = [11, 22, 33, 41, 95];
     let arr = scores.toSpliced(3, 1); 
     console.log(arr);
    

    a.[11,22,33,95]

    b.[11,22,33,41]

    c.[11,22,33]

    d.[11,22,33,41,95]

    e.error

    Answer:a

    Reason:From index 3 onwards 1 value is removed.

Did you find this article valuable?

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