Function Expressions in JavaScript

FuncionesÁmbito

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

Hemos revisado y comprobado los materiales, pero aún pueden existir errores. El contenido se ofrece únicamente con fines educativos, así que úsalo bajo tu propia responsabilidad y verifica con otras fuentes si es necesario.

✨ Pregunta a Lara — tu compañera de estudio con IA

Desbloquea soporte de aprendizaje personalizado. Lara puede explicar lecciones, resumir temas y responder tus preguntas — disponible desde el plan Go y superiores.


Lara te ayuda a aprender más rápido — exclusivo para los miembros ReadyTools Go, Plus y Max.

Sigue Tu Progreso 🚀

Aprende más fácilmente siguiendo tu progreso completamente gratis.