# Refer to constants in JS

**URL:** <https://discourse.elm-lang.org/t/refer-to-constants-in-js/531>\
**Category:** Learn\
**Created:** [January 15, 2018, 5:54am UTC](https://discourse.elm-lang.org/t/refer-to-constants-in-js/531 "2018-01-15T05:54:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anacrolix](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/anacrolix/32/458_2.png) [@anacrolix](https://discourse.elm-lang.org/u/anacrolix)\
**Post date:** [January 15, 2018, 5:54am UTC](https://discourse.elm-lang.org/t/refer-to-constants-in-js/531/1 "2018-01-15T05:54:25Z")

</div>

Recently my Elm Chromecast app stopped working on Android. I just tracked it down to a string constant changing on the JS side. chrome.cast.AutoJoinPolicy.ORIGIN\_SCOPED was “ORIGIN\_SCOPED” and changed to “origin\_scoped”. Of course in Elm I just have  
originScoped : AutoJoinPolicy  
originScoped =  
"origin\_scoped"  
I’d really like to just refer to the JS constant directly so this kind of thing can’t happen again. How would I do that?

---

<div class="post-metadata">

**Author:** ![robin.heggelund](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/robin.heggelund/32/1330_2.png) [@robin.heggelund](https://discourse.elm-lang.org/u/robin.heggelund)\
**Post date:** [January 15, 2018, 6:34am UTC](https://discourse.elm-lang.org/t/refer-to-constants-in-js/531/2 "2018-01-15T06:34:08Z")

</div>

You can pass in JS-constants to your Elm app using flags (see `programWithFlags`), and storing it in your model.

---

<div class="post-metadata">

**Author:** ![anacrolix](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/anacrolix/32/458_2.png) [@anacrolix](https://discourse.elm-lang.org/u/anacrolix)\
**Post date:** [January 15, 2018, 11:56am UTC](https://discourse.elm-lang.org/t/refer-to-constants-in-js/531/3 "2018-01-15T11:56:23Z")

</div>

This seems non-trivial. I want to pass a record that contains a bunch of constants with NAMES\_LIKE\_THIS, which Elm barfs on. Which may imply some JSON decoding or my munging the values before passing them in?

---

<div class="post-metadata">

**Author:** ![turboMaCk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/turbomack/32/355_2.png) [@turboMaCk](https://discourse.elm-lang.org/u/turboMaCk)\
**Post date:** [January 15, 2018, 12:53pm UTC](https://discourse.elm-lang.org/t/refer-to-constants-in-js/531/4 "2018-01-15T12:53:53Z")

</div>

You can use `Decoder` for `Flags`. Just define `main` as `Program Value model msg` (where Value is Value from Json module) and use `decode` in `init`.
