I believe JavaScript's was running in the web where Java could not (iPhones) or was considered too heavyweight (no startup).
Then it became the true extremely portable language, because developers wanted a single language to write webapps in, and it was easier to get JavaScript running on their server than a new language running on every browser.