
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM console.log() Method
The HTML DOM console.log() method is used for writing a message to the console. The console is used for debugging and testing purposes mainly. The message can be a string type or an object type.
Syntax
Following is the syntax for the console.log method −
onsole.log(msg)
Here, msg can be a string, array or object. We can send multiple comma separated objects as parameter too.
Example
Let us look at an example for the console.log() method −
<!DOCTYPE html> <html> <body> <h1>JavaScript console.log() Method</h1> <p>Press F12 key to view the message in the console view.</p> <button type="button" onclick="logConsole()">LOG</button> <script> function logConsole(){ console.log("Following are some animal names"); var Arr1 = ["dog", "cat", "monkey", "lion" ]; console.log(Arr1); } </script> </body> </html>
Output
This will produce the following output −
On clicking LOG button and viewing the console −
In the above example −
We have first created a button LOG that will execute the logConsole() function upon being clicked by the user −
<button type="button" onclick="logConsole()">LOG</button>
The logConsole() function has the console.log() method inside it. We have first passed a simple string as a parameter to the console.log() method. Then we have passed an array of length 4 to the console.log(). It will print both the messages in the order they are in the document −
function logConsole(){ console.log("Following are some animal names"); var Arr1 = ["dog", "cat", "monkey", "lion" ]; console.log(Arr1); }
- Related Articles
- HTML DOM write() Method
- HTML DOM writeln() Method
- HTML DOM normalize( ) Method
- HTML DOM addEventListener() Method
- HTML DOM appendChild() Method
- HTML DOM blur() Method
- HTML DOM click() method
- HTML DOM cloneNode() method
- HTML DOM close() method
- HTML DOM compareDocumentPosition() Method
- HTML DOM console.assert() Method
- HTML DOM console.clear() Method
- HTML DOM console.count() Method
- HTML DOM console.error() Method
- HTML DOM console.group() Method
- HTML DOM console.groupCollapsed() Method
