The important thing about them is you can pass functions to other functions. That allows for really powerful stuff. A lot of built-in functions make use of this: map, filter, sort, etc. Coming from a language that doesn't have first class functions, they blew my mind. But I can see how if you learned a language with first class functions as your first language, perhaps they wouldn't seem so extraordinary! Because after all, they are just like any other data type: you can assign them to a variable, you can put them in a dictionary ("object" in javascript terms), you can pass them to functions, etc. etc. Nothing seems unique about functions from that perspective. But take my word for it: there are languages that don't treat functions this way, and those languages are painful to work with once you are used to first class functions. Answer from evanhackett on reddit.com
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › function
function expression - JavaScript | MDN
A function expression is very similar to, and has almost the same syntax as, a function declaration. The main difference between a function expression and a function declaration is the function name, which can be omitted in function expressions to create anonymous functions.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-function-expression
JavaScript Function Expression - GeeksforGeeks
Function expressions can be named or anonymous. They are not hoisted, meaning they are accessible only after their definition. Frequently used in callbacks, closures, and dynamic function creation. Enable encapsulation of functionality within a limited scope. JavaScript ·
Published   January 23, 2026
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Function expressions
A Function Expression is created when the execution reaches it and is usable only from that moment. Once the execution flow passes to the right side of the assignment let sum = function…
🌐
Reddit
reddit.com › r/learnjavascript › what are the point of function expressions? when should i use them?
r/learnjavascript on Reddit: What are the point of function expressions? When should I use them?
October 19, 2023 -

Learning JavaScript and came across function expressions. The thing is, they just seem like standard functions. I don’t really even see how they’re “anonymous” since they have a variable name instead of a function name. The only different I can see is that function declarations are hoisted, whereas function expressions are not.

So then what’s even the point of them then? Are they just for making a function that is used only for a small scope of code? Or am I just missing something obvious about them?

Find elsewhere
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Functions
Functions - JavaScript | MDN
This is almost equivalent to just writing the function body, but there are a few unique benefits: It creates an extra scope of variables, which helps to confine variables to the place where they are useful. It is now an expression instead of a sequence of statements.
🌐
web.dev
web.dev › learn › javascript › functions › function-expressions
Function expressions | web.dev
March 31, 2024 - Function expressions are functions created where an expression is expected. You'll frequently encounter function expressions as values assigned to a variable.
Top answer
1 of 5
430

They're actually really similar. How you call them is exactly the same.The difference lies in how the browser loads them into the execution context.

Function declarations load before any code is executed.

Function expressions load only when the interpreter reaches that line of code.

So if you try to call a function expression before it's loaded, you'll get an error! If you call a function declaration instead, it'll always work, because no code can be called until all declarations are loaded.

Example: Function Expression

alert(foo()); // ERROR! foo wasn't loaded yet
var foo = function() { return 5; } 

Example: Function Declaration

alert(foo()); // Alerts 5. Declarations are loaded before any code can run.
function foo() { return 5; } 


As for the second part of your question:

var foo = function foo() { return 5; } is really the same as the other two. It's just that this line of code used to cause an error in safari, though it no longer does.

2 of 5
114

Function Declaration

function foo() { ... }

Because of function hoisting, the function declared this way can be called both after and before the definition.

Function Expression

  1. Named Function Expression

    var foo = function bar() { ... }
    
  2. Anonymous Function Expression

    var foo = function() { ... }
    

foo() can be called only after creation.

Immediately-Invoked Function Expression (IIFE)

(function() { ... }());

Conclusion

Douglas Crockford recommends to use function expression in his «JavaScript: The Good Parts» book because it makes it clear that foo is a variable containing a function value.

Well, personally, I prefer to use Declaration unless there is a reason for Expression.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Functions › Arrow_functions
Arrow function expressions - JavaScript | MDN
1 month ago - An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate limitations in usage:
🌐
freeCodeCamp
freecodecamp.org › news › function-declaration-vs-function-expression
Function Declaration vs Function Expression
April 26, 2023 - This is an IIFE where we create a function that executes console.log('deeecode'). Immediately after creating the function, we execute it as you see at the end (()). Here, we do not intend to use the function later, so a function expression works fine. Using a function declaration here will not throw an error, but the name of the function will be inaccessible:
🌐
Medium
medium.com › @alaminkhanshakil › understanding-function-declarations-and-function-expressions-in-javascript-a8ff37ebb5c4
Understanding Function Declarations and Function Expressions in JavaScript | by Al Amin Khan Shakil | Medium
March 11, 2025 - A function expression is another way to define a function in JavaScript. Instead of using the function keyword directly, you assign an anonymous or named function to a variable.
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › functions.html
TypeScript: Documentation - More on Functions
In JavaScript, functions can have properties in addition to being callable. However, the function type expression syntax doesn’t allow for declaring properties.
🌐
Medium
publication.masteringbackend.com › function-declaration-vs-function-expression-in-javascript-when-to-use-them-2edc7d3e76a2
Function declaration vs. function expression in JavaScript: When to use them. | by Codevet | Masteringbackend
July 23, 2022 - Unlike function declaration, you can’t call a function expression before creating it, it will throw an error. So we can only call a function expression only after we have created it. in JavaScript, a function is treated as a special kind of value, and any value can be assigned to a variable.
🌐
Programiz
programiz.com › javascript › function
JavaScript Function and Function Expressions (with Examples)
In JavaScript, a function expression is a way to store functions in variables.
🌐
freeCodeCamp
freecodecamp.org › news › when-to-use-a-function-declarations-vs-a-function-expression-70f15152a0a0
When to use a function declaration vs. a function expression
April 19, 2019 - The name — immediately invoked function expressions — pretty much says it all here. When a function is created at the same time it is called, you can use an IIFE, which looks like this: ... For an in-depth look at IIFEs, check out this comprehensive article. A function passed to another function is often referred to as a “callback” in JavaScript.
🌐
WsCube Tech
wscubetech.com › resources › javascript › function-expression
Function Expression in JavaScript: Types, Syntax, Examples
October 11, 2025 - Learn about Function Expression in JavaScript, its syntax, and examples to enhance your programming skills. Master this concept with clear explanations
🌐
SitePoint
sitepoint.com › blog › javascript › when to use a function expression vs. function declaration
When to Use a Function Expression vs. Function Declaration — SitePoint
November 7, 2024 - The primary difference between function expressions and function declarations lies in the way JavaScript engine interprets them. A function declaration is parsed before any code is executed, meaning you can call a function that is declared later in your code.
🌐
DEV Community
dev.to › catherineisonline › function-declarations-function-expressions-2o5k
Function declaration vs expression - DEV Community
August 13, 2024 - When we use function expression we do not declare any variable or expression with this function, we save this function inside the variable where the function is a value. During hoisting, the value is not hoisted however the variable where we ...