Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Returning Values from Functions | Functions in JavaScript
Introduction to JavaScript

bookReturning Values from Functions

メニューを表示するにはスワイプしてください

The primary purpose of a function is to return a value.

The function's space is deleted after its execution, and you rarely output information directly from the function to the console.

The return keyword is used to perform the value return operation, and it signifies the end of the function's execution:

1234567
function add(a, b) { return a + b; } let sum = add(25, 30); console.log("sum =", sum);
copy

In the example above, you can see that the function call (add(25, 30)) is replaced by the value 55 (25 + 30) after the return keyword.

Note

The function completes its execution and returns a value at the point of call, and the function's space is cleared.

It's also essential to understand that the return keyword terminates the execution of the function. Any code after the return statement will not be executed:

1234567891011
function add(a, b) { return a + b; console.log("Two numbers added"); console.log("Two numbers added"); console.log("Two numbers added"); console.log("Two numbers added"); } let numb = add(25, 12); console.log("numb =", numb);
copy

The console.log() statements after the return statement were not executed.

question mark

What does the return keyword do inside a JavaScript function?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 6.  5

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 6.  5
some-alt