I’m learning Arrow functions basics, and have some questions, hoping somebody might give me a clue.
I learned it from this website. https://javascript.info/arrow-functions-basics
1.
they say => means return its results, and they wrote something like this:
let sayHi = () => alert("Hello!");
sayHi();
which make me a bit confused, can I return an alert? becasue I have only seen this(below) before:
funtion showOk(){
alert('you agreed')
}
there’s no return written before alert. they just alert something and didn’t return it. so if I want to write sayHi() in a different way, would it be like this(below)?that’s the correct answer?
let sayHi = function() {
return alert("Hello!");
};
sayHi();
2.
another question is arguments.
let func = (arg1, arg2, ..., argN) => expression;
They say “This creates a function func that accepts arguments arg1..argN, …”, and then they give you another concrete example:
let sum = (a, b) => a + b;
/* This arrow function is a shorter form of:
let sum = function(a, b) {
return a + b;
};
*/
alert( sum(1, 2) ); // 3
here’s the question, I thought a and b are parameters, not arguments, the arguments in this code should be 1 and 2?
so what should I write in ()?
thank you for reading my questiones.