In plain words
Numbers and text are copied when you assign them, but objects and arrays are shared, so two names can point at the very same thing.
Where you see it
Maya edits a draft of a Quill note, clicks Cancel, and the saved note has changed anyway. The draft was never a copy: both names pointed at one object, so every edit landed on both.
What goes wrong
- Editing a "copy" that's really the original
const draft = note copies nothing. Cancel buttons and undo break, because the original was being edited the whole time.
- Changing React state in place
posts.push(newPost) changes the existing array, so React sees the same array and may not re-render. Make a new one: setPosts([...posts, newPost]).
posts.push(newPost); setPosts(posts); - Comparing objects with ===
=== checks whether two names point at the same object, not whether the contents match. Two orders with identical fields are still not ===.
What to tell your agent
Quick check
Sign in to earn +10 XP for itIn Quill, Maya edits a draft and clicks Cancel, but the saved note keeps her edits. The code starts with const draft = note. What's wrong?