SharePoint: Check if feature is enabled using Sharepoint Client object model

Scenario: Check if a feature like "SharePoint Server Publishing Infrastructure" is activated in a site using JavaScript client object model.

Solution: There are mainly two things we need to know about a feature. One is the Scope of the feature like Site, Web, etc. and other is the ID of the feature. One of the ways of finding the ID of the feature is to use SharePoint Manager. We know that "SharePoint Server Publishing Infrastructure" is a Site scoped feature. Open your site in SharePoint Manager and click on Site Features. The following snapshot shows how to get the ID of the feature:  

Feature ID 

Now, the JavaScript client object model to check if the feature is enabled in the site or not.
var context = null;
var site = null;
var featureCollection;
ExecuteOrDelayUntilScriptLoaded(CheckFeatureIsEnabled, "SP.js");
function CheckFeatureIsEnabled(){
    context = new SP.ClientContext.get_current();
    site = context.get_site();
    featureCollection = site.get_features();
    context.load(featureCollection);
    context.executeQueryAsync(onSuccess,onFailure);
}
function onSuccess() {
    var listEnumerator = featureCollection.getEnumerator();
    while (listEnumerator.moveNext()) {
        if (listEnumerator.get_current().get_definitionId() == 'f6924d36-2fa8-4f0b-b16d-06b7250180fa') {
            alert('SharePoint Server Publishing Infrastructure is activated on the site');  
        }
    }  
}
function onFailure(sender, args) {
    alert('request failed ' + args.get_message() + 'n' + args.get_stackTrace());
}
Observe here that we are checking the feature at site level using site = context.get_site(); Had the feature been web scoped we would have to use web object like web = context.get_web();