Using FileSystemObjectType.Folder and UnderlyingObjectType in ECMAScript (Client Object Model)

ECMAScript is sorta hit or miss in regards to utility IMHO but I having been involved in a few internal MSFT projects about it so have been using it more and more. Two assets that are significant when working with ECMAScript, specifically item creation, are the FileSystemObjectType enumeration and SP.ListItemCreationInformation.underlyingObjectType property. The FileSystemObjectType enumeration contains the following values:

invalid – the object is invalid.
file – the object is a file.
folder – the object is a folder.
web – the object is a site.

Using these values, you can use the SP.ListItemCreationInformation.underlyingObjectType property to toggle your item creation type, as demonstrated in the below code snippet:

var clientContext = new ClientContext(“http://localhost/”);
var web = clientContext.get_web();
var listCollection = web.get_lists();
var list = listCollection.getByTitle(“TestList”);
var itemCreateInfo = new ListItemCreationInformation();
var listItem= list.addItem(itemCreateInfo);
// Set title and properties
// context.Load(web);
// context.Load(list);