Are function literals and function expressions the same thing, or is there a difference?
-
Yes, they're two different terms for the same concept.Bergi– Bergi2017-04-01 20:27:10 +00:00Commented Apr 1, 2017 at 20:27
-
3Possible duplicate of var functionName = function() {} vs function functionName() {}Ayman El Temsahi– Ayman El Temsahi2017-04-01 20:28:21 +00:00Commented Apr 1, 2017 at 20:28
-
See also Exact meaning of Function literal in JavaScript and Difference between “anonymous function” and “function literal” in JavaScript?Bergi– Bergi2017-04-01 20:30:59 +00:00Commented Apr 1, 2017 at 20:30
-
@AymanElTemsahi No, not of that one.Bergi– Bergi2017-04-01 20:31:33 +00:00Commented Apr 1, 2017 at 20:31
1 Answer
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.