Function Expressions in JavaScript

FunctionsScope

Function expressions are another way to create functions. Instead of using the function keyword at the start, you assign a function to a variable – like storing a recipe in a box you can name.

They look different from function declarations and have some important differences, especially with hoisting and the this keyword. Let’s explore them carefully with lots of examples.

Basic Function Expression

Create a function and store it in a variable. It can be named or anonymous.

This is anonymous because the function has no name – it’s stored in the variable sayHi.

Named Function Expression

You can give the function a name (useful for recursion or debugging).

Arrow Functions (Modern Syntax)

Arrow functions are a shorter way to write function expressions, introduced in ES6.

For multiple lines, use curly braces and return.

Key Differences: Declarations vs Expressions

  • Declarations are hoisted (can be called before definition).
  • Expressions are not hoisted – must be defined first.
  • Arrow functions have different 'this' behavior (lexical this).

Immediately Invoked Function Expressions (IIFE)

Run a function as soon as it’s created – useful for one-time setup.

Quick Quiz

We have reviewed and checked the materials, but errors may still occur. The content is provided for educational purposes only, so use it at your own responsibility and verify with other sources if needed.

✨ Ask Lara — your AI study partner

Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.


Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.

Track Your Progress 🚀

Learn more easily by tracking your progress completely for free.