Had troubles choosing title. I am learning js and looking for place to ask questions, most of the time they are simple. Is stackoverflow a good place for that or can you recommend another place (irc or forum)?
Begann to work with functions in js. These lines are given:
function calculateTax(amount){
let result = amount * 0.08;
return result;
}
let tax = calculateTax(100);
console.log(tax);
I ask my self why function needs a local variable "result", why couldn't the parameter be used:
function calculateTax(amount){
amount * 0.08;
return amount;
}
let tax = calculateTax(100);
console.log(tax);
My guess is because the parameter is a placeholder or is a variable needed to safe the multiplication and the 0.08? I think I read that parameters are variables to, is this correct? Is the 100 in the function a parameter too?
I think I waste to much time on such things. My problem is, I am to curious. Thank you for your time.
function calculateTax(amount){ return amount * 0.08; }amount… it’s nice for readability ifamountalways refers to the parameter instead of switching to something else partway through the function. In this particular case, as people have gotten at,resultdoesn’t add much value as a new name and the better way to write it is a directreturn amount * 0.08.