Function Declarations, Expressions & Arrows in JavaScript

From the JavaScript cheat sheet · Functions · verified Jul 2026

Function Declarations, Expressions & Arrows

Three ways to define functions — declarations, expressions, and arrow functions

javascript
// Declaration (hoisted)
function greet(name) { return "Hello " + name; }

// Expression (not hoisted)
const greet = function(name) { return "Hello " + name; };

// Arrow function (short syntax, no own "this")
const greet = (name) => "Hello " + name;
💡 Arrow functions inherit "this" from the parent scope — perfect for callbacks and closures
⚡ Single-expression arrows have implicit return — no curly braces, no return keyword
📌 Don't use arrows for object methods or constructors — they have no own "this"
🟢 Declarations are hoisted; expressions and arrows are NOT — order matters

More JavaScript tasks

Back to the full JavaScript cheat sheet