| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/return | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.
return , .
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
return [[expression]];
expression . undefined .
return . . , x .
function square(x) {
return x * x;
}
var demo = square(3);
// demo 9
undefined .
return .
return;
return true;
return false;
return x;
return x + y / 3;
return (ASI) . return .
return
a + b;
ASI .
return;
a + b;
"unreachable code after return statement" .
ASI .
return a + b;
return .
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
function magic(x) {
return function calc(x) {
return x * 42;
};
}
var answer = magic();
answer(1337); // 56154
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-return-statement |
This page was last modified on 2025 6 27 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |