The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Proper use of console.assert in JavaScript

Proper use of console.assert in JavaScript

3:06
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.
Watch this lesson now
Avatar
egghead.io

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.

Avatar
Nishchal Gautam

BTW, console.assert is very useful if you're doing a quick TDD when you're writing on JSBIN or something like that. So you might want to do something like:

myFn(){

}
console.assert(myFn(3) === 3);
console.assert(myFn(6) === 3);
console.info("All tests passed");

then implement the function so that there are no errors in console and then finally delete the console calls.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?