assert Module
assert checks conditions and throws AssertionError when they fail.
Example
const assert = require("assert");
assert.strictEqual(2 + 2, 4);
assert.deepStrictEqual({ a: [1] }, { a: [1] });
try { assert.strictEqual(1, 2); } catch (e) { console.log(e.name); }
assert.throws(() => { throw new Error("x"); });
console.log("all good");Result
AssertionError all good
Exercise
Deep compare.
assert.StrictEqual(a, b)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.