1function idk() {
2 alert('This is an alert!')
3}
4//call the function to make the function run by saying "Name of function + ()"
5idk()
1var x = myFunction(4, 3); // Function is called, return value will end up in x
2
3function myFunction(a, b) {
4 return a * b; // Function returns the product of a and b
5}
1function myFunc(theObject) {
2 theObject.make = 'Toyota';
3}
4
5var mycar = {make: 'Honda', model: 'Accord', year: 1998};
6var x, y;
7
8x = mycar.make; // x gets the value "Honda"
9
10myFunc(mycar);
11y = mycar.make; // y gets the value "Toyota"
12 // (the make property was changed by the function)
13
1A JavaScript function is defined with the function keyword,
2 followed by a name, followed by parentheses ().
3
4Function names can contain letters, digits, underscores,
5and dollar signs (same rules as variables).
6
7The parentheses may include parameter names separated by commas:
8(parameter1, parameter2, ...)
9
10The code to be executed, by the function, is placed inside curly brackets: {}
11
12_____________________________________________________
13function name(parameter1, parameter2, parameter3) {
14 // code to be executed
15}
16
17____________________________________________________
18let x = myFunction(4, 3); // Function is called, return value will end up in x
19
20function myFunction(a, b) {
21 return a * b; // Function returns the product of a and b
22}
23