GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing ko.javascript.info — AND 연산자의 피연산자가 alert 라면?

  • 튜토리얼
  • 코어 자바스크립트
  • 자바스크립트 기본
  • 논리 연산자
돌아가기

AND 연산자의 피연산자가 alert 라면?

중요도: 3

아래 코드의 결과를 예측해 보세요.

alert( alert(1) && alert(2) );

얼럿 창엔 1, undefined가 차례대로 출력됩니다.

alert( alert(1) && alert(2) );

alert를 호출하면 undefined가 반환됩니다. alert는 단순히 얼럿 창에 메시지만 띄워주고, 의미 있는 값을 반환해 주지 않습니다.

&&는 왼쪽 피연산자를 평가하고(이때 1이 얼럿 창에 출력됩니다) 평가를 즉시 멈춥니다. alert(1)의 평가 결과는 undefined로 falsy이기 때문이죠. && 연산자는 falsy를 만나면 그 값을 출력하고 즉시 연산을 멈춥니다.

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.