All 28 lessons ▾

Inside JavaScript · Lesson 13 of 28

Functions Are Values: Statements, Expressions and First-Class Functions

Updated 11 Nov 2026 · By Akshay, software engineer, India · 8 min read

Do you know that in JavaScript, a function is just a value? Yes! You can store it, you can pass it, you can even return it. And that one idea powers almost everything. So let's understand it properly.

The video for this lesson is coming soon.

A new lesson goes up every day at 11 am. Subscribe on YouTube so you don't miss it.

Got a doubt? Ask in the comments under the video.Subscribe

In one minute
  • Function statement = function declaration
  • Function expression: a function stored in a variable
  • The difference: hoisting
  • Anonymous: no name, used as a value
  • Named expression: its name works only inside
  • Parameters in the definition, arguments in the call
  • First-class: store, pass and return functions

Part 1Two ways to make a function

So today we are going to talk about the heart of JavaScript. Functions! Now you've used them in every episode so far. But there are many ways to create a function, and many fancy names. Function statement, function expression, function declaration, anonymous function, first-class function. And you know what? Interviewers love asking about these. So don't worry, we'll clear all of them, one by one. Let's start.

two-ways.js
1function greet() {2  console.log("Hello!");3}4 5var wave = function () {6  console.log("Hi!");7};

So here are the two most common ways. Look at the first one. It starts with the word function, and then a name, greet. So this is called a function statement. Its other name is function declaration. Same thing, two names. Now see the second one. It's different. We create a function, and assign it to a variable, wave. Here, the function is used as a value, just like a number or a string. And this is called a function expression. Remember this. Now you call both of them the same way, greet and wave, with brackets. So then what's the difference? Let's find out!

difference.js
1greet();2wave();3 4function greet() {5  console.log("Hello!");6}7var wave = function () {8  console.log("Hi!");9};
Output
Hello!
TypeError: wave is not a function

Now let's do something interesting. Let's call both of them before they're even written, and watch the memory carefully. greet is a function statement, so phase one stores the whole function. But wave is a var. So it gets undefined, just like any other var. The function part is just a value, waiting for line seven to run. Now line one calls greet, and it prints Hello. No problem at all. Now line two calls wave. But wait. Right now, wave is still undefined. And can you call undefined? No! So the console says, wave is not a function!

REMEMBER THIS
Thedifferenceishoisting:a
statementbringsitscode,an
expressionstartsasundefined.
with let or const, it's a dead-zone error instead

And that's a type error. So remember this. The big difference between a function statement and a function expression is hoisting. A function statement is hoisted with its whole code, so you can call it from anywhere. But a function expression follows the rules of its variable. With var, it's undefined until its line runs, so calling it early is a type error. And with let or const? It's in the temporal dead zone, so you get a reference error instead.

Part 2Functions with no name

Now, did you notice something about wave? The function itself had no name. We wrote function, and then straight away the brackets. So that kind of function has a name of its own. Let's see.

anonymous.js
1function () {2  console.log("Who am I?");3}
Output
SyntaxError: Function statements require a function name

So a function without a name is called an anonymous function. But now try to write one on its own, like this. JavaScript rejects the whole file. Nothing runs, and nothing even reaches memory. A syntax error. Function statements require a function name. Because when a line starts with the word function, JavaScript expects a function statement, and a statement needs a name. And notice the error said, function statements. So knowing these words helps you read error messages, blogs, and Stack Overflow answers properly. Now where do anonymous functions live? Wherever a function is used as a value. Assigned to a variable, like wave. Passed into another function. Or returned from one. There, no name is needed.

named.js
1var wave = function hand() {2  console.log(typeof hand);3};4wave();5hand();
Output
function
ReferenceError: hand is not defined

But you can also give that function a name, like hand. Now it's called a named function expression. Phase one gives wave undefined, and then line one stores the function in it. And look at the memory. There's wave, but no hand anywhere. Now here's the twist. Line four calls wave. Inside, line two asks for the type of hand. And it's function. It works! The function knows its own name. But line five calls hand from outside. And we get a reference error. hand is not defined. Why? Because the name hand only exists inside the function itself. It's never added to the outer scope. Only wave is. So when is it useful? When a function needs to call itself, and for clearer names in error messages while you debug.

Part 3Parameters and arguments

Next, two words people mix up all the time. Parameters, and arguments. So let's settle it in ten seconds.

add.js
1function add(a, b) {2  return a + b;3}4 5add(2, 3);

So in the function definition, a and b are parameters. They're the labels, the placeholders. And they behave like local variables of add. Now in the call, two and three are arguments. They're the actual values you pass in. Think of a form. The empty boxes, like name and age, are the parameters. What you write in those boxes are the arguments. So, parameters are in the definition, and arguments are in the call. Easy.

Part 4First-class functions

And now, the most important idea of today. The one that makes JavaScript so powerful.

REMEMBER THIS
Functionsarefirst-class:usethem
likeanyothervalue.
store them, pass them, return them

In JavaScript, functions are first-class citizens. That means you can use a function just like any other value. So you can store it in a variable, like wave. You can pass it into another function, as an argument. And you can return it from a function, like we did with closures. Now this ability is called first-class functions. Not every language has it, and it's the reason callbacks, closures, and higher-order functions are even possible.

pass.js
1function sayHi() {2  console.log("Hi!");3}4 5function run(fn) {6  fn();7}8 9run(sayHi);
Output
Hi!

So let's pass a function, and watch it happen. Phase one stores sayHi and run. Line nine calls run, and passes sayHi into it. Now notice, there are no brackets after sayHi. We're not calling it. We're handing over the function itself, as a value. run gets a new context, and its parameter fn now holds the sayHi function. Line six calls fn. And since fn is sayHi, it prints Hi! Then run is finished. So a function went into another function, just like a number would. That's first-class functions in action.

return.js
1function maker() {2  return function () {3    console.log("made!");4  };5}6 7var made = maker();8console.log(made);9made();
Output
ƒ () { console.log("made!"); }
made!

And now the third ability, returning a function. maker doesn't return a number or a string. It returns a whole function. Line seven calls maker, and made gets that function, as its value. Now watch line eight carefully. It logs made, without calling it. And the console shows the function itself, its code! Not a result. Because made is just a value, holding a function. Then line nine calls made, with brackets, and only now it runs, and prints made. So, a function can come out of a function too. Store, pass, return. All three, done!

arrow.js
1var wave = function (name) {2  return "Hi " + name;3};4 5var wave2 = (name) => "Hi " + name;

And now one more way you'll see everywhere. The arrow function. It's just a shorter way to write a function expression. Here, wave and wave2 do exactly the same thing. No function keyword, an arrow instead. And when the body is a single expression, even the word return goes away. Now arrow functions follow the same scope rules as normal functions. They do behave differently with the this keyword, and we'll see that in the this episodes. So for now, think of them as short function expressions.

INTERVIEW ANSWER
Statementvsexpression:
hoisting.First-class:
functionsarevalues.
stored, passed as arguments, returned
Quick quiz
quiz.js
1console.log(typeof hello);2console.log(typeof bye);3 4function hello() {}5var bye = function () {};

What do the two lines print?

Show the answer

So hello is a function statement, hoisted with its code. So line one prints function. And bye is a function expression with var, so in phase one it's just undefined. Line two prints undefined. Not an error, because typeof never crashes. Did you get both? Well done!

Your turn

Which of these names was new for you?

Answer in the comments under the video.

Your progress stays on this device.
A new lesson every day at 11 am

The video on YouTube, and the lesson as a swipe-through on Instagram.