If I see something like this:
myVariable += myF开发者_StackOverflowunction();
How does that work? Like, for example, is the myFunction() function supposed to return a value that is added to myVariable?
That's correct. myFunction()
is evaluated first, (e.g., it'll run and return its value), then its return value will be added to myVariable.
Depends on your the result of your function and the value of your existing value that your are adding.
If the preceding
myVariable
is a string and the result is a number the values will be concatenated as a string.If the preceding
myVariable
is a number and the result is a number the values will be handled as a sum of numbers.If the preceding
myVariable
is a number or string but the result is a string themyVariable
will be treated as a string, and the values will be concatenated.
I assume it's the equivalent of
myVariable = myVariable + myFunction();
精彩评论