JavaScript Curriculum
Packaging Related Data
mediumEvery Nexus user has a name, a role, a level, an XP total, a theme preference, and a department. Right now they live in six separate variables that get passed around everywhere together. When a new property gets added, every function that touches users needs updating. There's a structure built for exactly this problem — and it's the foundation of almost everything in JavaScript.
Six variables that belong together
Six variables, but they're all about the same thing. Pass them to a function and you're passing six arguments. Add a property and you're updating six call sites. Lose track of which name variable belongs to which user and you've introduced a subtle bug.
An object bundles related data under one name, with labelled slots called properties:
One variable. Six properties. Pass user to a function and it gets everything.
Reading properties — two notations
Click any property in the object below. Both access syntaxes update live:
dot notation
Use when the key name is known at write time
bracket notation
Use when the key is in a variable or dynamic
The rule is simple: dot notation by default, bracket notation when the key is dynamic.
Writing and updating properties
Destructuring — extract properties cleanly
When you need several properties from an object, destructuring lets you grab them all in one line instead of repeating the object name every time.
Step through both approaches and feel the difference:
Rename while destructuring — useful when the property name conflicts with an existing variable:
Default values — for properties that might not exist:
Spread syntax — composing and updating objects
The spread operator ... copies all properties from one object into another. This is how you update an object without mutating the original — critical for React, state management, and any code that needs predictable data flow.
base — defaults
overrides — applied last
Methods — functions as properties
Objects can hold any value — including functions. A function stored on an object is called a method:
this inside a method refers to the object the method belongs to. Arrow functions don't have their own this — use regular function syntax for methods that need it.
Nested objects — objects within objects
Real-world data is often nested. An object can hold other objects as property values:
The immutable update pattern
The single most important object pattern in modern JavaScript — used constantly in React:
Your challenge
Build a user object for Jordan — then write promote(user, newLevel) that returns a new object using spread. The test is logging both the original and the result: Jordan should still be level 7, the promoted version should be level 8.
This is the exact pattern you'll use in React state management from day one.
Challenge
Create a user object for a team member called \"Jordan\" — an admin at level 7 with 3420 XP, currently active, working in the Security department. Then write a function called promote(user, newLevel) that returns a NEW object with the level updated (use spread — don't mutate). Call promote with Jordan and level 8, log the original and promoted objects to prove the original didn't change.
Packaging Related Data
mediumEvery Nexus user has a name, a role, a level, an XP total, a theme preference, and a department. Right now they live in six separate variables that get passed around everywhere together. When a new property gets added, every function that touches users needs updating. There's a structure built for exactly this problem — and it's the foundation of almost everything in JavaScript.
Six variables that belong together
Six variables, but they're all about the same thing. Pass them to a function and you're passing six arguments. Add a property and you're updating six call sites. Lose track of which name variable belongs to which user and you've introduced a subtle bug.
An object bundles related data under one name, with labelled slots called properties:
One variable. Six properties. Pass user to a function and it gets everything.
Reading properties — two notations
Click any property in the object below. Both access syntaxes update live:
dot notation
Use when the key name is known at write time
bracket notation
Use when the key is in a variable or dynamic
The rule is simple: dot notation by default, bracket notation when the key is dynamic.
Writing and updating properties
Destructuring — extract properties cleanly
When you need several properties from an object, destructuring lets you grab them all in one line instead of repeating the object name every time.
Step through both approaches and feel the difference:
Rename while destructuring — useful when the property name conflicts with an existing variable:
Default values — for properties that might not exist:
Spread syntax — composing and updating objects
The spread operator ... copies all properties from one object into another. This is how you update an object without mutating the original — critical for React, state management, and any code that needs predictable data flow.
base — defaults
overrides — applied last
Methods — functions as properties
Objects can hold any value — including functions. A function stored on an object is called a method:
this inside a method refers to the object the method belongs to. Arrow functions don't have their own this — use regular function syntax for methods that need it.
Nested objects — objects within objects
Real-world data is often nested. An object can hold other objects as property values:
The immutable update pattern
The single most important object pattern in modern JavaScript — used constantly in React:
Your challenge
Build a user object for Jordan — then write promote(user, newLevel) that returns a new object using spread. The test is logging both the original and the result: Jordan should still be level 7, the promoted version should be level 8.
This is the exact pattern you'll use in React state management from day one.
Challenge
Create a user object for a team member called \"Jordan\" — an admin at level 7 with 3420 XP, currently active, working in the Security department. Then write a function called promote(user, newLevel) that returns a NEW object with the level updated (use spread — don't mutate). Call promote with Jordan and level 8, log the original and promoted objects to prove the original didn't change.