I went through ES6, assuming it's easy to upgrade to EcmaScript 2017.
Having walked, I got confused in this code
function f (x, y = 7, z = 42) { return x + y + z } f(1) === 50
What has the equivalent of ES5
function f (x, y, z) { if (y === undefined) y = 7; if (z === undefined) z = 42; return x + y + z; }; f(1) === 50;
I understood the default parameter value from it.
But what does f(1)===50 mean in both codes? What is the use of this?
Here is another example
function f (x, y, ...a) { return (x + y) * a.length } f(1, 2, "hello", true, 7) === 9
What does f(1, 2, "hello", true, 7) === 9 mean?
I understand that === for comparing the LHS and RHS of an operator, including the type and not only the values.
But why was it used like that?
Please explain its use.
This is the link where I got this from. http://es6-features.org/#RestParameter
javascript jquery equality function-call triple-equals
Tirthraj rao
source share