arrow functions ⇒ a concise way to write function expressions good for simple functions that you use only once
(parameters) => some code
function declaration
function hello(){
console.log("hello");
}
hello();function expression
const hello = function(){
console.log("hello");
}
hello();arrow functions
//if only one code statment, dont need "{}"
//const hello = (name) => console.log(`hello ${name}`);
const hello = (name, age) => {
console.log(`hello ${name}`);
console.log(`you are ${age} years old`);
}
hello("bro", 25);another example
setTimeout(() => console.log("hello"), 3000);const numbers = [1, 2, 3, 4, 5, 6];
const squares = numbers.map((element) => Math.pow(element, 2));
const cubes = numbers.map((element) => Math.pow(element, 3));
const evenNumbs = numbers.filter((element) => element % 2 === 0);
const oddNumbs = numbers.filter((element) => element % 2 !== 0);
const total = numbers.reduce((accumulator, element) => accumulator + element);