What is value-equal?
The value-equal npm package is a simple utility for checking the equality of two values. It is primarily used to determine if two values are equivalent in terms of their actual content, rather than being the same reference. This is particularly useful in scenarios where deep comparison of objects, arrays, or other complex data structures is required.
What are value-equal's main functionalities?
Deep Equality Check
This feature allows you to check if two values are equivalent, looking deeply into the structure of objects or arrays. It returns true if the values are equivalent, otherwise false.
const valueEqual = require('value-equal');
console.log(valueEqual({ a: 1 }, { a: 1 })); // true
console.log(valueEqual([1, 2], [1, 2])); // true
console.log(valueEqual('hello', 'hello')); // true
console.log(valueEqual(42, 42)); // true
console.log(valueEqual(null, null)); // true
console.log(valueEqual(undefined, undefined)); // true
console.log(valueEqual({ a: 1 }, { a: 2 })); // false
Other packages similar to value-equal
deep-equal
deep-equal is another npm package that provides deep comparison functionality. It is similar to value-equal but offers more detailed options for comparison, such as strict mode checks and handling of prototype properties.
lodash.isequal
lodash.isequal is a method from the popular Lodash library that performs a deep comparison between two values to determine if they are equivalent. It supports a wider range of data types and has optimizations for large datasets, making it more versatile than value-equal.
value-equal

value-equal
determines if two JavaScript values are equal using Object.prototype.valueOf
.
In many instances when I'm checking for object equality, what I really want to know is if their values are equal. This is good for:
- Stuff you keep in
localStorage
window.history.state
values- Query strings
Installation
Using npm:
$ npm install --save value-equal
Then with a module bundler like webpack, use as you would anything else:
import valueEqual from 'value-equal';
var valueEqual = require('value-equal');
The UMD build is also available on unpkg:
<script src="https://unpkg.com/value-equal"></script>
You can find the library on window.valueEqual
.
Usage
valueEqual(1, 1);
valueEqual('asdf', 'asdf');
valueEqual('asdf', new String('asdf'));
valueEqual(true, true);
valueEqual(true, false);
valueEqual({ a: 'a' }, { a: 'a' });
valueEqual({ a: 'a' }, { a: 'b' });
valueEqual([1, 2, 3], [1, 2, 3]);
valueEqual([1, 2, 3], [2, 3, 4]);
That's it. Enjoy!