English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM console.assert() 메서드

 JavaScript Console 객체

assert가 false일 경우console.assert()메서드는 오류 메시지를 콘솔에 기록합니다.

assert가 true일 경우, 어떤 일도 일어나지 않습니다.

문법:

console.assert(assertion, message)
console.assert(document.getElementById("result"), "ID가 없는 요소'result'
테스트 보기‹/›

브라우저 호환성

모든 브라우저는 console.assert() 메서드를 완전히 지원합니다:

Method
console.assert()

매개변수 값

매개변수설명
assertion모든 부울 표현식. 만약assertfalse라면 메시지를 콘솔에 기록합니다
message콘솔에 기록할 문자열이나 객체

更多示例

이 예제는 문자열을 콘솔에 기록합니다:

console.assert(false, "Hello world!!!");
테스트 보기‹/›

이 예제는 객체를 콘솔에 기록합니다:

var myObj = { str: "Some text", id: 12 };
console.assert(document.getElementById("result"), myObj);
테스트 보기‹/›

이 예제는 배열을 콘솔에 기록합니다:

var arr = ["Item1", "Item2", "Item3", "Item4"];
console.assert(document.getElementById("result"), arr);
테스트 보기‹/›

 JavaScript Console 객체