# What's the best way for global variables in UXP development?

**URL:** <https://forums.creativeclouddeveloper.com/t/whats-the-best-way-for-global-variables-in-uxp-development/3804>\
**Category:** UXP Plugin API\
**Tags:** javascript\
**Created:** [October 27, 2021, 7:17am UTC](https://forums.creativeclouddeveloper.com/t/whats-the-best-way-for-global-variables-in-uxp-development/3804 "2021-10-27T07:17:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![timmreiner](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@timmreiner](https://forums.creativeclouddeveloper.com/u/timmreiner)\
**Post date:** [October 27, 2021, 7:17am UTC](https://forums.creativeclouddeveloper.com/t/whats-the-best-way-for-global-variables-in-uxp-development/3804/1 "2021-10-27T07:17:43Z")

</div>

With the ES6 standard of UXP, which is the best way to set a global variable in my scripts?

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [October 27, 2021, 10:37am UTC](https://forums.creativeclouddeveloper.com/t/whats-the-best-way-for-global-variables-in-uxp-development/3804/2 "2021-10-27T10:37:26Z")

</div>

If you really have no other choice you could bind to the `window` object. But avoid it if you can. It will make your code cleaner and work easier and less likely to be in conflict with 3rd party libraries that could accidentally try to use the same variable name.

---

<div class="post-metadata">

**Author:** ![timmreiner](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@timmreiner](https://forums.creativeclouddeveloper.com/u/timmreiner)\
**Post date:** [October 27, 2021, 10:44am UTC](https://forums.creativeclouddeveloper.com/t/whats-the-best-way-for-global-variables-in-uxp-development/3804/3 "2021-10-27T10:44:27Z")

</div>

Hey, thanks for your quick feedback. Do you think it would be better to redefine the variable

(for example …var app = require(‘photoshop’).app; …)

in every single function? My thought was that it would be practical to define it once globally, especially when trigger the application.

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [October 27, 2021, 11:49am UTC](https://forums.creativeclouddeveloper.com/t/whats-the-best-way-for-global-variables-in-uxp-development/3804/4 "2021-10-27T11:49:08Z")

</div>

Well the best practice is not to do that. And in modern IDE like VSCode with TypeScript it can import things automatically. But otherwise, if you really want to then you can do it. The problem could if anything else will also try to add the same variable into the global scope.

---

<div class="post-metadata">

**Author:** ![timmreiner](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@timmreiner](https://forums.creativeclouddeveloper.com/u/timmreiner)\
**Post date:** [October 27, 2021, 11:50am UTC](https://forums.creativeclouddeveloper.com/t/whats-the-best-way-for-global-variables-in-uxp-development/3804/5 "2021-10-27T11:50:22Z")

</div>

All right,  
I will try my best 😉

Thanks!
