Course contents
- 01Variables
- 02Primitive Data Types
- 03Operators
- 04Conditionals
- 05Arrays
- 06Array methods and properties
- 07Objects
- 08Functions
- 09Callbacks
- 10Arrow functions
- 11Promises
- 12Async and await
- 13Loops
- 14DOM Manipulation
- 15Syntax parser
- 16Execution context and hoisting
- 17Call stack
- 18WebAPI and setTimeout
- 19Closures
- 20Function Constructors and Prototypes
- 21By value vs by reference
Functions
In order to run certain blocks of code, we can use functions. Whenever a function is invoked, the code inside the function gets executed. We can then return something from that function, although that’s not always necessary.
One way to define a function is to type the keyword “function”, followed by the name of that function. In between the curly brackets, we can specify what we want that function to do or what value to return.
You invoke a function by typing the name of that function, followed by parentheses.

We can pass arguments (or parameters) to functions by adding values between the brackets. In order for a function to be able to receive arguments, we need to specify it when defining our function.

Function expressions
There are two types of function expressions: named, and anonymous. The difference get clear when we declare a variable to a function:

Function statements
A function statement declares a function, and makes it possible for us to invoke the function any time.

The difference between function statements and function expressions will make a lot more sense when we get to hoisting!
Arrow functions
Since the new version of JavaScript, ES2015 got introduced, we have a shorter way of writing functions!

You can write arrow functions inline, which makes it possible for you to save a lot of space.

Once we get to the “this” keyword, you’ll notice some differences between the regular way of writing functions, or writing arrow functions!
References and further reading
- MDN: FunctionsDeclarations, expressions, parameters, and scope.
- MDN: function declarationThe syntax and hoisting behavior.