We demonstrate how JavaScript treats functions the same as any other value, and show how they can be assigned to variables and how this concept can be used in the real world.
- [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 after their declaration in the code.…
Released
7/14/2017- What's functional programming?
- Functional vs. object-oriented programming
- First-class functions
- Higher-order functions
- Array functions
- Mapping, filtering, and reducing
- Simple callbacks
- Callbacks with arguments
Share this video
Embed this video
Video: Assigning functions to variables