What is the correct syntax to write a JavaScript array?

What is the correct syntax to write a JavaScript array?

A) `var array = 1,2,3,4,5;`

B) `var array = (1 2 3 4 5);`

C) `var array = [1,2,3,4,5];`

D) `var array: [1,2,3,4,5];`

What is the correct syntax to write a JavaScript array?

A)      `var array = 1,2,3,4,5;`

B)      `var array = (1 2 3 4 5);`

C)      `var array = [1,2,3,4,5];`

D)      `var array: [1,2,3,4,5];`

What is the correct syntax to write a JavaScript array?

A)      `var array = 1,2,3,4,5;`

Arrays in JavaScript are defined using square brackets `[]`, and elements are separated by commas. Option C is the correct syntax for defining an array.

Palette

By Vinay Mavi

Palette

  • 76