# Constants and JS/TS Style

**URL:** https://forum.makecode.com/t/constants-and-js-ts-style/104
**Category:** PXT
**Created:** [April 1, 2019, 5:46pm UTC](https://forum.makecode.com/t/constants-and-js-ts-style/104 "2019-04-01T17:46:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)
#### Post date: [April 1, 2019, 5:46pm UTC](https://forum.makecode.com/t/constants-and-js-ts-style/104/1 "2019-04-01T17:46:53Z")

</div>

While I have a specific question, I also am looking for some guidance. I trust this group, so I’m willing to open this can of worms here. 🙂

I’m looking at different JavaScript style guides to implement in the second half of the course that I am writing. I’ve settled on the _JavaScript Standard Style_ ([https://github.com/standard/standard](https://github.com/standard/standard)). It seems reasonable, widely-used, and fits the style that I’m accustomed to using as a C# programmer, aside from the typical Java quirks inherited from the Sun’s implementation of K&R style. It also specifically supports TypeScript code.

One thing that’s missing from _JavaScript Standard Style_ is a convention for naming constants. I can draw from other style guides, of course, but I’m curious as to what y’all use. Do you follow a style guide for your JavaScript / TypeScript code and, if so, which? What convention do you follow when naming constants?

---

<div class="post-metadata">

### Author: ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)
#### Post date: [April 5, 2019, 5:31pm UTC](https://forum.makecode.com/t/constants-and-js-ts-style/104/2 "2019-04-05T17:31:38Z")

</div>

Since no one else responded; for TypeScript I typically use `UPPER_CASE_WITH_UNDERSCORES` for constants that are intended to be used like class constants in java / macros in c (e.g. [here in the particle effects](https://github.com/Microsoft/pxt-common-packages/blob/85959d59f561e1cb349e02e1137f6e11a68ff881/libs/game/particles.ts#L7)). If it is just a local variable that I’ve made a constant because there is no current reason for it to be mutable, I `camelCase` it to match other local variables (e.g. [here](https://github.com/Microsoft/pxt-common-packages/blob/85959d59f561e1cb349e02e1137f6e11a68ff881/libs/game/particles.ts#L93)).

---

<div class="post-metadata">

### Author: ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)
#### Post date: [April 6, 2019, 2:47pm UTC](https://forum.makecode.com/t/constants-and-js-ts-style/104/3 "2019-04-06T14:47:26Z")

</div>

Awesome response; thanks, @jwunderl! I like the distinction between global/class constants and local constants. Thanks, too, for the examples! Much appreciated!

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [April 11, 2019, 3:00pm UTC](https://forum.makecode.com/t/constants-and-js-ts-style/104/4 "2019-04-11T15:00:11Z")

</div>

We have these naming conventions, mostly for extension writers: [https://makecode.com/extensions/naming-conventions](https://makecode.com/extensions/naming-conventions) . Probably should add a section on constants.

---

<div class="post-metadata">

### Author: ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)
#### Post date: [April 11, 2019, 9:14pm UTC](https://forum.makecode.com/t/constants-and-js-ts-style/104/5 "2019-04-11T21:14:52Z")

</div>

Thanks, @peli! I’ve looked at the main PXT docs many times as I write my own extensions, and somehow I missed that one.
