在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
简介Almost all web browsers and JavaScript environments support writing messages to a console using a suite of logging methods. The most common of these is the `console.log()` method. 起步Open up the JavaScript Console in your browser, type the following, and press Enter:
In the example above, the console.log() function prints Hello, World! to the console, along with a new line, and returns undefined (shown above in the console output window), because it has no explicit return value. The console.log() function is predominantly used for debugging purposes. 输出变量console.log() can be used to log variables of any kind, not only strings. Just pass the variable that you want to be displayed in the console, for example:
Will log in the console…
If you want to log two or more values, simply separate them with commas:
输出对象Below depicts the result of logging an object, which can be useful, for example, to log JSON responses received from an API call:
Will log in the console…
输出函数The console can also be used to show the return value of a function. In the example below, isNaN() will be executed and the value returned by this function will be shown in the console;
console.log also has the ability to display function definitions by passing a non invoked instance of the function.
Will log to the console…
输出HTML元素You have the ability to log any element which exists within the DOM. In this case we log the body element;
Will log to the console…
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13