-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions.js
51 lines (39 loc) · 960 Bytes
/
Functions.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
/*
* Functions
*/
// function declaration
function functionName(parameters) {
console.log(parameters)
}
// function expression
const functionExpression = function (parameters) {
console.log(parameters)
}
// arrow functions
const arrowFunctions = () => {
console.log('do something here')
}
// IIFE (Immediately Invoked Function Expression) functions
(function () {
console.log('function running immediately')
})();
// high order functions
function calculate(operation, a, b) {
return operation(a, b)
}
console.log(calculate((a, b) => a + b, 3, 2))
// Methods
const Person = {
name: 'username', age: 0, greet: function () {
console.log(`hi my name is ${this.name} and age is ${this.age}`)
}
}
console.log(Person.greet());
// Default Parameters
function greet(name = 'user') {
console.log(`hi, ${name}`)
}
// Rest Parameters
function sum(...numbers) {
return numbers.reduce((acc, curr) => acc + curr, 0)
}