JavaScript Curriculum
Writing JavaScript Like It's Now
mediumYou're reviewing a pull request on the Nexus team. The code uses ?., ??, ??=, ...args, and [key]: value. You understand JavaScript — but this syntax is unfamiliar. This lesson closes that gap. These aren't tricks. They're solutions to real, recurring problems that older syntax handled badly.
The syntax gap
The JavaScript you see in production looks different from the JavaScript in beginner tutorials. Not because it does different things — because the language kept adding better syntax for the same things. Every feature in this lesson replaces a pattern that was awkward, verbose, or silently dangerous.
Optional chaining ?.
The most common runtime error in JavaScript is TypeError: Cannot read properties of null. It happens whenever you assume a nested property exists and it doesn't.
Toggle any level of the object to null and watch the difference:
without ?. (unsafe)
with ?. (safe)
never throws — returns undefined if any link is null
user?.profile?.bio
"Engineer at Nexus"
user?.profile?.address?.city
"London"
user?.getPermissions?.()
undefined
?. also works on method calls and bracket notation:
Nullish coalescing ??
When you want a fallback value, || seems natural — but it treats 0, false, and "" as missing, which causes silent data corruption:
Select each value below and watch || and ?? diverge:
value of username
Falls back on any falsy value: false, 0, "", null, undefined, NaN
⚠ 0 is falsy — you lost a valid zero
Falls back only on null or undefined — 0, false, "" are kept as-is
Use ?? when the value might legitimately be 0, false, or "" and you only want to fall back on true absence. Use || when any falsy value should trigger the default.
The rule is precise: ?? only falls back on null and undefined — the two values that mean "truly not here". Everything else, including 0, false, and "", is kept as-is.
Modern syntax: shorthand, spread, rest, and more
Six patterns you'll see daily — each one with its old form and its modern replacement:
Object shorthand properties & methods
When a property name matches the variable holding its value, you can omit the value. Functions in objects can drop the colon and function keyword.
before (old way)
after (modern syntax)
Shorthand properties are everywhere in modern JS — especially when building objects from function parameters or destructured values.
Destructuring — a deeper look
Destructuring was introduced in lesson-07, but there are a few patterns worth seeing together:
Logical assignment ??= ||= &&=
These combine a check with assignment. They only assign if the condition is met:
Before ES2021 this required:
Template literal types
Beyond basic string interpolation, template literals have two advanced forms:
Putting it together — the buildConfig challenge
All five patterns meet in one function:
Three features, one small function, real behaviour. This is what modern JavaScript looks like.
Challenge
Write a function called buildConfig(overrides) that takes an optional overrides object and returns a config object. Use object spread to merge a set of defaults ({ timeout: 3000, retries: 3, debug: false }) with overrides. Use ??= to ensure the result always has a version property (default: '1.0.0') if it wasn't in overrides. Use optional chaining to safely read overrides?.env and set it as the env property (default via ?? to 'production').
Writing JavaScript Like It's Now
mediumYou're reviewing a pull request on the Nexus team. The code uses ?., ??, ??=, ...args, and [key]: value. You understand JavaScript — but this syntax is unfamiliar. This lesson closes that gap. These aren't tricks. They're solutions to real, recurring problems that older syntax handled badly.
The syntax gap
The JavaScript you see in production looks different from the JavaScript in beginner tutorials. Not because it does different things — because the language kept adding better syntax for the same things. Every feature in this lesson replaces a pattern that was awkward, verbose, or silently dangerous.
Optional chaining ?.
The most common runtime error in JavaScript is TypeError: Cannot read properties of null. It happens whenever you assume a nested property exists and it doesn't.
Toggle any level of the object to null and watch the difference:
without ?. (unsafe)
with ?. (safe)
never throws — returns undefined if any link is null
user?.profile?.bio
"Engineer at Nexus"
user?.profile?.address?.city
"London"
user?.getPermissions?.()
undefined
?. also works on method calls and bracket notation:
Nullish coalescing ??
When you want a fallback value, || seems natural — but it treats 0, false, and "" as missing, which causes silent data corruption:
Select each value below and watch || and ?? diverge:
value of username
Falls back on any falsy value: false, 0, "", null, undefined, NaN
⚠ 0 is falsy — you lost a valid zero
Falls back only on null or undefined — 0, false, "" are kept as-is
Use ?? when the value might legitimately be 0, false, or "" and you only want to fall back on true absence. Use || when any falsy value should trigger the default.
The rule is precise: ?? only falls back on null and undefined — the two values that mean "truly not here". Everything else, including 0, false, and "", is kept as-is.
Modern syntax: shorthand, spread, rest, and more
Six patterns you'll see daily — each one with its old form and its modern replacement:
Object shorthand properties & methods
When a property name matches the variable holding its value, you can omit the value. Functions in objects can drop the colon and function keyword.
before (old way)
after (modern syntax)
Shorthand properties are everywhere in modern JS — especially when building objects from function parameters or destructured values.
Destructuring — a deeper look
Destructuring was introduced in lesson-07, but there are a few patterns worth seeing together:
Logical assignment ??= ||= &&=
These combine a check with assignment. They only assign if the condition is met:
Before ES2021 this required:
Template literal types
Beyond basic string interpolation, template literals have two advanced forms:
Putting it together — the buildConfig challenge
All five patterns meet in one function:
Three features, one small function, real behaviour. This is what modern JavaScript looks like.
Challenge
Write a function called buildConfig(overrides) that takes an optional overrides object and returns a config object. Use object spread to merge a set of defaults ({ timeout: 3000, retries: 3, debug: false }) with overrides. Use ??= to ensure the result always has a version property (default: '1.0.0') if it wasn't in overrides. Use optional chaining to safely read overrides?.env and set it as the env property (default via ?? to 'production').