Function Syntax
This code shows four different ways to create JavaScript functions.
by Edward Tanguay
HTML
<div id="output"></div>
JavaScript
function add(a, b) {
return a + b;
}
const addv2 = function(a, b) {
return a + b;
}
const addv3 = (a, b) => {
return a + b;
}
const addv4 = (a, b) => a + b;
const display = (html) => document.getElementById('output').innerHTML += html + '<br/>';
display(add(2,3));
display(addv2(2,3));
display(addv3(2,3));
display(addv4(2,3));
console.log(add(2,3));
console.log(addv2(2,3));
console.log(addv3(2,4));
console.log(addv4(2,3))