-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequired_features.txt
140 lines (133 loc) · 4.08 KB
/
required_features.txt
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
1. variable can store dynamic data type and dynamic value, variable can inferred data type from value, value of variable can be reassign with different data type or has option to make variable can store dynamic data type and dynamic value
```javascript
let something = "foo";
console.log(`something: ${something}`);
something = 123;
console.log(`something: ${something}`);
something = true;
console.log(`something: ${something}`);
something = null;
console.log(`something: ${something}`);
something = [1, 2, 3];
console.log(`something: ${something}`);
something = { "foo": "bar" };
console.log(`something: ${something}`);
```
```go
type Any interface{}
```
2. it is possible to access and modify variables defined outside of the current scope within nested functions, so it is possible to have closure too
```javascript
function getModifiedIndentLevel() {
let indentLevel = 0;
function changeIndentLevel() {
indentLevel += 1;
if (indentLevel < 5) changeIndentLevel();
return indentLevel;
}
return changeIndentLevel();
}
console.log(`getModifiedIndentLevel(): ${getModifiedIndentLevel()}`);
function createNewGame(initialCredit) {
let currentCredit = initialCredit;
console.log(`initial credit: ${initialCredit}`);
return function () {
currentCredit -= 1;
if (currentCredit === 0) {
console.log("not enough credits");
return;
}
console.log(`playing game, ${currentCredit} credit(s) remaining`);
};
}
const playGame = createNewGame(3);
playGame();
playGame();
playGame();
```
3. object/dictionary/associative-array/hash/hashmap/map/unordered-list-key-value-pair-data-structure can store dynamic data type and dynamic value
```javascript
const myObject = {
"my_string": "foo",
"my_number": 123,
"my_bool": true,
"my_null": null,
"my_array": [1, 2, 3],
"my_object": {
"foo": "bar"
}
};
console.log(`myObject: ${myObject}`);
```
4. array/list/slice/ordered-list-data-structure can store dynamic data type and dynamic value
```javascript
const myArray = ["foo", 123, true, null, [1, 2, 3], { "foo": "bar" }];
console.log(`myArray: ${myArray}`);
```
5. support passing functions as arguments to other functions
```javascript
function sayHello(callbackFunction) {
console.log("hello");
callbackFunction();
}
function sayHowAreYou() {
console.log("how are you?");
}
sayHello(sayHowAreYou);
sayHello(function () {
console.log("how are you?");
});
```
6. support returning functions as values from other functions
```javascript
function multiply(a) {
return function (b) {
return (a * b);
};
}
const multiplyBy2 = multiply(2);
const multiplyBy2Result = multiplyBy2(10);
console.log(`multiplyBy2Result: ${multiplyBy2Result}`);
```
7. support assigning functions to variables
```javascript
const getRectangleAreaV1 = function (rectangleWidth, rectangleLength) {
return (rectangleWidth * rectangleLength);
};
console.log(`getRectangleAreaV1(7, 5): ${getRectangleAreaV1(7, 5)}`);
const getRectangleAreaV2 = (rectangleWidth, rectangleLength) => {
return (rectangleWidth * rectangleLength);
};
console.log(`getRectangleAreaV2(7, 5): ${getRectangleAreaV2(7, 5)}`);
const getRectangleAreaV3 = (rectangleWidth, rectangleLength) => (rectangleWidth * rectangleLength);
console.log(`getRectangleAreaV3(7, 5): ${getRectangleAreaV3(7, 5)}`);
```
8. support storing functions in data structures like array/list/slice/ordered-list-data-structure or object/dictionary/associative-array/hash/hashmap/map/unordered-list-key-value-pair-data-structure
```javascript
const myArray2 = [
function (a, b) {
return (a * b);
},
"foo",
123,
true,
null,
[1, 2, 3],
{ "foo": "bar" }
];
console.log(`myArray2[0](7, 5): ${myArray2[0](7, 5)}`);
const myObject2 = {
"my_function": function (a, b) {
return (a * b);
},
"my_string": "foo",
"my_number": 123,
"my_bool": true,
"my_null": null,
"my_array": [1, 2, 3],
"my_object": {
"foo": "bar"
}
}
console.log(`myObject2["my_function"](7, 5): ${myObject2["my_function"](7, 5)}`);
```