forked from nhattruongniit/learn-javascripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimperative-declarative.js
More file actions
41 lines (25 loc) · 918 Bytes
/
imperative-declarative.js
File metadata and controls
41 lines (25 loc) · 918 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
38
39
40
/* ===========================
IMPERATIVE
- Procedural and OOP belong under imperative.
- Your code focuses on creating statements that change program states by creating algorithms.
- Your code will make use of conditinal statements, loops and inheritance.
================================*/
class Number {
constructor(number = 0) {
this.number = number;
}
add(x) {
this.number = this.number + x;
}
}
const myNumber = new Number(5);
myNumber.add(3);
console.log(myNumber.number);
/* ===========================
DECLARATIVE
- Logic, functional and domain-specific belong under declarative.
- Functional programming based on lambda calculus is Turing complete, avoids states, side effects and muatation of data.
- You create expressions instead of statements and evaluate functions.
================================*/
const sum = a => b => a + b;
console.log('declarative', sum(2)(3));