Bryan's article describes Value Objects as "simple objects whose equality is dependent on their value rather than an identity."
// Primitives var foo = 2; var bar = 2; foo === bar; // => true // Object identity var foo = new Number(2); var bar = new Number(2); foo === bar; // => false
The first example assigns primitive integers to the variables
foo does not equal
bar, even though both
Number instances represent the same integer value.
But Value Objects offer a great place for domain logic to reside. Almost every value type in your application has logic associated with it, such as equality, and the best place for that logic is in a value object.Read More