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

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

问题描述

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

解决方案


  • alert()正在阻止

  • alert()不能在非调试环境中轻松抑制

  • 控制台通常格式化对象很好,并允许遍历他们

  • 日志记录通常有一个交互式指针,代码发出日志记录

  • 你不能看多个 alert()一次消息

  • 控制台可以具有不同的日志记录级别直观格式化


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() 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天全站免登陆