Destructuring is useful but what if you have conflicts with the variable names provided by the object being imported?
Consider the following example where we destructure arguments of a function.
|
|
We can get into a pickle if the function already has a variable x
. Well, not exactly in the above example but in a real world program that tends to have a hundred lines of code, and interact with a thousand other components.
One of the ways of avoiding the conflict is by using named arguments while destructuring the input - provide an alias during the destructuring.
|
|
During destructuring we specify the name of the function-specific variable that stores the value provided in input. The function will use this new variable while the original variable continues to be available within the object.