代码示例:(标识:jsck_console_assert_1)
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript console.assert() 方法</h1>

<p>按键盘上的 F12 可在控制台视图中查看消息。</p>

<script>

console.assert(document.getElementById("demo"), "You have no element with ID 'demo'");

</script>

</body>
</html>
运行结果: