Javascript - Function Expressions
Code Life
By Pierre Marsaa
A Function Stored in a Variable
So far you've declared functions with function name() {}. There's a second way: create the function without a name and store it in a variable. This is called a function expression:
↗️
Loading editor...
↶
↷
The variable cheer now holds the function, and you call it exactly like before, with parentheses. Note the semicolon at the end: it's an assignment like any other.
Why bother?
Right now this may look like a longer way to do the same thing, and that's fair. The real payoff comes when you start passing functions around, especially with the array methods of class 12. For now, just get comfortable with the form.
Verify