# Where are the Javascript classes before I use them?

**URL:** https://discourse.processing.org/t/where-are-the-javascript-classes-before-i-use-them/48819
**Category:** Beginners
**Created:** [June 15, 2026, 8:08pm UTC](https://discourse.processing.org/t/where-are-the-javascript-classes-before-i-use-them/48819 "2026-06-15T20:08:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![EricRogerGarcia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ericrogergarcia/32/21029_2.png) [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)
#### Post date: [June 15, 2026, 8:08pm UTC](https://discourse.processing.org/t/where-are-the-javascript-classes-before-i-use-them/48819/1 "2026-06-15T20:08:23Z")

</div>

Hello,

Now that I’ve started using P5js and therefore Javascript, I’m curious about how it works internally.🙂

So, an object in javascript is likely to be permanently erased from memory when there is nothing more that references it by the garbage collector.

Since there aren’t really any classes in JavaScript, when I use the keyword class, I necessarily create an object somewhere and when I “create an instance” with the keyword new, I create a new object with the constructor of the parent class (which is actually an object) and it reference the parent object that I defined with the class keyword (via its prototype,

```auto

 __proto__ of the new object = the object created with the class keyword

```

_ **Is that correct?** _

**So, the funny question I ask myself is:**

How does JavaScript make sure not to delete the objects created with the class keyword before I use them to create new objects with the new keyword (the pseudo instances)?

I suppose it’s referring to them somewhere so that the garbage collector doesn’t erase them???

**N.B.** I didn’t find the answer on internet … hum, I didn’t think to ask to an I.A. !!! I’ll try tomorrow !!!

---

<div class="post-metadata">

### Author: ![EricRogerGarcia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ericrogergarcia/32/21029_2.png) [@EricRogerGarcia](https://discourse.processing.org/u/EricRogerGarcia)
#### Post date: [June 15, 2026, 8:31pm UTC](https://discourse.processing.org/t/where-are-the-javascript-classes-before-i-use-them/48819/2 "2026-06-15T20:31:41Z")

</div>

Well, I’m answering my question since I asked it here (and I couldn’t wait to ask Gemini)

the `class` keyword behaves like the `let` keyword, that is, it creates a new variable in the scope with the class name

so the garbage collector isn’t going to delete it !

🙂

**and so, I suppose one must not create a variable with the name of a class (in the same scope) !**

---

<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: [June 15, 2026, 9:43pm UTC](https://discourse.processing.org/t/where-are-the-javascript-classes-before-i-use-them/48819/3 "2026-06-15T21:43:02Z")

</div>

> [@EricRogerGarcia](#):
>
> … so the garbage collector isn’t going to delete it!

Keyword `class`, just like `let`, `const`, `var`, `function`, `import` and `using`, is used to declare a variable in JS.

Basically, `class` is a constructor `function` which returns an object instance when invoked via keyword `new`.

However, just like any JS object (functions & arrays are objects too), the `class` block itself can become eligible to be garbage-collected once it’s outta scope.

But there are some things that will withhold its fully deletion:

1. As long as any instance object of it exists, the `class` can’t be deleted; b/c the instance’s ` __proto__ ` points to the `class`.

2. As long as any variable, closure, property or array is still storing the `class` itself.

3. The `class` was declared globally at top-level scope.
