What is the main purpose of constructor?

Posted by Prem Tiwari | Updated on

What is the main purpose of constructor?

The constructor is mainly used for two purposes,

  1. To initialize local state by assigning object to this.state
  2. For binding event handler methods to the instance For example, the below code covers both the above cases,


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers