# Javascript class - class instance variables declaration

**URL:** <https://discourse.processing.org/t/javascript-class-class-instance-variables-declaration/38936>\
**Category:** Beginners\
**Created:** [September 22, 2022, 11:05pm UTC](https://discourse.processing.org/t/javascript-class-class-instance-variables-declaration/38936 "2022-09-22T23:05:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vkbr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vkbr/32/16844_2.png) [@vkbr](https://discourse.processing.org/u/vkbr)\
**Post date:** [September 22, 2022, 11:05pm UTC](https://discourse.processing.org/t/javascript-class-class-instance-variables-declaration/38936/1 "2022-09-22T23:05:33Z")

</div>

In Java I could:

```auto
  class Stuff{
    //a instance var not got trough constructor
    color c = color(0,0,0);

     Stuff(float _x){
      float x = _x;
    }
  }

```

in js, instance vars need all to be inside the constructor right? Like this?

```auto
class Stuff(){
  // only methods, right?
  constructor(x){
    this.x = x
    //a instance var not got trough constructor
    thisc = color(0,0,0);

  }
}

```

Did I get this correct?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 22, 2022, 11:15pm UTC](https://discourse.processing.org/t/javascript-class-class-instance-variables-declaration/38936/2 "2022-09-22T23:15:47Z")

</div>

> [@vkbr](#):
>
> In JS, instance vars need all to be inside the constructor, right?

> **[Public class fields - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields#public_instance_fields)**
>
> Public fields are writable, enumerable, and configurable properties. As such, unlike their private counterparts, they participate in prototype inheritance.

---

<div class="post-metadata">

**Author:** ![vkbr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vkbr/32/16844_2.png) [@vkbr](https://discourse.processing.org/u/vkbr)\
**Post date:** [September 22, 2022, 11:55pm UTC](https://discourse.processing.org/t/javascript-class-class-instance-variables-declaration/38936/3 "2022-09-22T23:55:05Z")

</div>

Ok, thanks for pointing me the specific part of the docs. Didn’t find this. I see I got this wrong. Will study. Instance public fields… very well, knowing the name is a lot :)))  
cheers
