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
Copy file name to clipboardExpand all lines: README.md
+70-7Lines changed: 70 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,9 +145,6 @@ greet(); // Hello World!
145
145
### Classes
146
146
The classes are introduced as syntactic sugar over existing prototype based inheritance and constructor functions. So this feature doesn't bring new object-oriented inheritance model to JavaScript.
147
147
148
-
### Reflect
149
-
Reflection is the ability of a code to inspect and manipulate variables, properties, and methods of objects at runtime. JavaScript already provides Object.keys(), Object.getOwnPropertyDescriptor(), and Array.isArray() methods as classic refection features. In ES6, it has been officially provided through Reflect object. Reflect is a new global object which is used to call methods, construct objects, get and set properties, manipulate and extend properties. It is similar to Math and JSON objects and all the methods of this object are static.
150
-
151
148
### Set
152
149
Set is a built-in object to store collections of unique values of any type.
Reflection is the ability of a code to inspect and manipulate variables, properties, and methods of objects at runtime. JavaScript already provides Object.keys(), Object.getOwnPropertyDescriptor(), and Array.isArray() methods as classic refection features. In ES6, it has been officially provided through Reflect object. Reflect is a new global object which is used to call methods, construct objects, get and set properties, manipulate and extend properties. It is similar to Math and JSON objects and all the methods of this object are static.
326
+
325
327
### Proper Tail Calls
328
+
**Proper tail call(PTC)** is a technique where the program or code will not create additional stack frames for a recursion when the function call is a tail call.
329
+
330
+
For example, the below classic or head recursion of factorial function relies on stack for each step. Each step need to be processed upto `n * factorial(n - 1)`
331
+
332
+
```js
333
+
function factorial(n) {
334
+
if (n === 0) {
335
+
return 1
336
+
}
337
+
return n * factorial(n - 1)
338
+
}
339
+
console.log(factorial(5)); //120
340
+
```
341
+
342
+
But if you use Tail recursion functions, they keep passing all the necessary data it needs down the recursion without relying on the stack.
343
+
344
+
```js
345
+
function factorial(n, acc = 1) {
346
+
if (n === 0) {
347
+
return acc
348
+
}
349
+
return factorial(n - 1, n * acc)
350
+
}
351
+
console.log(factorial(5)); //120
352
+
```
353
+
354
+
The above pattern returns the same output as first one. But the accumulator keeps track of total as an argument without using stack memory on recursive calls.
355
+
356
+
The browsers which supports PTC do not generate stack overflow instead shows Infinity with below inputs,
The `flat()` method is used to 'flattens' the nested arrays into the top-level array. The functionality of this method is similar to Lodash's `_.flattenDepth()` function.
699
+
Prior to ES2019, you need to use `reduce() or concat()` methods to get a flat array.
In ES2019, the `flat()` method is introduced to 'flattens' the nested arrays into the top-level array. The functionality of this method is similar to Lodash's `_.flattenDepth()` function.
While creating symbols, you also can add a description to it for debugging purposes. But there was no method to access the description directly before ES2019. Considering this, ES2019 introduced a read-only description property to retrieve a string containing the description of the Symbol.
770
+
771
+
This gives the possibility to access symbol description for different variations of Symbol objects
Prior to ES9, if you don't need `error` variable and omit the same variable then catch() clause won't be invoked. Also, the linters complain about unused variables. Inorder to avoid this problem, the optional catch binding feature is introduced to make the binding parameter optional in the catch clause. If you want to completely ignore the error or you already know the error but you just want to react to that the this feature is going to be useful.
0 commit comments