首页 > 编程语言 > 详细

[Javascript] Proper use of console.assert in JavaScript

时间:2016-05-16 16:58:46      阅读:221      评论:0      收藏:0      [点我收藏+]

Learn about console.assert, which is syntactic sugar for logging an error the console when a given condition is not met. It‘s useful, but may not do what you expect if you‘re coming from another language - watch this lesson to learn how to use it, and when not to.

 

var foo = undefined;

if(!foo){
    console.log("Foo is undefined");
}

// The same as

var foo = undefined;

console.assert(foo, "Foo is falsy value");

 

技术分享

 

But notice, assert just log out the error message in the console, but it doesn‘t help to handle the error.

 

[Javascript] Proper use of console.assert in JavaScript

原文:http://www.cnblogs.com/Answer1215/p/5498259.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!