JavaScript · Junior · Question 36 of 75

What does const arr = ['a', 'b']; console.log(arr[20]); print?

Explanation

Accessing a nonexistent index, like a missing object property, returns undefined without an error. For the last element, arr.at(-1) is handy.

Further reading

Problem with a question

JavaScript · Junior · question 36

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz