Yahoo India Web Search

Search results

  1. The return statement stops the execution of a function and returns a value. Read our JavaScript Tutorial to learn all you need to know about functions. Start with the introduction chapter about JavaScript Functions and JavaScript Scope.

  2. Aug 11, 2023 · js. return ( . a + b. ); Examples. Interrupt a function. A function immediately stops at the point where return is called. js. function counter() { // Infinite loop for (let count = 1; ; count++) { . console.log(`${count}A`); // Until 5 if (count === 5) { return; } .

  3. Jun 6, 2024 · The return statement in JavaScript is used to end the execution of a function and specifies the value to be returned by that function. The return statement stops the execution of a function and returns a value.

  4. Feb 2, 2024 · JavaScript allows us to use the return statement to end the function’s execution to specify the value that needs to be returned to the code that is calling it. Below are the methods and examples of how to use a return statement in JavaScript. Syntax: function nameOfFunction() { return result // Value that need to be returned. } Table of Content.

  5. Jan 21, 2020 · JavaScript Return Statements. Introduction. When a return statement is called in a function, the execution of this function is stopped. If specified, a given value is returned to the function caller. If the expression is omitted, undefined is returned instead. return expression; Functions can return:

  6. Jan 1, 2024 · To return a value from a custom function, you need to use the return keyword. We saw this in action recently in our random-canvas-circles.html example. Our draw() function draws 100 random circles somewhere on an HTML <canvas>: js. function draw() { . ctx.clearRect(0, 0, WIDTH, HEIGHT); for (let i = 0; i < 100; i++) { . ctx.beginPath(); .

  7. Mar 31, 2024 · Use return to specify the value that the function should produce as a final result. When the interpreter reaches a return statement, the function that contains that statement immediately ends, and the specified value is returned to the context where the function was called: const myFunction = function() { return 2 + 2; } myFunction(); > 4.

  8. Mar 31, 2021 · The return keyword in JavaScript is a keyword to build a statement that ends JavaScript code execution. For example, suppose you have the following code that runs two console logs: console.log("Hello"); return; console.log("How are you?");

  9. You can use a return statement to send a value back out of a function. Example. function plusThree(num) { return num + 3; } const answer = plusThree(5); answer has the value 8. plusThree takes an argument for num and returns a value equal to num + 3.

  10. Simply put, the return keyword is used to exit a function and hand back a value to the place where the function was invoked. This feature is not just a convenience but a powerful tool for controlling the flow of data through your code. When to Use return in JavaScript. "Wann benutzt man return?"