---
title: "Comment by CJ on \"Understanding Private Variables in JavaScript Class Constructors\" | Hashnode"
description: "This really helped me understand what this &quot;private variable&quot; was really about. Thank you, Anna, for this wonderful explanation. just one thing: class"
url: "https://hashnode.com/posts/understanding-private-variables-in-javascript-class-constructors/5fa1479124a897066ab25a37/comment/60ed726cfc37a15ec1567c8e"
---

[Discussion](https://hashnode.com/posts/understanding-private-variables-in-javascript-class-constructors/5fa1479124a897066ab25a37)

Comment [Understanding Private Variables in JavaScript Class Constructors](https://hashnode.com/posts/understanding-private-variables-in-javascript-class-constructors/5fa1479124a897066ab25a37)

[CJ](https://hashnode.com/@cjreads665)

[Jul 13, 2021](https://hashnode.com/posts/understanding-private-variables-in-javascript-class-constructors/5fa1479124a897066ab25a37/comment/60ed726cfc37a15ec1567c8e)

This really helped me understand what this "private variable" was really about. Thank you, Anna, for this wonderful explanation. just one thing:

```
class User {
  constructor(name, age, favNumber) {
    let superSecretNumber = Math.round((age * favNumber) / name.length);
    function logOutcome() {
      console.log(`Wow! Your secret number is ${superSecretNumber}`);
    }
    return { name, age, favNumber, logOutcome };
  }
}

let firstUser = new User("Anna", 33, 7);
console.log(firstUser.name); // logs "Anna"
console.log(firstUser.superSecretNumber); // WHOMP WHOMP: 'undefined'
firstUser.logOutcome();  // logs "Wow! Your secret number is 58"
```

Isn't the constructor function ONLY for assigning arguments to variables we use inside the class? shouldn't we declare the supersecretnumber outside the constructor? and why are assigning the values _outside_ the constructor?
