1.
A function is created using the keyword function
and can be used as;
A. An expression:
const f = function(a) { console.log(a + 2); }
B. A declaration or statement:
function greet(name) { console.log("My name is " + name); }
C. Using an arrow =>
h = a => a + 3;
In general, functions may or may not have parameters and typically have a function body, where the statement to be executed is written in curly braces.
Function name(optional parameters) { statement to be executed; }
2.
Functions that use the keywords let and const are local to the block in which they were created. Code that sits outside of the local block cannot see or call it. Comparatively var has global scope, meaning it can be seen and called from outside the block it was stated in.
3.
A pure function is a function which;
- Given the same input, it will always produce the same outputs
- Has no side effects or rely on side effects from other code.