Function Expressions in JavaScript

FunktionenGültigkeitsbereich

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

Wir haben die Materialien überprüft, dennoch können Fehler vorkommen. Der Inhalt dient ausschließlich Bildungszwecken, daher verwende ihn auf eigene Verantwortung und überprüfe ihn bei Bedarf mit anderen Quellen.

✨ Frag Lara — deine KI-Lernpartnerin

Entsperre personalisierte Lernunterstützung. Lara kann Lektionen erklären, Themen zusammenfassen und deine Lernfragen beantworten — verfügbar ab dem Go-Tarif.


Lara hilft dir, schneller zu lernen — exklusiv für ReadyTools Go-, Plus- und Max-Mitglieder.

Verfolge deinen Fortschritt 🚀

Lerne einfacher, indem du deinen Fortschritt kostenlos verfolgst.