Array Reference Concept
Concept Check Medium
Question
What happens when you assign an array to a new variable and push to it?
Hint
Arrays are reference types in JavaScript.
Explanation
Arrays are objects in JavaScript, and objects are reference types. When you do const b = a;, both a and b point to the same array in memory. Pushing to b also affects a because they are the same array. To create an independent copy, use [...a] (spread) or a.slice().
Related Resources
Related Lessons
- JavaScript Arrays
Learn about reference vs value types.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.