Home > Web Front-end > JS Tutorial > body text

What is the return value of JavaScript

醉折花枝作酒筹
Release: 2023-01-07 11:44:34
Original
6336 people have browsed it

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'
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template