HTML JS

HOW TO SHOW ERROR MESSAGES IN JAVASCRIPT

1) CONSOLE

Javascript errors will show in the developer's console by default. Press F12 > Console in most major browsers to bring it up.

console.log("MESSAGE"); console.error("MESSAGE");

2) ALERT

try { doesNotExist(); } catch (err) { alert(err); }

3) HTML

<div id="err"></div>

try { doesNotExist(); } catch (err) {   let notify = document.     getElementById("err");   notify.innerHTML = err;     notify.style.display = "block"; }