1<!DOCTYPE html>
2<html>
3<body>
4
5<h2>JavaScript Functions</h2>
6
7<p>calculator function example</p>
8
9<label>Result:</label>
10
11<p id="fnc"></p>
12
13<script>
14function myFunction(p1, p2) {
15 return p1 * p2;
16}
17document.getElementById("fnc").innerHTML = myFunction(2, 3);
18</script>
19
20</body>
21</html>
22
1// 3 ways you see it
2function name(argument){
3 return argument + 2
4 //return something here
5}
6name(4) // equals 6
7
8let name = function(arg){ return arg + 2}
9name(4) //this equals 6, here we are calling our name function
10
11//es6 style
12
13let name = (arg) => {return arg+ 2}
14name(4) //equals 6
1//A JavaScript function is a block of code designed to perform a particular task.
2//A JavaScript function is executed when "something" invokes it (calls it).
3
4function myFunction(p1, p2) {
5 return p1 * p2; // The function returns the product of p1 and p2
6}