Functions in JavaScript

ObjektummetódusokFüggvénykifejezések

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

Az anyagokat átnéztük és ellenőriztük, de hibák továbbra is előfordulhatnak. A tartalom kizárólag oktatási célt szolgál, ezért saját felelősségre használd, és szükség esetén ellenőrizd más forrásokkal is.

✨ Kérdezd Larát — a tanulási partnered

Fedezd fel a személyre szabott tanulási támogatást. Lara elmagyarázza az anyagot, összefoglalja a témákat és megválaszolja a kérdéseidet — az Go csomagtól elérhető.


Lara segít gyorsabban tanulni — kizárólag a ReadyTools Go, Plus és Max tagoknak.

Kövesd nyomon a fejlődésed 🚀

Tanulj egyszerűbben utad nyomonkövetésével teljesen ingyen.