Stop 04 · JavaScript & TypeScript for BackendTopics · 1/12

ES6+ Refresher

Part of the Backend Developer Roadmap

In short

Open any modern Node.js codebase and you'll see arrows, spreads and question marks everywhere. Learn these few features and backend code stops looking like a puzzle.

A quick pass over modern JavaScript syntax — destructuring, arrow functions, spread/rest, template literals — that you'll use constantly writing backend code.

The mascot opens a shiny new toolbox next to an old rusty one.

Think of it like this

The new toolbox

Your grandfather's toolbox works, but every job needs three tools and some force. The new one has a tool for each job, neatly sorted. Modern JavaScript is the new toolbox: the same jobs, with less code and fewer bugs.

Watch it happen

Reading a request body the modern way

name
0
email
1
role
2
city
3

1/5req.body arrives with four fields. Old code read each one as req.body.name, req.body.email and so on.

The big ideas

What you need to know

const and let

Use const by default, let when you reassign. Forget var. Block scope means fewer surprise bugs.

Arrow functions

(a, b) => a + b is short and doesn't create its own this, which is handy inside callbacks.

Destructuring and spread

Pull fields out of objects in one line, and copy or merge objects with { ...a, ...b }.

?. and ??

user?.address?.pin avoids crashes on missing data. value ?? 10 uses 10 only for null or undefined.

See it in code

Walk through the code

js
1const user = { name: "Aman", email: "a@x.in", address: null };2 3const { name, email, role = "user" } = user;4const pin = user.address?.pin ?? "not given";5 6const safeUser = { ...user, password: undefined };7const greet = (n) => `Hello, ${n}!`;8 9const ids = [3, 1, 2];10const sorted = [...ids].sort((a, b) => a - b);11 12console.log(greet(name), role, pin, sorted);13// Hello, Aman! user not given [ 1, 2, 3 ]

1/4Destructure name and email, and give role a default because the object doesn't have it.

[...ids].sort() copies first, because sort changes the array in place. Spreading keeps the original safe.

Save yourself the pain

Common mistakes

Oops

Using || for defaults, so a real value of 0 or "" gets replaced.

Do this instead

Use ?? when 0, false or an empty string are valid. It only replaces null and undefined.

Oops

Thinking { ...user } makes a deep copy.

Do this instead

Spread copies one level. Nested objects are still shared. Use structuredClone(user) for a deep copy.

Your mission

Modernise old code

~20 min

Quick check

What does const qty = req.body.qty ?? 1 give when qty is 0?

Go deeper

  1. 1Skim a checklist of ES6+ features and confirm you're comfortable using each on the backend.
  2. 2Refactor an older callback-heavy script into modern async/await syntax.
  3. 3Focus especially on destructuring and optional chaining — they show up everywhere in API handlers.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge