Also, one of the potential purpose of doing this is to save that multi lines of code just to declare variables right?
and inside var {x:x,y:y,z:z}=bar(); the x,y,z that is left to the : are the global variables we just declared right? the ones that are on the right of : are the internal values of the object.

Also, one of the potential purpose of doing this is to save that multi lines of code just to declare variables right?

Yes, you are correct.

zhouxiang19910319:

Also, one of the potential purpose of doing this is to save that multi lines of code just to declare variables right?
and inside var {x:x,y:y,z:z}=bar(); the x,y,z that is left to the : are the global variables we just declared right? the ones that are on the right of : are the internal values of the object.

No, the ones of the left are the internal values of the objects’s properties and the ones on the right are the new variable names. Think about it in the following manner:

var {actualPropertyName: newVariableName} = objectName;

FYI - If you want the new variable’s name to be the same as the object property’s name, you can write:

You are creating your function in manner that it will work only on AVG_TEMPERATURES object.
But, what if there was another object like :

const AVG_TEMPERATURES1 = {
today: 75.5,
tomorrow: 80
};

?
You will have to write function for that too.
So, you should use the argument passed in your function instead of actual object name and your function will be applicable for every object.
Does this help?