Function Expressions in JavaScript
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
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.

