Node.jsQuestion 09 of 26
Assertions
Answer out loud or in your head first, then compare.
Answer
An assertion checks that an assumption holds. A failed assertion throws an error, which makes it useful in tests and for checking invariants.
JavaScript
import assert from 'node:assert/strict';
assert.equal(2 + 2, 4);
assert.deepEqual({ role: 'user' }, { role: 'user' });equal checks values for equality under strict rules, and deepEqual compares nested structures in the strict mode shown.
Pitfall: an assertion doesn't replace proper validation of user data. Bad input should usually produce a controlled message and API status.
How did it go? Be honest — “Not yet” puts the question on your review list.