A key feature of Scala.js is its interoperability with JavaScript code, which far exceeds that of many other languages targeting JavaScript. Except of course for languages that translate almost literally to JavaScript (e.g., TypeScript and CoffeeScript).

Scala.js exhibits both means to call JavaScript APIs from Scala.js, and to be called from JavaScript code.

Type Correspondance

Some Scala types are directly mapped to corresponding underlying JavaScript types. These correspondances can be used when calling Scala.js code from JavaScript and when defining typed interfaces for JavaScript code.

Scala typeJavaScript typeRestrictions
java.lang.Stringstring
scala.Booleanboolean
scala.Charopaque
scala.Bytenumberinteger, range (-128, 127)
scala.Shortnumberinteger, range (-32768, 32767)
scala.Intnumberinteger, range (-2147483648, 2147483647)
scala.Longopaque
scala.Floatnumber
scala.Doublenumber
scala.Unitundefined
scala.Nullnull
subtypes of js.Objectcorresponding JavaScript typesee calling JavaScript guide
other Scala classes
including value classes
opaque, except for exported methods
Note: toString() is always exported
see exporting Scala.js APIs to JavaScript