# Constants inside functions

**URL:** <https://community.haxe.org/t/constants-inside-functions/736>\
**Category:** Haxe\
**Created:** [May 30, 2018, 6:46pm UTC](https://community.haxe.org/t/constants-inside-functions/736 "2018-05-30T18:46:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shalmu](https://community.haxe.org/user_avatar/community.haxe.org/shalmu/32/359_2.png) [@shalmu](https://community.haxe.org/u/shalmu)\
**Post date:** [May 30, 2018, 6:46pm UTC](https://community.haxe.org/t/constants-inside-functions/736/1 "2018-05-30T18:46:06Z")

</div>

I’d be happy to

```haxe
function a(){
  const hey=33;
}

```

I love immutability. Do you?

---

<div class="post-metadata">

**Author:** ![RblSb](https://avatars.discourse-cdn.com/v2/letter/r/edb3f5/32.png) [@RblSb](https://community.haxe.org/u/RblSb)\
**Post date:** [May 30, 2018, 7:20pm UTC](https://community.haxe.org/t/constants-inside-functions/736/2 "2018-05-30T19:20:29Z")

</div>

Here is `final hey = 33;` since haxe 4.0 preview 2  
There is no documentation yet, but you can learn more here [Final by Simn · Pull Request #6596 · HaxeFoundation/haxe · GitHub](https://github.com/HaxeFoundation/haxe/pull/6596)  
UPD Oh, this does not work locally, my bad.

---

<div class="post-metadata">

**Author:** ![fullofcaffeine](https://community.haxe.org/user_avatar/community.haxe.org/fullofcaffeine/32/28_2.png) [@fullofcaffeine](https://community.haxe.org/u/fullofcaffeine)\
**Post date:** [May 30, 2018, 11:45pm UTC](https://community.haxe.org/t/constants-inside-functions/736/3 "2018-05-30T23:45:09Z")

</div>

Why wouldn’t `final` work for local vars? Was this intentional?

---

<div class="post-metadata">

**Author:** ![shalmu](https://community.haxe.org/user_avatar/community.haxe.org/shalmu/32/359_2.png) [@shalmu](https://community.haxe.org/u/shalmu)\
**Post date:** [June 3, 2018, 1:20pm UTC](https://community.haxe.org/t/constants-inside-functions/736/4 "2018-06-03T13:20:14Z")

</div>

Hm… So why there is no way to declare immutable variable locally? Is it hard to implement? Is anybody against it?

---

<div class="post-metadata">

**Author:** ![cmandlbaur](https://community.haxe.org/user_avatar/community.haxe.org/cmandlbaur/32/193_2.png) [@cmandlbaur](https://community.haxe.org/u/cmandlbaur)\
**Post date:** [June 4, 2018, 2:10pm UTC](https://community.haxe.org/t/constants-inside-functions/736/5 "2018-06-04T14:10:14Z")

</div>

Looks like the local implementation is still open to be implemented: [Add final keyword · Issue #6584 · HaxeFoundation/haxe · GitHub](https://github.com/HaxeFoundation/haxe/issues/6584)
