Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript return

/* The return statement ends a function immediately at the 
point where it is called. */

function counter() {
  for (var count = 1; count < 5 ; count++) {
    console.log(count + 'A');
    if (count === 3) return; // ends entire counter function
    console.log(count + 'B');
    }
  console.log(count + 'C'); // never appears
}

counter();
// 1A
// 1B
// 2A
// 2B
// 3A
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #javascript #return
ADD COMMENT
Topic
Name
7+7 =