Check if two unknown values are strictly equal.

If the values are arrays, then each element is compared, regardless of order. If the values are objects, then each key and value from left is compared to the corresponding key and value from right. If the values are primitives, then they are compared using strict equality.

import { isStrictEqual } from '@aws-lambda-powertools/commons/typeUtils';

const left = { key: 'value' };
const right = { key: 'value' };
const equal = isStrictEqual(left, right); // true

const otherLeft = [1, 2, 3];
const otherRight = [3, 2, 1];
const otherEqual = isStrictEqual(otherLeft, otherRight); // true

const anotherLeft = 'foo';
const anotherRight = 'bar';
const anotherEqual = isStrictEqual(anotherLeft, anotherRight); // false

const yetAnotherLeft = 42;
const yetAnotherRight = 42;
const yetAnotherEqual = isStrictEqual(yetAnotherLeft, yetAnotherRight); // true
  • Parameters

    • left: unknown

      Left side of strict equality comparison

    • right: unknown

      Right side of strict equality comparison

    Returns boolean