JAVASCRIPT NOTES
Functions
A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" invokes it (calls it).
function name(parameter1, parameter2, parameter3) {
// code to be executed
}
Example
// Function to compute the product of p1 and p2
function myFunction(p1, p2) {
return p1 * p2;
}
Arrow functions are anonymous functions i.e. they are
functions without a name and are not bound by an identifier.
Arrow functions do not return any value and can be declared
without the function keyword. They are also called Lambda
Functions.
Arrow functions do not have the prototype property
like this, arguments, or super.
Arrow functions cannot be used with the new keyword.
Arrow functions cannot be used as constructors.
// Normal function for multiplication
// of two numbers
function multiply(a, b) {
return a * b;
}
console.log(multiply(3, 5));
Below code uses Arrow function to perform the multiplication in
single line.