The javascript function incorporates a special App Inventor feature called window.AppInventor.getWebViewString(), which allows App Inventor apps to communicate with the WebViewer component's internal processing of javascript.
This simple example shows how to use the window.AppInventor.getWebViewString() function to pass data to and from the WebViewer component, and thereby an App Inventor app.