Crawling & Indexing Javascript

In general, search engines cannot execute Javascript and Ajax code when crawling and indexing websites.

Google is the exception. A test performed by Stephan Boyer suggests indexing is first performed without executing Javascript. Later, pages are re-indexed while taking their Javascript into account.

Content displayed via onclick methods, for example, will be taken into account for relevancy and ranking, but will be discounted because it is not immediately visible to users.

Javascript files must be accessible to Google crawlers (i.e., not blocked in the robots.txt for example) or Google is unlikely to rank corresponding pages. Google wants to know and trust what is being displayed to users when serving references in its search results.

Using the Fetch as Google functionality from Google's Search Console helps understanding what Google sees from a webpage.

SEO For Angular & Ajax Based Libraries

Angular.js modifies the content of a webpage dynamically using Ajax URLs, but it is hard for Google to crawl and index such content. Ajax URLs typically contain hashbangs #! to communicate with the server.

Regarding SEO, there is an agreement that web crawlers will transform hashbang URLs into escaped fragments URLs when sending requests to servers. Such servers return html content equivalent to the hashbang URLs content for indexing.

Some documentation to make your website Ajax crawalable via hashbangs URLs is available here and here. Many expect this method to be decommissioned sooner or later, since there is a better alternative.

Using HTML5's pushState()

Typically, one-page applications load their content via Ajax. Users don't navigate from URLs to URLs. HTML5's pushState() method is an alternative method to hashbang URLs to let crawlers access such application's content. It is SEO friendly for crawlers, since they don't need to translate URLs.

The pushState() method lets you modify the browser's current URL (and therefore its history too) without reloading pages. It is one-page application friendly. Using pushState() is the preferred method over escaped fragments for SEO purposes.

Avoiding to rely on escaped fragments for SEO is the safest long term practice today.