Top Backbone js interview questions and Answers for freshers and experienced.

Backbone.js is a client-side (Model, View, Controller) MVC-based JavaScript framework.It purely is written in Javascript.

Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.

Backbone’s Js only hard dependency is Underscore.js ( >= 1.8.3). For RESTful persistence and DOM manipulation with Backbone.View, include jQuery ( >= 1.11.0), and json2.js for older Internet Explorer support. (Mimics of the Underscore and jQuery APIs, such as Lodash and Zepto, will also tend to work, with varying degrees of compatibility.)

In Backbone.js, the collection is used to represent ordered set of models. Any event in model triggers an event in collection directly. For example, you can bind “change” event to be notified in a case when any model in the collection has been modified.

Backbone events is a module that can be mixed into any object, giving the object the ability to bind and trigger custom named events. Events are not declared before they are bound to any object. Events reflect the state of the model.

The “id” property on a model is automatically assigned based on the “id” set in the model’s attributes hash.

Ideally, this is the ID that you receive from the rest API for the resource that you are querying. On the other hand, “cid” is an ID temporarily assigned to each model and is useful until an actual ID is determined for the object. For example, a model pushed to a collection that has not yet been persisted can be addressed using “cid”, until it is saved in the database and an actual ID is generated for it.

A collection is a set of models which binds events when the model has been modified in the collection. Collection contains a list of models that can be processed in the loop and supports sorting and filtering. When creating a collection, we can define what type of model that collection is going to have along with the instance of properties. Any event triggered on a model, which will also trigger on the collection in the model.