Multiple choice technology web technology

What is the correct way to write a JavaScript array?

  1. var txt = new Array="tim","kim","jim";

  2. var txt = new Array("tim","kim","jim");

  3. var txt = new Array:1=("tim")2=("kim")3=("jim")

  4. var txt = new Array(1:"tim",2:"kim",3:"jim")

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

JavaScript arrays can be created using the Array constructor with comma-separated values in parentheses. Option B demonstrates the correct syntax: new Array("tim","kim","jim") creates a 3-element array. Options A, C, and D all use incorrect syntax - option A incorrectly uses an equals sign, option C uses colons and numbers, and option D tries to use associative array/object key syntax which doesn't work with the Array constructor.