为什么 console.log() 被认为比 alert() 更好? [英] Why is console.log() considered better than alert()?

查看:25
本文介绍了为什么 console.log() 被认为比 alert() 更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直被告知在调试应用程序时,JavaScript 的 console.log() 方法优于简单地使用 alert() 方法.为什么是这样?有没有一个很好的例子,有人可以向我指出 console.log() 显然是更好的选择?

I've always been told that when debugging an application, JavaScript's console.log() method is preferred over simply using an alert() method. Why is this? Is there a good example someone can point me to where console.log() is obviously the better choice?

推荐答案

  • alert() 正在阻塞
  • alert() 在非调试环境中不容易被抑制
  • console 通常很好地格式化您的对象并允许遍历它们
  • 日志语句通常有一个交互式指针,指向发出日志语句的代码
  • 您不能一次查看多个 alert() 消息
  • consoles 可以有不同的日志级别和直观的格式
    • alert() is blocking
    • alert() cannot be easily suppressed in non-debug environment
    • console typically formats your objects nicely and allows to traverse them
    • logging statements often have an interactive pointer to code which issued logging statement
    • you cannot look at more than one alert() message at a time
    • consoles can have different logging levels with intuitive formatting
    • 这篇关于为什么 console.log() 被认为比 alert() 更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆