Below you can see the same functionality implemented in JavaScript ES6 and Scala.js. See any differences?

ES6

  1. const xhr = new XMLHttpRequest();
  2. xhr.open("GET",
  3. "https://api.twitter.com/1.1/search/" +
  4. "tweets.json?q=%23scalajs"
  5. );
  6. xhr.onload = (e) => {
  7. if (xhr.status === 200) {
  8. const r = JSON.parse(xhr.responseText);
  9. $("#tweets").html(parseTweets(r));
  10. }
  11. };
  12. xhr.send();

Scala.js

  1. val xhr = new XMLHttpRequest()
  2. xhr.open("GET",
  3. "https://api.twitter.com/1.1/search/" +
  4. "tweets.json?q=%23scalajs"
  5. )
  6. xhr.onload = { (e: Event) =>
  7. if (xhr.status == 200) {
  8. val r = JSON.parse(xhr.responseText)
  9. $("#tweets").html(parseTweets(r))
  10. }
  11. }
  12. xhr.send()

Even though Scala language comes from a very different background than JavaScript, typical Scala code is quite understandablefor JavaScript developers. This section will walk you through the differences and show you how to write basic Scala code. If youhave fallen in love with the new features in ES6 like arrow functions or destructuring, you can find them all in Scala as well!

The walk-through has been split into three parts:

Each part has a lot of code examples comparing ES6 code to corresponding Scala code.

You may also find some of the presentation videos a nice way to familiarize yourself with Scala.