-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.js
More file actions
37 lines (24 loc) · 784 Bytes
/
Copy pathFunctions.js
File metadata and controls
37 lines (24 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// lets understand the power of funtions in js
// An additional thing you will learn with functions is memory managemant
// lets write our first function
function sum(a,b) {
console.log(a+b);
};
// sum // this is funciton reference
sum(11, 22); // this is function executon
// return keyword
function subtract(num1, num2) {
return num1 - num2
};
console.log(subtract(9828, 9217));
// let's implement some logic here
function correctSum(num1 = 4, num2 = 4) {
if (typeof num1 === "number" && typeof num2 === "number") {
return num1 + num2;
} else {
console.log("please write correct values");
}
}
console.log(correctSum(11,2));
// we can also set default values when we are defining our funcitons.
console.log(correctSum()); // 8