Manuals / JavaScript / Chapter 3
A · Fundamentals · beginner · Week 1–2 · Chapter 3 of 14
Functions & scope
Functions are first-class: assign them, pass them, return them. Arrow functions vs function declarations. Scope (block vs function), hoisting intuition, and default parameters. Pure functions — same input, same output, no side effects — are the foundation of testable code.
Path progress16%
Step 1 of 5
Three ways to write functions
Declaration: function foo() {} — hoisted. Expression: const foo = function() {} — not hoisted. Arrow: const foo = () => {} — concise, no own this (important later).
Example
function isEven(n) { return n % 2 === 0 }
const isEvenExpr = function(n) { return n % 2 === 0 }
const isEvenArrow = (n) => n % 2 === 0Do this now
Write isEven(n) three ways. Verify all return the same results.
Was this step clear?
Chapter learning outcomes
- Function declarations vs expressions
- Arrow functions
- Parameters & defaults
- Block scope
- Return early pattern
Clear these before you leave
Side quest
String utilities module
Create utils.js with titleCase, truncate(str, max), and slugify(str). Test each in Node or console.