If we make the function the abstract operation, we can log the result when it is returned. A function with the word
get in the name implies something to be got and returned, not logged by the function itself. Returning a value sets wheels in motion, whereas logging is a one-off operation with no lasting result.
const getAverageOfTwoValues = (a, b) => (a + b) / 2;
console.log(getAverageOfTwoValues(365, 27)); // 196
Part of coding practice is documentation. Simple code can be self-documented by the names we use on the functions and the running variables. Above, we use
b to represent two unknown values, which is adequate given that the name of the function says it all.
One school of thought is to put everything in variables which is essentially a label that says what it represents.
const average = (a + b) / 2;
The degree of verbosity will depend upon the stage of development. When sketching out ideas verbosity is helpful but once the testing is completed we need to trim the fat and simplify the code so it is both lightweight and easily readable.
To be clear, variable and function names are meant for human readers, not the computer. They help to describe the intermediate steps and expected outcomes at each stage. If code is readable and discernible in simplified form, then that is what to write.