From the course: Learning Functional Programming with JavaScript (ES5)

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Assigning functions to variables

Assigning functions to variables - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript (ES5)

Start my 1-month free trial

Assigning functions to variables

- [Instructor] First we'll talk about how we assign functions to variables. As you can see from this example, it's quite simple. We just write it the same way as assigning any other value, except we put a function after the equal sign. These variables can then be called exactly like functions by adding parentheses after them with the correct number of arguments. Let's take a moment to notice a difference between a function variable with parentheses after it and a function variable without parentheses. Essentially, putting parentheses after a function variable transforms it into whatever its return value is. Writing the value without parentheses simply represents the function itself. You may be wondering what the difference is between defining functions the normal way and assigning functions to variables. After all, they do look and work very similarly. However, there is one important difference. When functions are defined the normal way, it doesn't matter whether we use them before or…

Contents