[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/return [Back]  [Original]

return - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

return

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

return , .

In this article

function getRectArea(width, height) {
  if (width > 0 && height > 0) {
    return width * height;
  }
  return 0;
}

console.log(getRectArea(3, 4));
// Expected output: 12

console.log(getRectArea(-3, 4));
// Expected output: 0

js
return [[expression]];
expression

. undefined .

return . . , x .

js
function square(x) {
  return x * x;
}
var demo = square(3);
// demo 9

undefined .

return .

js
return;
return true;
return false;
return x;
return x + y / 3;

return (ASI) . return .

js
return
a + b;

ASI .

js
return;
a + b;

"unreachable code after return statement" .

ASI .

js
return a + b;

return .

js
function counter() {
  for (var count = 1; ; count++) {
    //  
    console.log(count + "A"); // 5
    if (count === 5) {
      return;
    }
    console.log(count + "B"); // 4
  }
  console.log(count + "C"); //   
}

counter();

// :
// 1A
// 1B
// 2A
// 2B
// 3A
// 3B
// 4A
// 4B
// 5A

.

js
function magic(x) {
  return function calc(x) {
    return x * 42;
  };
}

var answer = magic();
answer(1337); // 56154

Specification
ECMAScript 2027 LanguageSpecification
# sec-return-statement


Web Proxy Viewer  |  New URL  |  Original Page