Arrays

Last Updated :
Discuss
Comments

Question 1

What is the index of the first element in a JavaScript array?

  • A

    1

  • B

    0

  • C

    -1

  • D

    undefined

Question 2

What is the output of the following code?

JavaScript
let a = [10, 20, 30];
console.log(a[1]);


  • A

    10

  • B

    20

  • C

    30

  • D

    undefined

Question 3

Which method is used to add an element to the beginning of an array?

  • A

    push()

  • B

    pop()

  • C

    unshift()

  • D

    shift()

Question 4

What does the following code do?

JavaScript
let a = [1, 2, 3];
a.length = 2;
console.log(a);


  • A

    [1, 2]

  • B

    [2, 3]

  • C

    [1, 2, 3]

  • D

    [1, 2, 3, ]

Question 5

Which of the following methods modifies the original array?


  • A

    concat()

  • B

    slice()

  • C

    reverse()

  • D

    toString()

Question 6

What will be the output of the following code?

JavaScript
let a = [10, 20, 30];
console.log(a.pop());


  • A

    30

  • B

    10

  • C

    Undefined

  • D

    Error

Question 7

How do you check if a variable a is an array?

  • A

    typeof a === 'array'

  • B

    Array.isArray(a)

  • C

    a instanceof Object

  • D

    a.constructor === Array

Question 8

What does the splice() method do?

  • A

    Adds elements to the end

  • B

    Removes elements from the array

  • C

    Adds and removes elements

  • D

    Merges two arrays

Question 9

What is the result of the following code?

JavaScript
console.log([] + []);


  • A

    NaN

  • B

    ""

  • C

    []

  • D

    undefined

Question 10

What does a closure in JavaScript do?

  • A

    Accesses outer function variables

  • B

    Only accesses global variables

  • C

    Is not useful in async code

  • D

    Can't access outer variables


There are 10 questions to complete.

Take a part in the ongoing discussion