Nodejs

No description

fork
loading
Files
  • index.js
index.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
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
/**
 * Assigning a function to a variable 
 * 
 * The variable "mindBlown" has a value which is a function.
 * 
 * Setting the variable doesn't call the function, 
 * so it outputs "undefined". 
 */
var mindBlown = () => {
	var myFunction = (name) => { 
		return "Hello, " + name
	}
	return myFunction
}
// Output:
// undefined

/**
 * Reading the "mindBlown" variable outputs its value, 
 * which is the function that we assigned to it. 
 */
mindBlown
// Output:
// () => {
// 	var myFunction = (name) => { 
// 		return "Hello, " + name
// 	}
// 	return myFunction
// }

/**
 * Calling the "mindBlown" variable executes the function. 
 * It evaluates to whatever the function returns. 
 */
mindBlown()
// Output:
// (name) => { 
// 		return "Hello, " + name
// 	}

/**
 * You can copy variables that have functions as their value,
 * just like you can copy any other kind of variable.
 * 
 * Like before, setting the variable doesn't call the function, 
 * so it outputs "undefined". 
 */
var adamsFunction = mindBlown
// Output:
// undefined

/**
 * Again, reading the variable outputs its value, 
 * which is the function that we assigned to it. 
 */
adamsFunction
// Output:
// () => {
// 	var myFunction = (name) => { 
// 		return "Hello, " + name
// 	}
// 	return myFunction
// }

/**
 * If you call a function, you can assign whatever it returns 
 * to a variable. Even if it returns another function.
 * 
 * Same as always, setting the variable evaluates to "undefined".
 */
var adamsFunction = mindBlown()
// Output:
// undefined

/**
 * Same as always, reading the variable prints its value.
 */
adamsFunction
// Output:
// (name) => { 
// 		return "Hello, " + name
// 	}

/**
 * Now you're getting it
 */
adamsFunction()
// Output:
// "Hello, undefined"

/**
 * #mindBlown
 */
adamsFunction('adam')
// Output:
// "Hello, adam"
node v10.16.0