The second method is simply more specific, so for the purpose of creating an object (if it does not already exist), this is better. The first method only checks whether the object is "true", that is, if Obj was 5, it will still return the original Obj , whereas in the second method, Obj must be of type "object" in order to preserve its value.
In fact, there isn’t much difference because you rarely encounter situations like the one above; the second method simply tells the reader what you want, more precisely. I like the first method because it is shorter, but it depends on how specific you want to be.
source share