c(a(),b()) - this is a function invocation expression.
Invocation expressions consist of following parts:
- function expression that identifies the function that is to be called.
- opening parenthesis.
- comma-separated list of zero or more argument expressions.
- closing parenthesis.
When function invocation expression is evaluated, function expression is evaluated first and then the argument expressions, if there are any, are evaluated (from left to right) to produce values that are to be passed to the function that is being called.
c(a(),b()) is evaluated as:
First of all, identifier c is evaluated. If c wasn't defined, javascript would have thrown a ReferenceError.
Since in this case, c is a function, so argument expressions are evaluated from left to right.
First a() is evaluated which itself is an invocation expression. So a is evaluated first and since there are no arguments, function a is invoked and the body of the function a executes. Since a returns new Date().getTime(), it becomes the value of a() invocation expression.
After that b() is evaluated in the same way as a() is evaluated.
Finally, c() is called with the return values of a() and b() as its arguments. If c wasn't a function, javascript would have thrown a TypeError.
c()does not call eithera()orb(); they're called in preparation for the call toc(), and they're called one at a time, left to right.c, the arguments tocare resolved left-to-right by callingathenb.c(a(),b()). If it's not clear what's happening, don't do it that way. Good programmers write code that humans can understand.