There are actually two ways to add a table of contents to a document in Google Docs. Both of these ways require that you create headings and subheadings in your document. The first way is through using Google Docs' built-in feature which can be accessed by clicking on "insert" button then select "table of contents". Watch this excellent tutorial from Shannon Hermandez to learn more about how to create a table of content using Google Docs built-in functionality.
The second way is through using a third party add-on called 'Table of Contents'. This is a powerful Google Docs add-on that allows you to easily create a table of content in the sidebar. The great thing about this feature besides providing readers with a quick overview of the main points covered in your document is that it makes it easier for them to instantly jump to any section in the document by simply clicking on any of the headings listed in the table of contents.
More importantly, the table of contents is automatically created out of the headings in your document. And when you add another heading you simply hit the refresh button and it will be automatically added to the table of contents. However, be forewarned that in some cases where you have several headings or your document is really very long, the functionality of table of contents can be very slow.