So the challenge itself is not that hard and I am able to pass it,
but (and here comes the potential spoiler):
apparently { value : 1 } == { value : 1 } is false?
Why is that?
Link to the challenge:
So the challenge itself is not that hard and I am able to pass it,
but (and here comes the potential spoiler):
apparently { value : 1 } == { value : 1 } is false?
Why is that?
Link to the challenge:
Hello,
β==β makes a loose equality check while β===β makes a strict equality check.
Here is an article about the differences between the two:
Hello there,
This is a common pitfall developers find, especially when working with a high-level language like JavaScript.
It all boils down to the references of the object literals:
const objectA = { value: 1 };
const objectB = { value: 1 };
console.log(objectA === objectA); // returns true - they point to the same reference object in memory
console.log(objectA === objectB); // returns false - different objects in memory
Now, remember, all I have done is given the two anonymous object literals you created, variable names. Otherwise, it is the same distinction.
Hope this helps
Thanks it does help a lot!
As I understand it, this is a general rule for not only objects, but also arrays and functions, right?
Thanks!
- Non-primitive values such as Array , Object , or Functions arenβt equal to each other except themselves.
This (from the article) helped a lot!
Ah, but that is why I specifically said object literals. In JS, Arrays, Strings, Functions, Dates are all objects. The thing created with a curly-brace (e.g. { value: 1 }
) is an object literal. In Python, it is called a dictionary. In other languages it is called a mixture of enum, structβ¦
Point is, JavaScript is heavily object-based (although, not typically considered an object oriented programming language, and I am not sure why).
Hope that clarifies.
Oh yes sure, I forgot about that. Makes perfect sense now
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.