Which of the Following Correctly Declares an Array? A Developer's Guide to Array Syntax
Arrays are one of the most fundamental data structures in programming, and getting the declaration syntax right is the first step to using them effectively. Whether you're writing JavaScript for a web app, working through a coding quiz, or debugging an unexpected error, understanding what makes an array declaration correct — and what makes it wrong — is essential knowledge for any developer.
What Is an Array Declaration?
An array is an ordered collection of values stored under a single variable name. Declaring an array means telling your program: "Create a variable that holds multiple values in a specific sequence."
The exact syntax for declaring an array varies by programming language, but the core concept is universal: you're assigning a list of elements to a named variable.
Correct Array Declaration Syntax by Language
Since this question frequently appears in quizzes and coding assessments, it's worth walking through the most common languages and their correct forms.
JavaScript
JavaScript offers two main approaches:
Array literal syntax (preferred):