Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
What exactly is function expression?

I thought before that function expression can be any function that is store in some variable. For example, this is function expression, because function is stored in func variable.

let func = function() {
   console.log(5);
};

And here's function expression, because callback function is stored in function's paremeter callback.

function func(callback) {
   callback();
};
func(function() {
   console.log(5);
});
//That's what I mean:
//let callback = function() {...}

But... recently I've found out that this callback function can also be considered as function expression. Why? This function isn't stored in some variable.

let arr = [18, 50];
let obj = {
    name: 'Karina',
};
arr.forEach(function func(value) {
    console.log(`${this.name} is ${value} years old`);
}, obj);

So, my question is...What exactly make function function expression?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I thought before that function expression can be any function that is store in some variable.

No. The variable to store to does not matter. The let func = …; is not part of the function expression, the function expression is only the part (expression) that comes in the middle.

  let func = function() {
//           ^^^^^^^^^^^^
     console.log(5);
//^^^^^^^^^^^^^^^^^^
  };
//^

This function isn't stored in some variable.

Actually there's no difference between your second and third snippet. You're passing the function constructed from the expression to a function, regardless how that function is declared (with parameters, with rest syntax, without parameters, or as a builtin like forEach).

But yes, you can have function expressions completely without variables, like in

  !function() {…}();
// ^^^^^^^^^^^^^^
  void function() {…};
//     ^^^^^^^^^^^^^^
  (function() {…})();
// ^^^^^^^^^^^^^^

Basically, function expressions are just the literal syntax (as in: object literal, string literal) for function objects.

about 4 years ago · Juan Pablo Isaza Report

0

I'm also learning about functional programming and found out that using a function as a value is indeed a function expression, as you said, by assigning an anonymous function to a variable. But I think the main difference relies on the function declaration being hoisted right? So context comes to play and all of that fun stuff :)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!