Are function literals and function expressions the same thing, or is there a difference?
Asked
Active
Viewed 946 times
1
-
Yes, they're two different terms for the same concept. – Bergi Apr 01 '17 at 20:27
-
3Possible duplicate of [var functionName = function() {} vs function functionName() {}](http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname) – Ayman El Temsahi Apr 01 '17 at 20:28
-
See also [Exact meaning of Function literal in JavaScript](http://stackoverflow.com/q/12314905/1048572) and [Difference between “anonymous function” and “function literal” in JavaScript?](http://stackoverflow.com/q/5857459/1048572) – Bergi Apr 01 '17 at 20:30
-
@AymanElTemsahi No, not of that one. – Bergi Apr 01 '17 at 20:31
1 Answers
1
As answered on topic Exact meaning of Function literal in JavaScript: "A function literal is just an expression that defines an unnamed function."
Description of "function expression" on MDN about function name says, that it "Can be omitted, in which case the function is anonymous.". (unnamed function === anonymous function
)
Another example of anonymous function notation is "arrow function expression" in ES6
var func = (x, y) => { return x + y; };
This does the same thing as:
var func = function (x, y) { return x + y; };
and (almost) the same thing as:
function func(x, y) { return x + y; };
For more in-deph explanation read: Difference between “anonymous function” and “function literal” in JavaScript
TL;DR:
Function Literal is kind of function expression.