Back again with me!
For those who code in JS, do you make function like this?
function multiply(a, b) {
return a * b;
};
Well, YOU SAK!Let's talk about Arrow Function in ES6 JS so you can stop using that kind of ugly-yet-so-long syntax to make a single
First of all, as you can see from the function above it will multiply A with B right?
You can actually make it as simple as this :
multiply = (a, b) => {
return a * b;
};
Is it not-so-simple to you? *sigh* fine. You can do this :multiply = (a, b) => a * b;
What about if you did not provide one of those parameters? It will surely gives you multiply = (a, b = 5) => a * b;
So when you don't know what to multiply by what, you can just run multiply(3);
and still get 15!
No comments:
Post a Comment