You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function Clone(object){
var newObject = {};
for(var key in object){
newObject[key] = object[key];
}
return newObject;
}
var objectLit = {foo : 'Bar'};
var cloneObj = Clone(obj); // Clone is the function which you have to write
console.log(cloneObj === Clone(objectLit)); // this should return false
console.log(cloneObj == Clone(objectLit)); // this should return true
where does the obj come from in var cloneObj = Clone(obj)?
should A == B be the same as A === B when both A and B are objects? why the last two lines have different outputs?
Thanks.
The text was updated successfully, but these errors were encountered:
Isn't that Clone() creates a new object but just has the same properties?
For the objects to be the same two objects are equal if they refer to the exact same object.
When you do cloneObj === Clone(objectLit) or cloneObj == Clone(objectLit) both will return false because they are simply identical but they are not the same object.
In Q31, we have
where does the
obj
come from invar cloneObj = Clone(obj)
?should
A == B
be the same asA === B
when bothA
andB
are objects? why the last two lines have different outputs?Thanks.
The text was updated successfully, but these errors were encountered: