HTML DOM console.error() method

WBOY
Release: 2023-09-12 14:01:01
forward
1421 people have browsed it

HTML DOM The console.error() method is used to write error messages to the console. This method is great for testing and debugging.

Syntax

The syntax of the console.error() method is as follows:

console.error(console.error(message))
Copy after login

Here, message is a JavaScript string or object. It is a required parameter value.

Example

Let’s see an example about the HTML DOM console.error() method −

<!DOCTYPE html>
<html>
<body>
<h1>console.error() Method</h1>
<p>Click the below button to write object as error message on the console</p>
<button type="button" onclick="errMessage()">ERROR</button>
<script>
   function errMessage(){
      var errObj = { Message:"ERROR has been caused",Value:"NEGATIVE"};
      console.error(errObj);
   }
</script>
<p>Press F12 key to view the error message in the console </p>
</body>
</html>
Copy after login

Output

This will produce the following output−

HTML DOM console.error() 方法

Click the ERROR button and view the Console tab in Developer Tools−

HTML DOM console.error() 方法

In the example above−

We first created a button named ERROR. When the user clicks, the errMessage() function will be executed −

<button type="button" onclick="errMessage()">ERROR</button>
Copy after login

The errMessage() method creates a button with members Message and objects of Value and their respective values. This object is then passed as a parameter to the error() method of the console object. The console's console.error() method prints the object as an error message to the console −

function errMessage(){
   var errObj = { Message:"ERROR has been caused",Value:"NEGATIVE"};
   console.error(errObj);
}
Copy after login

The above is the detailed content of HTML DOM console.error() method. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template