var square = function(x){
return x*x;
}
square(10);//100
var square = function(x){
var total = x*x;
console.log(total);
}
square(10);//second way(probably wrong)
I was reviewing what I once wrote when passing the JS-track on codecademy.com.
The task is incredibly simple - write a function that just squares a number and prints it in the console.
I did it the second way (using total variable inside the function block).
Now I would do it the first way. Both seem to work.
But is the second one really correct?
console.log(square(10)).console.logprints the value to the console and doesn't return anything, hence the implicit return value ofundefined.