Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Thuộc tính message của Error trong JavaScript

Thuộc tính message của Error dùng để đặt hoặc lấy thông điệp lỗi trong JavaScript.

Ví dụ

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style>    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;    } </style> </head> <body> <h1>Thuộc tính message của Error</h1> <div class="sample"></div> <button class="Btn">NHẤN VÀO ĐÂY</button> <h3> Nhấn nút để xem thông điệp lỗi </h3> <script>    let sampleEle = document.querySelector(".sample");    document.querySelector(".Btn").addEventListener("click", () => {       try {          confrm('Are you sure'); // lỗi chính tả hàm       } catch (e) {          sampleEle.innerHTML = "Lỗi: " + e.message;       }    }); </script> </body> </html>

Kết quả

Hiển thị: Lỗi: confrm is not defined.