MCQ Single Best Answer Not Set

QWhat is the correct way to create a new array in JavaScript?

ID: #4852 Basic JavaScript MCQ 140 views
Question Info
#4852Q ID
Not SetDifficulty
Basic JavaScript MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A let arr = Array();
  • B let arr = new Array();
  • C let arr = [];
  • D let arr = new List();
Correct Answer: Option C

Explanation

In JavaScript, let arr = []; is the correct way to create a new array.
This is known as an array literal, and it is the most concise and commonly used way to create an array in JavaScript.

An array literal is a simple way to create an array by enclosing a list of values in square brackets ([]).
Each value in the list is called an element of the array, and the elements are separated by commas.

For example, the following code creates an array of numbers:

let arr = [1, 2, 3, 4, 5];

The following code creates an array of strings:

let arr = ['a', 'b', 'c', 'd', 'e'];

And the following code creates an array of mixed data types:

let arr = [1, 'a', true, {}, []];

Share This Question

Challenge a friend or share with your study group.