Functions in JavaScript

Objekt-MethodenFunktionsausdrücke

Functions are one of the most powerful tools in JavaScript. They let you group code that does a specific task and reuse it whenever you need – like a recipe you can follow again and again.

Instead of writing the same code multiple times, you put it in a function and just 'call' the function when you want it to run. This makes your code cleaner, easier to fix, and much more organized.

How to Create a Function

Use the keyword function, give it a name, add parentheses () for parameters (we’ll talk about those soon), and curly braces {} for the code inside.

The code inside the function only runs when you call it with sayHello(); – perfect for doing something only when needed.

Parameters – Giving Information to Functions

Functions can accept inputs called parameters. Think of them as ingredients for your recipe.

You can have multiple parameters separated by commas.

Return Statement – Getting Results Back

Functions can give back a value with return. This is useful when you want to use the result somewhere else.

Once return runs, the function stops – nothing after it executes.

Why Functions Are So Useful

  • Reuse code without copying and pasting.
  • Make code easier to read and understand.
  • Fix bugs in one place instead of many.
  • Organize big programs into small, manageable pieces.

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.