You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not a big deal, but generally when writing ES2015+ it's preferable to use `const` where possible for variable declarations, as it provides a guarantee to the reader that you won't change what the variable references, and preference `let` over `var` otherwise , as this at least guarantees that the variable will be block-scoped rather than function-scoped. Being inconsistent with this means readers must sometimes have to consider whether a difference is there for a reason or not.
@@ -150,7 +150,7 @@ A function is pure if the return value is only determined by its
150
150
input values, and does not produce side effects.
151
151
152
152
```js
153
-
letgreet= (name) =>"Hi, "+ name ;
153
+
constgreet= (name) =>"Hi, "+ name ;
154
154
155
155
greet("Brianne") // "Hi, Brianne"
156
156
@@ -160,9 +160,9 @@ As opposed to:
160
160
161
161
```js
162
162
163
-
let greeting;
163
+
constgreeting;
164
164
165
-
letgreet= () => greeting ="Hi, "+window.name;
165
+
constgreet= () => greeting ="Hi, "+window.name;
166
166
167
167
greet(); // "Hi, Brianne"
168
168
@@ -173,7 +173,7 @@ greet(); // "Hi, Brianne"
173
173
A function or expression is said to have a side effect if apart from returning a value, it interacts with (reads from or writes to) external mutable state.
174
174
175
175
```js
176
-
var differentEveryTime =newDate();
176
+
constdifferentEveryTime=newDate();
177
177
```
178
178
179
179
```js
@@ -202,16 +202,16 @@ Writing functions where the definition does not explicitly identify the argument
202
202
203
203
```js
204
204
// Given
205
-
letmap= (fn) => (list) =>list.map(fn);
206
-
letadd= (a) => (b) => a + b;
205
+
constmap= (fn) => (list) =>list.map(fn);
206
+
constadd= (a) => (b) => a + b;
207
207
208
208
// Then
209
209
210
210
// Not points-free - `numbers` is an explicit argument
`incrementAll` identifies and uses the parameter `numbers`, so it is not points-free. `incrementAll2` is written just by combining functions and values, making no mention of its arguments. It __is__ points-free.
@@ -346,7 +346,7 @@ behavior of the program is said to be referentially transparent.
346
346
Say we have function greet:
347
347
348
348
```js
349
-
letgreet= () =>"Hello World!";
349
+
constgreet= () =>"Hello World!";
350
350
```
351
351
352
352
Any invocation of `greet()` can be replaced with `Hello World!` hence greet is
@@ -361,15 +361,15 @@ When an application is composed of expressions and devoid of side effects, truth
361
361
Lazy evaluation is a call-by-need evaluation mechanism that delays the evaluation of an expression until its value is needed. In functional languages, this allows for structures like infinite lists, which would not normally be available in an imperative language where the sequencing of commands is significant.
362
362
363
363
```js
364
-
letrand=function*() {
364
+
constrand=function*() {
365
365
while (1<2) {
366
366
yieldMath.random();
367
367
}
368
368
}
369
369
```
370
370
371
371
```js
372
-
let randIter =rand();
372
+
constrandIter=rand();
373
373
randIter.next(); // Each execution gives a random value, expression is evaluated on need.
374
374
```
375
375
@@ -412,8 +412,8 @@ The identity value is empty array `[]`
412
412
If identity and compose functions are provided, functions themselves form a monoid:
If a function accepts another function as an argument it is wrapped in parentheses.
570
570
571
571
```js
572
572
// call :: (a -> b) -> a -> b
573
-
letcall= (f) => (x) =>f(x)
573
+
constcall= (f) => (x) =>f(x)
574
574
```
575
575
576
576
The letters `a`, `b`, `c`, `d` are used to signify that the argument can be of any type. For this `map` it takes a function that transforms a value of some type `a` into another type `b`, an array of values of type `a`, and returns an array of values of type `b`.
0 commit comments