-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscope.js
More file actions
49 lines (35 loc) · 799 Bytes
/
scope.js
File metadata and controls
49 lines (35 loc) · 799 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
41
42
43
44
45
46
47
48
49
console.log('Scope!');
// scope
let fruit = 'clementine';
console.log(fruit);
function printAVeggie() {
var veggie = 'spinach';
console.log(veggie);
}
printAVeggie();
// higher order function
function getCircleArea(r, pi) {
return pi * (r * r);
}
console.log(getCircleArea(2, 3.14));
function generateCircleAreaFunction(pi) {
return function(r) {
return pi * (r * r);
};
}
const basicArea = generateCircleAreaFunction(3.14);
console.log(basicArea(2));
const preciseArea = generateCircleAreaFunction(3.14159265358979);
console.log(preciseArea(2));
// function references + passing functions as arguments
function work() {
console.log('work!');
}
function executor(fn) {
console.log(fn);
fn();
fn();
fn();
}
executor(work);
executor(work);