This is the longhand for creating an object and assigning values to keys (you’re never going to use this, but as comparison):
const someObject = new Object();
someObject.prop1 = "val1";
someObject.prop = "val2";
someObject.prop3 = "val3";
This is the shorthand, the object literal syntax (you’re always going to use this):
const someObject = {
prop1: "val1",
prop2: "val2",
prop3: "val3",
};
This is the longhand for accessing properties on an object and assigning them to variables for using somewhere in your code:
const prop1 = myObject.prop1;
const prop2 = myObject.prop2;
const prop3 = myObject.prop3;
This is the shorthand for accessing properties on an object, assigning them to variables for use somewhere in your code:
const { prop1, prop2, prop3 } = myObject;
It is called pattern matching. Look at what it looks like – it’s the same as the object literal syntax:
const { prop1, prop2, prop3 } = { prop1: "val1", prop2: "val2", prop3: "val3" };
=
means assign the value on the right-hand side to the variable name on the left-hand side. This is doing that, but it’s also saying “match this shape object”. You know which keys because you’re literally writing the keys you want to match: if you write something different that isn’t a key on the object then it isn’t going to match.