Background
The JavaScript Object Model was introduced in SharePoint 2010. It exposes on the client side many of the objects that were previously only accessible through server-side code or through dedicated web services.
Embedding JavaScript in SharePoint Pages
In SharePoint 2013 you can put your JavaScript in a Script Editor web part.
In SharePoint 2010 you can use the "content link" property of a Content Editor web part to link to an HTML file that contains your embedded script.
Object Reference
The constructors, methods, and properties of all objects found in the SP
namespace are documented in the SharePoint 2013 client object model reference here.
The SharePoint 2010 JavaScript client object model reference is available here.
JSOM's Asynchronous Programming Pattern
When using the JavaScript client object model, code generally takes the following pattern:
ClientContext
object.ClientContext
object to retrieve objects representing entities in the SharePoint object model, such as lists, folder, views.load
function to tell the ClientContext
what information you want to receive back from the server.ClientContext
object's executeQueryAsync
function to send the queued instructions to the server, passing two callback functions to run on success or failure.Alternatives
Client-side alternatives to the JSOM include SharePoint's web services, REST endpoints, and the .NET client object model.