mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-25 04:56:23 +00:00
757 B
757 B
date | id | title |
---|---|---|
2020-10-06 | 4851138e-ddbd-4801-8178-51d990e327e5 | JavaScript arrow functions |
Introduction
const power = (base, exponent) => {
let result = 1;
for (let count = 0; count < exponent; count++) {
result *= base;
}
return result;
};
console.log(power(2, 3))
If there is only one parameter name, parentheses can be omitted around the parameter list. Same for the function body and brackets
const square1 = (x) => { return x * x; };
const square2 = x => x * x;
console.log(square1(5))
console.log(square1(6))
When an arrow function has no parameters at all, its parameter is just an empty set of parentheses
const horn = () => {
console.log("Toot");
};
horn()