How To Create A Generic List Using SharePoint JSOM

Just copy the code below and paste it in a "content editor" webpart on a web part page. 
  1. <script src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js" type="text/javascript"></script>  
  2. <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>  
  3. <script type="text/javascript" src="/_layouts/15/sp.js"></script> <input id="listName" type="text" name="Listname"></input> <input id="btnCreate" type="button" value="Click me" onclick="createList()">  
  4. <script type="text/javascript">  
  5.     function createList() {  
  6.         var clientContext;  
  7.         var listCreationInfo;  
  8.         var web;  
  9.         var list;  
  10.         var lstname = document.getElementById("listName").value;  
  11.         clientContext = SP.ClientContext.get_current();  
  12.         web = clientContext.get_web();  
  13.         listCreationInfo = new SP.ListCreationInformation();  
  14.         listCreationInfo.set_title(lstname);  
  15.         listCreationInfo.set_templateType(SP.ListTemplateType.genericList);  
  16.         list = web.get_lists().add(listCreationInfo);  
  17.         clientContext.load(list);  
  18.         clientContext.executeQueryAsync(function() {  
  19.             alert("List created successfully!")  
  20.         }, function() {  
  21.             alert("Failed to create list!")  
  22.         });  
  23.     }  
  24. </script>  
It's the working code. It will work 100% for you. I am using my SharePoint online account in this example. Just name the generic list in the text box you want to create then click on the Click me button as shown below.
 
SharePoint 
 
A notification message will pop up as shown below. 
 
 SharePoint
 
You will find the newly created lists on the left navigation as shown below. If the list already exists it will give you a message saying that the list already exists.
 
SharePoint
 
It is a very basic example. I was looking for the working code but I was unable to find it anywhere, then after struggling with so many errors finally I was able to do that. I decided to post it  so new programmers can simply copy paste the code directly and understand it.