forked from Swap76/Learn-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
40 lines (33 loc) · 1.23 KB
/
Copy pathfunctions.js
File metadata and controls
40 lines (33 loc) · 1.23 KB
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
38
39
40
function helpGST () { // This way you can write functions in JS
// There is no requirement of specifying the return type of function
console.log("Hii GST");
}
// Function is written to do a specific task many types in program.
// This increases the maintainability and decreases the repetition of same code.
helpGST(); // For executing we have to call that function
function Add (a, b) { // Here We have taken 2 Arguments a and b
const c = a + b;
return c; // This returns the result
}
console.log(Add(10, 5)); // This Calls the function
// We have to directly pass the arguments in function call
// Functions can have a default parameter value.
// Default value will be used if the argument is not defined.
function subtract(a, b = 1) {
const c = a - b;
return c;
}
console.log(subtract(5)); // Output 4.
console.log(subtract(5, 3)); // Output 2.
console.log(subtract(5, null)); // Output 5, because null is a valid value.
// Functions which don't have name are called Anonymous this should be assigned to a particular variable
const helpFast = function () {
return ("Fast Fast");
};
console.log(helpFast());
// Output Fast Fast
const helpVeryFast = () => {
return ("Very Fast");
};
console.log(helpVeryFast());
// Output Very Fast