When do you need to use default="{'sobjectType': 'ObjectName'} for an aura:attribute?
Based on your comments:
Creating an instance in JS
Defaulting the attribute makes sure that you have an instance created for the object. If you don't have it defaulted, and if you attempt to utilize it in JS or the component, you will get a null
instance. And thus, if you attempt to utilize a null
instance further, you will get an error.
So, if you want to utilize an SObject
instance in your component or JS, then you have to use default the sobjectType
during declaration to create an instance of the object, and then utilize it in your component or JS to populate other fields or use for further operations.
<aura:attribute name="customObject" type="CustomObject__c"
default="{'sobjectType': 'CustomObject__c'}"/>
OR
If you don't provide default, you will need to make sure you construct the object in the JS on initialization and provide the sobjectType
attribute and utilize it accordingly.
var c = {'sobjectType' : 'CustomObject__c', 'Field1' : field1Value};