There are many people who want to be president each with a different idea about how to govern the country. Those with similar ideas belong to the same political party. Party members choose their presidential nominee through a process called primaries and caucuses.
Once a candidate has the backing of enough delegates they become the Republican or Democratic presidential nominee. Then it is time for the televised debates. In order to participate in the debates a candidate must be on enough state ballots and have a statistically feasible chance of winning 270 electoral votes (to learn more about electoral college click here).
The debates are important because they allow voters to see how candidates think and speak and hear what others are saying about them. They also provide a chance for candidates to change the perceptions of their opponents which can make all the difference in the final result.
The debates are also a chance for the candidates to generate excitement and enthusiasm for their campaign. This in turn increases voter participation and turnout.