function variable (parameters) {
// Statements
return value;
}
// Give parameter a default value
function variable(parameters = value) {
// Statements
}
// If only one argument & statement, Automatically return
const variable = parameter => statement
// Arrow Function
const variable = (parameters) => {
// Statements
}
const variable = function(parameters) {
// Statements
}
variable(arguments) // Call a function
this.var
var
is available inside the whole function not just in block levellet
& const
have block level scope (function () {
// Statements
})();
variable(A).next().value
const functionName = function () {
let varName1 = 0;
return function () {
varName1++;
}
}
const varName2 = functionName();
varName2();
function functionName(A) {
let var = 0;
return {
next: function () {
if (var < A.length) {
return {
value: A[var++], done: false
}
}
else {
return {
done: true
}
}
}
}
}
// Gives the next value of elements of array after each execution
functionName(A).next().value
function* variable() {
yield value1;
yield value2;
}
variable(A).next().value // Gives the naxt value of elements of array after each execution