Are there any performance issues with passing an argument as an expression, instead of first making it a variable?
someFunction( x+2 );
var total = x+2; someFunction( total );
And how about functions?
someFunction( someOtherFunction() );
var sum = x+2; someFunction(sum);
This allocates memory to hold sum, which hangs around as long as the function is in scope. If the function ends up being a closure, this could be forever. In a recursive function this could be significant.
In most languages, this will compute x+2 on the stack and pass the result to someFunction. No memory is left hanging around.
The answer would be exactly the same for a function return value.
So in summary:
Most likely you won't notice a performance difference.
You may want to use variables when the result is re-used, or, when you want to examine the result easily in the debugger.
It's mostly a matter of personal preference.
No. And, more important, this sort of micro-optimization is (almost certainly) meaningless.
Having said that, if you were to use the result of the expression more than once, then there might be some completely imperceptible and totally not-worth-worrying-about benefit to saving the result of the calculation.
Write it to be readable. Don't worry about this stuff.
Just the obvious: Making a variable creates a variable. This costs memory and consumes some time when executing. Afterwards, it either will need time to garbage collect it, or not free the memory if your function leaks.
However, you won't notice any differences. The performance is not measurable at that level. Rule of thumb: Use variables when you really need them or when they improve readabilty of your code.