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.
时间: 2024-11-13 08:21:14