• 회원가입
  • 로그인
  • 구글아이디로 로그인

[Window_Console] JS - console.assert() 메서드 - 표현식이 FALSE인지 확인 (= 표현식 거짓 여부 체크 = console.assert메서드 = 콘솔어서트 메서드)

목차
  1. console.assert() 예제 - 표현식이 false인지 확인
  2. console.assert() 정의
  3. console.assert() 구문
  4. console.assert() 예제 - message 매개변수에 객체 입력
  5. console.assert() 예제 - message 매개변수에 배열 입력

 

console.assert() 예제 - 표현식이 false인지 확인

 

<script>

console.assert(document.getElementById("homzzang"), "id='homzzang' 없음");

</script>

 

※ id="homzzang" 요소가 없는 상태 (= 즉, 거짓상태 = FALSE 상태)이면, id='homzzang' 없음 메시지 띄우기.

 

console.assert() 정의

 

표현식이 'FALSE'일 때만 콘솔에 메시지 작성.

 


 
1.
크롬 접속 > F12키 > SCRIPT실행 > console 탭에서 메세지 확인

 

2.

모든 브라우저 지원.

 

 

console.assert() 구문

 

console.assert(expression, message)

 


[매개변수]


expression
필수. 참거짓 판명할 표현식.


message
필수. 표현식이 거짓인 경우 띄울 메세지.

※ 문자열, 객체나 배열 등 입력 가능.

 

 

console.assert() 예제 - message 매개변수에 객체 입력

 

<script>

var hz = { site : "홈짱닷컴", domain : "Homzzang.com" };

console.assert(document.getElementById("homzzang"), hz);

</script>

 

 

console.assert() 예제 - message 매개변수에 배열 입력

 

<script>

var hz = ["홈짱닷컴", "Homzzang.com"];

console.assert(document.getElementById("homzzang.com"), hz);

</script>

 

 


분류 제목
Basic JS - Let 키워드 ★★★★★ - 변수 블럭범위 설정 (렛키워드) ※ 클로저
Modernizr JS - Modernizr (모더나이저 = 마더나이저) - 크로스브라우징 구현 (= 브라우저의 HTML5 C…
React JS - React (리액트) - JS 라이브러리 일종으로 사용자 인터페이스 구축에 사용.(= 현재시간 = …
DOM_Attribute JS - Attribute 객체 - 속성객체
Window_Console JS - window.console 객체 - 콘솔객체
DOM_Document JS - Document 객체 - 웹문서 객체의 속성/메서드 종류 (= document객체 = 다큐먼트객체)
DOM_Element JS - Element 객체 - 요소객체 (속성 + 메서드) 종류
DOM_Event JS - Event 종류 ★ - 이벤트부착 / 이벤트종류 / 이벤트속성 / 이벤트메서드
API_Geolocation JS - Geolocation - 지리위치객체종류
Window_History JS - window.history 객체 정의 + 히스토리 객체의 (속성/메서드) 종류
DOM_HTMLCollection JS - HTMLCollection 객체 (속성 + 메서드) 종류
Window_Location JS - window.location 객체 - 위치 객체 (= window.location객체 = 윈도우로케…
Window_Navigator JS - window.navigator 객체 - 네비게이터 객체 (= window.navigator객체 = …
Window_Screen JS - window.screen 객체 - 스크린 객체 (= window.screen객체 = 윈도우스크린객체…
DOM_Style JS - CSS 스타일 속성값 반환 ★★ + style 객체의 속성 종류
Window_Object JS - window 객체 - 윈도우객체 (속성/메서드) 종류
API_Storage JS - Storage Object - 스토리지 객체 (※ 데이터 저장소)
Object JS - Object Constructor - 객체생성자종류 ★
Object JS - Object Prototypes - 객체프로토타입 (= 객체원형) ★
Object JS - object ECMAScript 5 - 객체혁명
22/67
목록
찾아주셔서 감사합니다. Since 2012