6.0k views
5 votes
What is the correct way to write a JavaScript array?

a) var colors = (1:"red", 2:"green", 3:"blue")
b) var colors = "red", "green", "blue"
c) var colors = ["red", "green", "blue"]
d) var colors = 1 = ("red"), 2 = ("green"), 3 = ("blue")

User Yudy
by
7.6k points

1 Answer

1 vote

Final answer:

The correct way to write a JavaScript array is var colors = ["red", "green", "blue"].

Step-by-step explanation:

The correct way to write a JavaScript array is option c) var colors = ["red", "green", "blue"]. In JavaScript, arrays are enclosed in square brackets and each element is separated by a comma.

User Qmarlats
by
8.2k points