Movatterモバイル変換


[0]ホーム

URL:


  1. 개발자를 위한 웹 기술
  2. JavaScript
  3. JavaScript 참고서
  4. 식 및 연산자
  5. void

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

View in EnglishAlways switch to English

void

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015년 7월⁩.

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

시도해 보기

const output = void 1;console.log(output);// Expected output: undefinedvoid console.log("expression evaluated");// Expected output: "expression evaluated"void (function iife() {  console.log("iife is executed");})();// Expected output: "iife is executed"void function test() {  console.log("test function executed");};try {  test();} catch (e) {  console.log("test function is not defined");  // Expected output: "test function is not defined"}

구문

js
void expression;

설명

void는 값을 생성하는 표현식을 평가해서undefined를 반환합니다.

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

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

js
void 2 == "2"; // undefined == '2', falsevoid (2 == "2"); // void true, undefined

IIFE

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

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

JavaScript URI

#"/ko/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined가 아니라면 페이지의 콘텐츠를 반환 값으로 대체합니다.void 연산자를 사용하면undefined를 반환할 수 있습니다. 다음 예제를 확인하세요.

html
<a href="#">클릭해도 아무 일도 없음</a><a href="#">  클릭하면 배경색이 녹색으로</a>

참고:#"새지_않는_화살표_함수" >

새지 않는 화살표 함수

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.

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

This ensures the return value ofdoSomething changing fromundefined totrue will not change the behavior of this code.

명세서

Specification
ECMAScript® 2026 Language Specification
# sec-void-operator

브라우저 호환성

같이 보기

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp