Init method

The author of Simply JavaScript uses the method of init for objects. But then I read that it is not a keyword in JavaScript. I am very confused. Do we have to define the init keyword first. Hopefully, someone can free me from this confusion.i

Yeah you’re right, this method doesn’t exist on objects in JS by default. It’s common to add convenience methods like this to make object creation easier. An init method is sometimes added by developers as a kind of ‘secondary constructor’ - you can see an example of this with libraries such as Backbone.js, where you create new view objects like this:

var ListItemView = Backbone.View.extend({
    
    tagName: 'li',

    initialize: function() {
        this.listenTo(this.model, "change", this.render);
    },

    // ...
});

var myListItem = new ListItemView;  // Initialize function will be called.

Here the object’s real constructor does the work of setting up object defaults and such behind the scenes, and then calls the user-defined initialize method (if it exists) to do any other object configuration that you might need.