7.8

Conclusion

In this chapter, we learned how to interact with JavaScript from Elm using ports, flags, and custom elements. Whenever possible we should avoid using any JavaScript code in Elm because it can cause our app to crash during runtime. But if we must, Elm still has our back. It tries to minimize the damage by setting clear boundaries. JavaScript isn’t allowed to pass an arbitrary code or sneak in an incorrectly typed value through those boundaries. If it still attempts to do so despite the restrictions, Elm will throw an error immediately.

Letting our app crash because of some faulty JavaScript code is not desirable. That’s why we should always try to decode the values coming from JavaScript ourselves instead of the Elm runtime. That way we can graciously handle the errors as we encounter them.

Back to top

New chapters are coming soon!

Sign up for the Elm Programming newsletter to get notified!

* indicates required
Close