Console API - Web APIs 编辑

The Console API provides functionality to allow developers to perform debugging tasks, such as logging messages or the values of variables at set points in your code, or timing how long an operation takes to complete.

Note:

This feature is available in Web Workers.

Concepts and usage

The Console API started as a largely proprietary API, with different browsers implementing it, albeit it in inconsistent ways. The Console API spec was created to define consistent behavior, and all modern browsers eventually settled on implementing this behavior — although some implementations still have their own additional proprietary functions. Find out about these at:

Usage is very simple — the console object — available via window.console, or WorkerGlobalScope.console in workers; accessible using just console — contains many methods that you can call to perform rudimentary debugging tasks, generally focused around logging various values to the browser's Web Console.

By far the most commonly-used method is console.log, which is used to log the current value contained inside a specific variable.

Interfaces

console
Provides rudimentary debugging functionality, including logging, stack traces, timers, and counters.

Examples

let myString = 'Hello world';

// Output "Hello world" to the console
console.log(myString)

See the Console reference page for more examples.

Specifications

SpecificationStatusComment
Console APILiving StandardInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

  • Tools
  • Web Console — how the Web Console in Firefox handles console API calls
  • Remote debugging — how to see console output when the debugging target is a mobile device

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:132 次

字数:3832

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文