Home  >  Article  >  Web Front-end  >  What is the return value of JavaScript

What is the return value of JavaScript

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-21 10:50:076155browse

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.

What is the return value of JavaScript

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.

What is the return value of JavaScript

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:

What is the return value of JavaScript

Use object:

What is the return value of JavaScript

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn