-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecap.js
71 lines (56 loc) · 1.34 KB
/
recap.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let x = 12.0;
x = "Dixant";
console.log(`His name is: ${x}`);
// console.log(`Value of x: ${x}`);
// console.log("Value of x: " + x);
// Conditional Statements
let age = 10;
if(age>18){
console.log("You can vote!");
} else {
console.log("You cannot vote right now.");
}
// Functions
// Defining
function print_sum(a, b) {
console.log(`a: ${a}`);
console.log(`b: ${b}`);
console.log(`a + b = ${a + b}`);
}
function add(a, b) {
return a + b;
}
// Calling
print_sum(2, 3);
var sum = add(2, 3);
console.log(`Sum: ${sum}`);
// Anonymous functions
// Defining
var function_to_print_sum = function(a, b) {
console.log("a + b = " + (a + b));
};
// Invoking
function_to_print_sum(4, 4);
// Arrow Functions: Used more in Node JS
var function_to_print_sum = (a, b) => {
console.log("a + b = " + (a + b));
};
function_to_print_sum(4, 4);
// Callback Function is tasked as a parameter
// operation is the callback function in this example
function print_after_operation(a, b, operation) {
var result = operation(a, b);
console.log("Result: " + result);
}
function add(a, b) {
return a + b
}
function product(a, b) {
return a * b
}
print_after_operation(3, 4, add);
print_after_operation(3, 4, product);
// Anonymous function that runs only for this instance
print_after_operation(3, 4, (a, b) => {
return a - b;
});