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
1// variable:
2var num1;
3var num2;
4// function:
5function newFunction(num1, num2){
6 return num1 * num2;
7}
1the function of javascript is to teach first year programers
2synactically correct language constructs by way of an anti-pattern.
3
1<html>
2 <head>
3 <script type = "text/javascript">
4 function concatenate(first, last) {
5 var full;
6 full = first + last;
7 return full;
8 }
9 function secondFunction() {
10 var result;
11 result = concatenate('Zara', 'Ali');
12 document.write (result );
13 }
14 </script>
15 </head>
16
17 <body>
18 <p>Click the following button to call the function</p>
19 <form>
20 <input type = "button" onclick = "secondFunction()" value = "Call Function">
21 </form>
22 <p>Use different parameters inside the function and then try...</p>
23 </body>
24</html>
1<div class="alert alert-warning alert-dismissible fade show" role="alert">
2 <strong>Holy guacamole!</strong> You should check in on some of those fields below.
3 <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
4</div>
1var x = myFunction(10, 10); // 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}
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
2 var x = myFunction(4, 3); // Function is called, return value will end up in x
3
4
5function myFunction(a, b) {
6
7 return a * b;
8// Function returns the product of a and b
9
10}
11
12