const add = (a, b) => a + b; const counter = { value: 23, inc: function () { this.value + 1; }, }; const greet = () => { console.log("Hey David"); }; // const btnGreet = document.getElementById("greet"); // btnGreet.addEventListener("click", greet); // eine Funktion, die eine Funktion zurück gibt const count = function () { let counter = 0; return function () { console.log("TEST"); }; }; count()(); const oneWord = function (str) { return str.replace(/ /g, "").toLowerCase(); }; const upperFirstWord = function (str) { const [firstWord, ...others] = str.split(" "); return [firstWord.toUpperCase(), ...others].join(" "); }; // Higher-order function const transformer = function (str, fn) { console.log(`Original string: ${str}`); console.log(`Transformed string: ${fn(str)}`); console.log(`Transformed by: ${fn.name}`); }; transformer("JavaScript is the best", upperFirstWord); transformer("JavaScript is the best", oneWord);