From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../javascript/reference/operators/void/index.html | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 files/ko/web/javascript/reference/operators/void/index.html (limited to 'files/ko/web/javascript/reference/operators/void') diff --git a/files/ko/web/javascript/reference/operators/void/index.html b/files/ko/web/javascript/reference/operators/void/index.html new file mode 100644 index 0000000000..79fe2c1837 --- /dev/null +++ b/files/ko/web/javascript/reference/operators/void/index.html @@ -0,0 +1,122 @@ +--- +title: void +slug: Web/JavaScript/Reference/Operators/void +tags: + - JavaScript + - Operator + - Reference + - Unary +translation_of: Web/JavaScript/Reference/Operators/void +--- +
{{jsSidebar("Operators")}}
+ +

void 연산자는 주어진 표현식을 평가하고 {{jsxref("undefined")}}를 반환합니다.

+ +
{{EmbedInteractiveExample("pages/js/expressions-voidoperator.html")}}
+ + + +

구문

+ +
void expression
+ +

설명

+ +

void는 값을 생성하는 표현식을 평가해서 {{jsxref("undefined")}}를 반환합니다.

+ +

오직 undefined 원시값을 얻기 위해 void 0 또는 void(0)처럼 사용하는 경우도 볼 수 있습니다. 이런 경우 전역 {{jsxref("undefined")}}를 대신 사용해도 됩니다.

+ +

void 연산자의 우선순위도 유념해야 합니다. 그룹 연산자(괄호)를 사용하면 void 연산자를 사용한 식의 평가 과정을 더 명확하게 보일 수 있습니다.

+ +
void 2 == '2'; // undefined == '2', false
+void (2 == '2'); // void true, undefined
+
+ +

IIFE

+ +

즉시 실행 함수 표현식({{Glossary("IIFE")}})을 사용할 때 void를 사용하면 function 키워드를 선언문이 아니라 표현식처럼 간주하도록 강제할 수 있습니다.

+ +
void function iife() {
+    var bar = function () {};
+    var baz = function () {};
+    var foo = function () {
+        bar();
+        baz();
+     };
+    var biz = function () {};
+
+    foo();
+    biz();
+}();
+
+ +

JavaScript URI

+ +

javascript:로 시작하는 URI를 지원하는 브라우저에서는, URI에 있는 코드의 평가 결과가 {{jsxref("undefined")}}가 아니라면 페이지의 콘텐츠를 반환 값으로 대체합니다. void 연산자를 사용하면 undefined를 반환할 수 있습니다. 다음 예제를 확인하세요.

+ +
<a href="javascript:void(0);">
+  클릭해도 아무 일도 없음
+</a>
+<a href="javascript:void(document.body.style.backgroundColor='green');">
+  클릭하면 배경색이 녹색으로
+</a>
+
+ +
+

참고: javascript: 의사 프로토콜보다 이벤트 처리기와 같은 대체재 사용을 권장합니다.

+
+ +

새지 않는 화살표 함수

+ +

Arrow functions introduce a short-hand braceless syntax that returns an expression. This can cause unintended side effects by returning the result of a function call that previously returned nothing. To be safe, when the return value of a function is not intended to be used, it can be passed to the void operator to ensure that (for example) changing APIs do not cause arrow functions' behaviors to change.

+ +
button.onclick = () => void doSomething();
+ +

This ensures the return value of doSomething changing from undefined to true will not change the behavior of this code.

+ +

명세

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ESDraft', '#sec-void-operator', 'The void Operator')}}{{Spec2('ESDraft')}} 
{{SpecName('ES6', '#sec-void-operator', 'The void Operator')}}{{Spec2('ES6')}} 
{{SpecName('ES5.1', '#sec-11.4.2', 'The void Operator')}}{{Spec2('ES5.1')}} 
{{SpecName('ES3', '#sec-11.4.2', 'The void Operator')}}{{Spec2('ES3')}} 
{{SpecName('ES1', '#sec-11.4.2', 'The void Operator')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.1
+ +

브라우저 호환성

+ +

{{Compat("javascript.operators.void")}}

+ +

같이 보기

+ + -- cgit v1.2.3-54-g00ecf