In this article, we will explore how to create a document library step by step using JavaScript.
Why we create CEWP
So that we can utilize the client-side computing by using CSOM.
Let's start step by step.

Step 1

Save the below script as a text file and upload it to in Site Assets page.
Step 2

Add Content Editor Web Part (CEWP) to your SharePoint site page. Create site page >> add CEWP in your page -
1 Click "Insert" option
2. Select "Media and Content".
3. Select Content Editor > Edit web part.
Step 3

Pass this script file's reference in your CEWP.
  1. <script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
  2. </script>
  3. <script language="javascript" type="text/javascript">
  4. $(document).ready(function() {
  5. SP.SOD.executeFunc('sp.js', 'SP.ClientContext', createDocLib);
  6. });
  7. function createDocLib() {
  8. // Below we will pass Get Client Context and Web Object
  9. var clientContext = new SP.ClientContext();
  10. var oWeb = clientContext.get_web();
  11. //Create Library Creation Information and add it to List Collection
  12. var libraryCreationInfo = new SP.ListCreationInformation();
  13. libraryCreationInfo.set_title('My Test Library');
  14. libraryCreationInfo.set_description('This is a Test Library Using CEWP');
  15. libraryCreationInfo.set_templateType(SP.ListTemplateType.documentLibrary);
  16. var oListColl = oWeb.get_lists().add(libraryCreationInfo);
  17. //how to Load Client Context and Execute batch below
  18. clientContext.load(oListColl);
  19. clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
  20. }
  21. function QuerySuccess() {
  22. console.log(" congratYour Document Library created successully.");
  23. }
  24. function QueryFailure(sender, args) {
  25. console.log('Request failed - ' + args.get_message());
  26. }
  27. </script>
My OUTPUT looks like the below screenshot.
Try it in your environment.
Soon, we will create more CSOM real-world scenario. So, stay tuned and follow me.