There are different ways to construct functions. Here are 3:
...the syntax is a bit like variable but:
Example:
function divide(x, y, z) { let answer = x / y / z; let txt = 'the answer is: '; return txt + answer; }
To run the above function just like a variable you omit the first word function and then put your numbers for x, y and z in the brackets separated by commas:
divide(5, 7, 181);
Which gives: "the answer is: 0.003946329913180742"
Writing functions this way means they don’t have a name, hence anonymous.
document.querySelector('pre').onclick = function() { alert('fuck off you moron'); }
The above code works on this page but only on the first <pre> element.
These are a new way using =>
to represent a function.