Let's take this code for example:
function doubleSay (str) {
return str + ", " + str;
}
function capitalize (str) {
return str[0].toUpperCase() + str.substring(1);
}
function exclaim (str) {
return str + '!';
}
If we want to call the functions in a precise way we would do something like:
const result = exclaim(capitalize(doubleSay("hello")));
With a pipe operator, the above code will look like this:
const result = "hello"
|> doubleSay
|> capitalize
|> exclaim;
It's way more readable and understandable.
There is a proposal already for adding a pipe operator in ECMAScript - github.com/tc39/proposal-pipeline-operator. Let's hope it gets approved and moved in the higher stages soon.
JavaScript stores numbers as double precision floating point numbers, following the international IEEE 754 standard. This leads to strange behaviours when working with numbers - just try to sum 0.1 and 0.2 and see the result.
With the rise of TypeScript and Flow, developers start to appreciate the need for static types, especially when we talk about big JavaScript projects.
ECMAScript 4 had a type system, but the standard was abandoned, due to political differences concerning language complexity.
There is a proposal for an optional type system which is in State 0.
We have const , which some see as an immutable data structure, but that is not the case. const provides an immutable binding, not pure immutability. Take the following example:
const names = ['Hashnode', 'Google', 'Facebook'];
names[3] = 'Twitter';
console.log(names) // ['Hashnode', 'Google', 'Facebook', 'Twitter']
As you can see, the array can be changed, even when assigned to a const variable type.
A true immutable object would throw an error when someone tries to change not only the value of the variable, but the members too.
This can also lead to a native deepEqual method.