JavaScript Tutorial
JS Functions
Function Declaration and Expression
Declare functions using function myFunc() {} or expressions const myFunc = function() {}.
Parameters and Return Values
Functions can accept parameters and return values using return.
Arrow Functions
Shorter syntax: const add = (a, b) => a + b;.
Examples
function greet(name) {
return 'Hello ' + name;
}
const sum = (a, b = 0, c) => a + b + c;
console.log(greet('World'));
console.log(sum(5, 3));