# Global variables

**URL:** <https://forums.fusetools.com/t/global-variables/6649>\
**Category:** How-to Discussions\
**Created:** [February 22, 2016, 4:55pm UTC](https://forums.fusetools.com/t/global-variables/6649 "2016-02-22T16:55:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdeichen](https://avatars.discourse-cdn.com/v4/letter/g/35a633/32.png) [@gdeichen](https://forums.fusetools.com/u/gdeichen)\
**Post date:** [February 22, 2016, 4:55pm UTC](https://forums.fusetools.com/t/global-variables/6649/1 "2016-02-22T16:55:05Z")

</div>

Hey guys,

Is there a way to declare global variables across a complete application? Or at least throughout a .ux file?

Ideally, I want to be able to grab a JSON file, pluck out some variables using JavaScript and make them accessible throughout the app.

If I redeclare module.exports at any point, I have to redeclare my variables.

Example:

```auto
<JavaScript File="questions.json" ux:Global="qs" />
<JavaScript>
    var json = require("qs");

    module.exports = {
        quizname: json.data.quizname
    }
</JavaScript>

```

Is there a way to make “quizname” accessible throughout the .ux file? I.e. without declaring it in every use of module.exports?

---

<div class="post-metadata">

**Author:** ![me14](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/me14/32/443_2.png) [@me14](https://forums.fusetools.com/u/me14)\
**Post date:** [May 12, 2016, 10:35pm UTC](https://forums.fusetools.com/t/global-variables/6649/2 "2016-05-12T22:35:37Z")

</div>

Any solution to this?

---

<div class="post-metadata">

**Author:** ![Paul\_Go](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/paul_go/32/212_2.png) [@Paul\_Go](https://forums.fusetools.com/u/Paul_Go)\
**Post date:** [May 12, 2016, 10:59pm UTC](https://forums.fusetools.com/t/global-variables/6649/3 "2016-05-12T22:59:46Z")

</div>

I’m fairly certain that there is no way to do this currently. Fuse team: Can you at least give us a “maybe”, or “not happening”?

This is a core concept of JS and the platform seems broken without it.

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [May 13, 2016, 3:25pm UTC](https://forums.fusetools.com/t/global-variables/6649/4 "2016-05-13T15:25:27Z")

</div>

Hi!

DataContexts are cascading down the UI three, so as long as you export `quizname` in one of your topmost `<JavaScript>` tags, e.g. direclty inside your `<App>` like this:

```auto
<App>
    <JavaScript>
        ...
        module.exports = {
            quizname: something
        }
    </JavaScript>

```

Then it will be available in the entire app using `{quizname}`

Hope that helps!

---

<div class="post-metadata">

**Author:** ![dafyk](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/dafyk/32/146_2.png) [@dafyk](https://forums.fusetools.com/u/dafyk)\
**Post date:** [September 20, 2016, 11:02am UTC](https://forums.fusetools.com/t/global-variables/6649/5 "2016-09-20T11:02:11Z")

</div>

\> \*\*Anders Lassen wrote:\*\* \> \>

Then it will be available in the entire app using `{quizname}`

> 

Hope that helps!

Is {quizname} also available from child component JavaScript code?

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [September 20, 2016, 9:43pm UTC](https://forums.fusetools.com/t/global-variables/6649/6 "2016-09-20T21:43:07Z")

</div>

Hi,

No, not in JavaScript.

You could use `this.findData("quizname")` which will return an observable of the value. This is however not recommended practice as it introduces hidden dependencies for your child component.

The best practice is to declare a `ux:Property` on the child component and databind `{quizname}` to that property from the parent scope.

---

<div class="post-metadata">

**Author:** ![juggy333](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@juggy333](https://forums.fusetools.com/u/juggy333)\
**Post date:** [February 26, 2017, 8:08am UTC](https://forums.fusetools.com/t/global-variables/6649/7 "2017-02-26T08:08:19Z")

</div>

Hi Anders,

I am trying to have Two Way binding on Observable (Array type) that is declared in main App Javascript and then being passed as object property to a Class. After it is passed on to a class ux, the Javascript under its is retrieving the Observable Property using **this.PropertyName.inner()** function. After retrieval, on some action the observable is changed by adding or deleting values. This change is not being reflected on the main App Observable. Please assist. Ultimately my goal is to have a Global Observable to access and modify on any Page in app.

- [Attached UX file](https://s3.us-east-2.amazonaws.com/fuse-legacy-forum-assets/GnvvprcWvSoA-image-1488096564467.ux)

- [Attached UX file](https://s3.us-east-2.amazonaws.com/fuse-legacy-forum-assets/K67JXbOuFVx2-image-1488096564485.ux)

---

<div class="post-metadata">

**Author:** ![juggy333](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@juggy333](https://forums.fusetools.com/u/juggy333)\
**Post date:** [February 26, 2017, 9:07am UTC](https://forums.fusetools.com/t/global-variables/6649/8 "2017-02-26T09:07:31Z")

</div>

Reading your comments on other post I realized that such variables would be good to be places in separate model JS file. So I kept the needed Global Observable in Model.js file and accessing this by importing using **require**. This helps having a Global Javascript observable. This fixed my issue.

Thank you.
