Remember that the first part of this article can be found here:
To me the truth is that writing them serves me so much to reinforce some parts of one of my favorite languages and to be aware of the main novelties that appear.
So, as always, let’s do it!
Be careful with the use of the “spread operator”, because as you see it produces what is known as a “shallow clone”, that is, it copies the objects of the object to be cloned by reference!
In this recipe I summarize the main features of ECMAScript 2020 so you don’t miss any:
Nullish coalescing operator
As you have seen in the summary of the main novelties of ES2020, one of them is the appearance of the “nullish coalescing operator”, which allows us to quickly check if a variable is null, and, in that case, set a value by default.
In the recipe you have some examples with the value obtained when using it:
In the example of the recipe you can see how it can be used to control the data that is entered in an array. Useful, right?
Basically, by controlling the get function we can create a new push function that checks the type of the value to be added so that, by doing
we obtain that function and the verification is carried out.
Now that functional programming is living a second youth, it is worth reviewing what a pure function is and what elements cause it to lose that adjective.
Remember that the benefit of working whenever possible with pure functions is that we will always have the security of obtaining the same result in each invocation without external factors that alter it or without causing chain effects within our application.
One of the most used features of ES6 and the one that has contributed the most (in my opinion) to make the code more readable.
Its uses are multiple, from cloning objects to adding new elements to objects and arrays. Very useful, both he and his twin brother the “rest” operator.
That is why I prepared this summary of the values that it adopts within an object depending on how we invoke the methods. I know that there are not all the cases but I think it is a good approximation to be taking fluency when identifying what value this famous variable will have.
I think that knowing the language is essential before going to work on a layer above, hence I prepare these mini recipes every Wednesday to reinforce my knowledge.
Do you want to read more articles like this?
If you liked this article I encourage you to subscribe to the newsletter that I send every Sunday with similar publications to this and more recommended content: 👇👇👇