As @ matt-busche points out, worrying about this kind of performance is a case of premature optimization: performance differences are not significant. It probably took more time to type the question than during the cumulative time that one or the other will save you throughout the life of the application that you write.
What you should aim for is to write clear code that most accurately reflects the intent of the logic and the intended use of the code.
You should set a default value for your argument if that default value is the most likely useful value for this argument. This is not always appropriate: sometimes there is no “most likely useful value”, so the argument should not have a default value and, accordingly, requires that the calling code pass a value.
You cannot write code that sets the default value, so that subsequent code is not interrupted (for example: the default string argument is "", so you can assume that it exists in the following code).
One of the advantages of specifying a default argument is that the default value is reflected in the metadata of the component and its auto-generated documents. This is useful if you are writing an API for third-party consumption.
On the other hand, isDefined() should usually be avoided, since it is a rather limited, inaccurate function, and I saw how it gave false positives in some rare situations (and this was not only I did not understand the framework -).
Almost always you need to use structKeyExists() over isDefined() .
source share