How can you create a function in Javascript?
To create a function we can use a function declaration. The function keyword goes first, then goes the name of the function, then a list of parameters between the parentheses (comma-separated, empty in the example above) and finally the code of the function, also named “the function body”, between curly braces.
function myFunction(p1, p2) {
return p1 * p2; // The function returns the product of p1 and p2
}
What is the difference between var and let in regards to scope?
The main difference is the scope difference, while let can be only available inside the scope it’s declared, like in for loop, var can be accessed outside the loop for example. This is unlike the var keyword, which defines a variable globally, or locally to an entire function regardless of block scope.
What is a pure function?
The function always returns the same result if the same arguments are passed in. It does not depend on any state, or data, change during a program’s execution. It must only depend on its input arguments.