davidjumani opened a new issue #4956: URL: https://github.com/apache/cloudstack/issues/4956
Two ways in which the UI code can be simplified ### Optioinal chainging The optional chaining `?.` is a safe way to access nested object properties, even if an intermediate property doesn’t exist. `(error.response && error.response.headers && error.response.headers['x-description']) || error.message` using optional chaining it reduces to `error.response?.headers.?['x-description'] || error.message` Ref : https://javascript.info/optional-chaining This can also be used to invoke methods on objects, etc This improves readability as well as simplifies the existing code ### Nullish coalescing Nullish coalescing is an improvement on the || operator where it only checks if an object is null or undefined. Using the || operator returns false if the object is zero or an empty string which can cause issues in the code when the value is zero but incorrectly treated as false ``` let height = 0; alert(height || 100); // 100 alert(height ?? 100); // 0 ``` https://javascript.info/nullish-coalescing-operator ##### ISSUE TYPE <!-- Pick one below and delete the rest --> * Enhancement Request -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
