Difference
Well, there are certain differences between both ways. In a declarative form, the entire configuration is based on HTML attributes, such as dojo-data-props , but also on some other attributes, such as value, name, ... Thus, the created DOM node actually serves as a kind of placeholder.
When you create widgets by writing JavaScript code, you will need to provide a DOM node, you will attach it too, but the biggest difference is that it will not copy the HTML attributes from that DOM node. The DOM node here serves only as a container, not a placeholder.
Preferred
There is no preferred solution that usually depends on the requirements of your application and what you consider to be the cleanest way to develop.
Personally, I like declarative markup because in the end it's part of the user interface. However, you can go as far as you want. I also saw people create stores and widget event handlers, but I personally prefer to write them in JavaScript, because they are not part of the user interface.
There are other reasons that can change the way widgets are created. For example, one of the biggest drawbacks of declarative markup is that you need to parseOnLoad page (e.g. using parseOnLoad ). This is usually slower than creating software widgets. You can improve it only by parsing certain DOM nodes, but then you need to write additional code (and it still is not accelerating).
Just a small note; this does not mean that the declarative way is slow. This is just an additional operation that needs to be performed, and therefore it is a bit slower, but most likely the end user will not even see the difference.
The advantage of the declarative method is that when the page loads, the end user can see the placeholder. If you select the placeholder you want (for example, <select> for dijit/form/FilteringSelect and dijit/form/ComboBox ), the end user will at least see something. If you create everything programmatically, the end user will see a blank page until the JavaScript code is executed.
So, if performance is one of the requirements, you can select them programmatically. If you like to separate code in which the presentation layer is separate from the business logic, I would recommend using a declarative way.
But in the end, both solutions are good.