[Javascript] Proper use of console.assert in JavaScript

时间:2023-03-08 16:28:14

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");

[Javascript] Proper use of console.assert in JavaScript

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