Are the tags obj1and obj2the same?
Yes. Although they are not strictly equal in your question (they are not the same object references), they are essentially identical.
Is there any difference between ({})and {}in javascript?
Yes. I know two situations that were in my mind where this could make a difference.
First, you might come across this syntax in the ES6 arrow function :
let array = [1, 2, 3, 4, 5];
let mappedArray = array.map(value => ({
original: value,
double: value * 2
}));
, , map. :
array.map(value => {
return {
original: value,
double: value * 2
};
});
( this, ES6):
array.map(function (value) {
return {
original: value,
double: value * 2
};
});
-, JavaScript, .
, :
{
a: 1,
b: 2,
c: 3
}
... ( ):
({
a: 1,
b: 2,
c: 3
})