Home > Article > Web Front-end > How to output JavaScript to the console
Output method: 1. Use the "console.log (information)" statement to output information; 2. Use the "console.info (information)" statement to output information; 3. Use "console.warn (warning)" The statement outputs warning information; 4. Use the "console.error(information)" statement.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, you can use the methods of the Console object to output from the console.
Two common uses of the Console object:
Display error information when the web page code is running.
Provides a command line interface for interacting with web page code.
Method | Description | Instance |
---|---|---|
error( ) | When outputting information, add a red cross at the front to indicate an error, and the stack where the error occurred will be displayed. | console.error("Error: %s (%i)", "Server is not responding",500) |
info() | console.log alias, output information | console.info("php中文网") |
log() | Output information | console.log("php中文网") |
warn() | Output warning information | console.warn("警告") |
Taking the Chrome browser as an example, we can open the Console window by pressing F12 or Control Shift i (PC platform) / Alt Command i (Mac platform) .
[Related recommendations: javascript learning tutorial]
The above is the detailed content of How to output JavaScript to the console. For more information, please follow other related articles on the PHP Chinese website!