What will the output of console.log([1, 2][0]); be?

Prepare for the Salesforce JavaScript Developer I Certification Exam. Utilize interactive quizzes, flashcards, and detailed explanations for each question. Boost your confidence and ace your exam effortlessly!

The output of console.log([1, 2][0]); will be 1. This result occurs because the expression [1, 2] creates an array containing two elements: the number 1 in the first position (index 0) and the number 2 in the second position (index 1). When you access an element of an array in JavaScript, you use square brackets with the index of the element you wish to access. Since the index for the first element of the array is 0, using [0] retrieves the first element, which is 1. Therefore, when you log this value to the console, it outputs 1.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy