There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Thanks, it would have thought it needed the .push() method to add it into the sum object, but I must be confusing it with an array. Seems to work just fine like this.
Just for fun, I tried another one:
describe('+', () => {
it('returns the sum of two values', () => {
// Setup
let expected = {a: 3, b: 4, result: 7, substract: -1};
let sum = {a: 3, b: 4};
// Exercise
sum.result = sum.a + sum.b;
sum.substract = sum.a - sum.b;
// Verify
assert.deepEqual(sum, expected);
});
});
Test passed: indeed, properties can be added to objects seamlessly using this method.
using .equal to compare strings and so forth is fine. But won’t work for objects. Which is why we use deepEqual, which very likely uses a loop to compare all the items within the object
Sorry I’m late to the party. This goes back to the reference over value section we had gone over. Objects are referenced by location. So with both objects having the same key value pairs they are considered different in nature. It still seems weird, but the deep equal does go deep into the object itself to extract the actual value to compare against. Whereas the .equal and .strictEqual are comparing the object, it will always return Falsey because they are different objects within memory.