Arrow functions (ES2015) code example
Example 1: arrow function javascript
let testingFunc(string) => string == "Test" ? "Success!" : "Failure!";
console.log(testingFunc("test"));
let arrowFunc(string) => {
if (string = "test") {
return "Success!";
}
return "Failure!";
}
};
console.log(testingFunc("Test"));
Example 2: arrow function javascript
const power = (base, exponent) => {
let result = 1;
for (let count = 0; count < exponent; count++) {
result *= base;
}
return result;
};
const square1 = (x) => { return x * x; };
const square2 = x => x * x;
const horn = () => {
console.log("Toot");
};