1. Strict mode import
Importing node:assert/strict makes every method use strict (===) comparison by default.
import assert from "node:assert/strict";Typorithm · easy
Step 1 of 8 · intro card
Testing & Debug
node:assert provides strictEqual, deepStrictEqual, throws, rejects, and match. Import node:assert/strict so every method uses strict (===) comparison. Assertions throw an AssertionError on failure, and the strict variants are preferred over the loose ones.
node:assert ships strictEqual and deepStrictEqual for value and deep structural checks, throws and rejects for error expectations, and match for regex checks.
Importing from node:assert/strict (or using the strict variants directly) makes comparisons use === — the loose equal/deepEqual methods coerce and should be avoided.
Every assertion throws an AssertionError when it fails; throws checks a synchronous throw while rejects (awaited) checks a rejected promise.
strictEqual / deepStrictEqual / throws / rejects / match.
node:assert/strict makes everything strict (===).
Failures throw AssertionError; prefer strict over loose.
import assert from "node:assert/strict";
assert.strictEqual(1 + 1, 2);
assert.deepStrictEqual({ a: 1 }, { a: 1 });
assert.throws(() => JSON.parse("{"), SyntaxError);
await assert.rejects(Promise.reject(new Error("x")));
assert.match("hello", /ell/);Connect each part of the code to the concept before you type.
Importing node:assert/strict makes every method use strict (===) comparison by default.
import assert from "node:assert/strict";strictEqual compares with === and throws AssertionError if the values differ.
assert.strictEqual(1 + 1, 2);deepStrictEqual recursively compares structure and values using strict equality.
assert.deepStrictEqual({ a: 1 }, { a: 1 });throws asserts the function throws, optionally matching the expected error type.
assert.throws(() => JSON.parse("{"), SyntaxError);rejects is the async counterpart: await it to assert a promise rejects.
await assert.rejects(Promise.reject(new Error("x")));match asserts that a string matches the given regular expression.
assert.match("hello", /ell/);Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.