Code Monkey home page Code Monkey logo

are-equal's Introduction

@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) // returns true

let str1 = 'Some text'
let str2 = 'Some text'
areEqual(str1, str2) // returns true

let bool1 = true
let bool2 = true
areEqual(bool1, bool2) // returns true

let nullVal = null
let undefinedVal
areEqual(nullVal, undefinedVal) // returns false

areEqual(0/0, NaN) // returns true

You can compare arrays to see if they hold the same values:

// 
const array1 = [1, 2, 3]
const array2 = [1, 2, 3]
array1 === array2 // returns false because they are by reference.
areEqual(array1, array2) // returns true because this is by value.

You can compare objects to see if their properties and values are equal:

const obj1 = {name: 'Joe'}
const obj2 = {name: 'Joe'}

obj1 === obj2 // returns false
obj1 == obj2 // returns false
areEqual(obj1, obj2) // returns true

are-equal's People

Contributors

dependabot[bot] avatar rbiggs avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.