Take a look at the code below. Will these assertions throw errors?

const a = 3; const b = '3'; assert.ok(a == b); assert.ok(a === b);
  • The first assertion will not throw an error because it uses loose (==) equality. It performs a type conversion when comparing two things.
  • The second will throw an error because it uses strict (===) equality. It returns false if the types differ.

If you need to be strict in evaluating equality, you can use assert.strictEqual().

  • assert.equal() performs a == comparison
  • assert.strictEqual() performs a === comparison

Compare the following code to the first example. This code performs the same verifications, but it is more expressive. Without parsing any logic, a reader would know the intention of your tests by reading the method names.

const a = 3; const b = '3'; assert.equal(a, b); assert.strictEqual(a, b);

July 2021 Update: the assert documentation recommends always using assert.strictEqual() instead of assert.equal().



Set expected to the string '96' and run the test suite. The test still passes!


Replace assert.equal() with assert.strictEqual()


Run the test suite in the command line. The test fails!


Reset expected to 96 so that assert.strictEqual() does not return an error.


Run the test suite.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?