Functions in Javascript are very confusing, especially for beginners.
Here is me explaining them with my handwritten notes. A Thread🧵
A function definition consists of the function keyword, followed by: - Name of the function.
- A list of parameters to the function
- The JavaScript statements that define the function, enclosed in curly brackets, {...}.
Different types and ways to create functions in Javascript
- Function Declaration
- Function Expression
- Arrow Function
- Functions Constructor
Calling functions
Defining a function does not execute it. Defining it names the function and specifies what to do when the function is called. Calling a function is known as invoking.
Functions Scope
Arrow functions An arrow function expression is a compact alternative to a traditional function expression, but is limited and can't be used in all situations.