JavaScript's default return value is unfined. When the code line of any function ends or the execution flow finds the return keyword, the function will terminate. When JavaScript encounters this keyword, it exits function execution and returns control to its caller.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Every function returns a value, which is undefined
by default.
The function terminates when any function's line of code ends or when the execution flow finds the return
keyword.
When JavaScript encounters this keyword, it exits function execution and returns control to its caller.
If you pass a value, that value is returned as the result of the function:
const dosomething = () => { return 'test' } const result = dosomething() // result === 'test'
You can only return a value.
To simulate returning multiple values, you can return an object constant or an array and use destructuring allocation when calling the function.
Use array:
Use object:
[Recommended learning: javascript Advanced Tutorial】
The above is the detailed content of What is the return value of JavaScript. For more information, please follow other related articles on the PHP Chinese website!