First Class Functions
Many people who have previously had contact with programming in a different language, are suprised that you can attach to a function an object, a function or a primitive. This is what we get thanks to a functions being objects.
- Code, code in the function object is really a property.
So what does it look like?
Note that in the fifth line, we did something that we could not in many other languages. We added a property to the function.
This is not a mistake. To prove it, just look at what we received thanks to console.log.
Function Expressions / Function Statements
Is a unit of code with a value that has to be saved in a variable.
The function below is an anonymous function (a function without a name).
Functions stored in variables do not need function names. They are always invoked (called) using the variable name.
The function statement declares a function.
A declared function is "saved for later use", and will be executed later, when it is invoked (called)
Function Statements are hoisted into memory.
I will talk about two concepts. By value and by reference.