Should I Use Optional Chaining?
You Can Use Optional Chaining When Attempting to Call a Method Which May Not Exist. This Can Be Helpful, for Example, When Using an Api in Which a Method Might...
You can use optional chaining when attempting to call a method which may not exist. This can be helpful, for example, when using an API in which a method might be unavailable, either due to the age of the implementation or because of a feature which isn't available on the user's device.
Is optional chaining bad practice?
There is nothing wrong with optional chaining, the feature is related to idiomatic absence value in JS, and it is "null | undefined". ... Issues are maybe not fully related with the proposition itself, but more with current state of things, and how JS needs to be compatible backward in order to not break the web.
Should I use optional chaining JavaScript?
Optional chaining in JavaScript is very useful because it can clean up our code with a single character: ? . Here's an example where we can check if an object person has a property called name . Note that this only works on nested properties. If you try to use this at the first level, it will just return an error.