Initializing objects can be a pain. You may end up with multiple checks if you are trying to set a specific prop in the object path to a pre-defined value.
For e.g. set color of a Kawasaki bike to ‘blue’. To do this we have to traverse through the object path from the root through color. This may be made more difficult if you may or may not get a partial array from an external function or a third party system.
Similar to using an OR condition to initialize a variable, we can deploy an AND function to efficiently set a prop in an object path.
|
|
The same arrangement will work even if you get a partial object from somewhere and you still need to output the same structure.
|
|