11장

     

     

    1분 퀴즈

    1.

    해설_ 변수 studentObject의 초깃값으로 할당된 객체의 키는 nameage입니다. 여기에 gender 속성을 동적으로 추가하고, 이후 age 속성을 동적으로 제거하므로 변수 studentObject에는 최종으로 namegender만 남게 됩니다.

    본문으로

     

    2.

    const arr = [10, 120, 30, 50, 20];
    arr.sort(function(a, b){
      if(a < b) return 1; 
      else if(a > b) return -1;
      else return 0;
    })
    console.log(arr[0]);

    해설_ 해당 코드는 여러 방법으로 작성할 수 있습니다. 여기서는 표준 내장 객체인 Arraysort() 메서드를 사용해 배열의 요소를 내림차순으로 정렬한 뒤 첫 번째 인덱스의 요소를 출력하게 했습니다.

    본문으로

     

    3.

    해설_ 웹 브라우저의 스크롤을 호출할 때마다 이동하게 하려면 window 객체의 scrollBy() 메서드를 사용해야 합니다.

    본문으로

     

     

    셀프체크

    1.

    해설_ 다른 선택지는 name 속성만 남지만, ③은 delete 키워드로 name 속성을 삭제하므로 age 속성만 남습니다.

     

    2.

    <body>
      <button onclick="popup()">팝업</button>
      <script>
        function popup(){
          const left = (screen.availWidth - 500) / 2 + window.screenX;
          const top = (screen.availHeight - 300) / 2;
          window.open('https://google.com', 'popup', 'width=500, height=300, left=' + left + ', top=' + top);
          console.log(window.screenX);
        }
      </script>
    </body>

    본문으로

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.