@composi/are-equal
A function that test the provided values to see if they are equal. If the values are primitive types the comparison is the same as using ===
. For complex types, such as arrays and objects, it also makes the comparison by value instead of by reference. By default JavaScript compares objects by reference. areEqual
lets you compare them by value.
Install
npm install --save-dev @composi/uuid
Using
You compare primitive types or complex types:
let num1 = 1
let num2 = 1
areEqual(num1, num2)
let str1 = 'Some text'
let str2 = 'Some text'
areEqual(str1, str2)
let bool1 = true
let bool2 = true
areEqual(bool1, bool2)
let nullVal = null
let undefinedVal
areEqual(nullVal, undefinedVal)
areEqual(0/0, NaN)
You can compare arrays to see if they hold the same values:
const array1 = [1, 2, 3]
const array2 = [1, 2, 3]
array1 === array2
areEqual(array1, array2)
You can compare objects to see if their properties and values are equal:
const obj1 = {name: 'Joe'}
const obj2 = {name: 'Joe'}
obj1 === obj2
obj1 == obj2
areEqual(obj1, obj2)