Module 4 · Lesson 1 of 413/32 in the course~16 min
Module lessons (1/4)
Declaring a function
Lesson preview5 hands-on exercises readyJavaScript Course · Module 4 — Functions
function declaration vs function expression, parameters, return.
What you'll learn in this lesson
- Distinguish between function declaration (
function fn()) and function expression (const fn = function ()). - Understanding hoisting rules: why declarations can be invoked before the definition line but expressions follow
const/let(TDZ). - Recognize the implicit return values (
undefinedifreturnis missing) and the ASI trap of thereturnnewline. - Passing functions as arguments (higher-order functions and callbacks).
Overview
In JavaScript, functions are first-class values: they can be called, stored in variables, returned from other functions, and passed as arguments. Understanding the difference between declaration and expression avoids bugs related to the definition order in the same module.
Sections covered in this lesson
- 1Mental model: declaration vs expression
- 2Progressive examples
- 3Guided laboratory
- 4Check for understanding
Pro Lesson · Module 4 — Functions
Unlock "Declaring a function" and the full JavaScript Course curriculum
function declaration vs function expression, parameters, return.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in JavaScript Course plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.