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. Feb 12, 2024 · Syntax: return value; Example: Here, the add function takes two parameters a and b, and returns their sum using the return keyword. When add(3, 5) is called, the function calculates the sum of 3 and 5, and returns 8, which is then stored in the result variable. Finally, console.log(result) prints 8 to the console. Javascript. Output. 8.

  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. 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(); .

  9. 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?");

  10. The return keyword in JavaScript is a cornerstone of function definition, allowing you to control the output and flow of your code effectively. By understanding and implementing return correctly, you can create more efficient and readable programs.