title: Javascript Class vs. "List" of Functions in Nodejs
body: <p>I'm kind of new in programming and I'm currently wondering myself what is the benefit of class vs a simple "list" of related functions in NodeJs.</p>
  
  <p>As very simplified example, I guess I would create a user like this if I'd use Class: </p>
  
  <pre><code>class User {
      constructor(email) {
          this.email = email;
      }
  
      validateEmail() {
          // whatever function that checks if this.email is valid
          if (this.email === 'notValid') {
              throw new Error();
          }
          return this;
      }
  
      create() {
          this.validateEmail();
          // whatever function that inserts user in the database
          return user;
      }
  }
  
  const newUser = new User('test@test.com');
  const user = newUser.create();
  </code></pre>
  
  <p>And I would do something like this with what I call a "list" of related functions : </p>
  
  <pre><code>const validateEmail = email =&gt; {
      // whatever function that checks if valid email
      if (email === 'notValid') {
          throw new Error();
      }
      return true;
  };
  
  const createUser = email =&gt; {
      if (validateEmail(email)) {
          // whatever function that inserts the user in the database
          return user;
      }
  };
  
  const user = createUser('test@test.com');
  </code></pre>
  
  <p>The second way seems to me that it can ends with a little less code. And don't even have to instatiate the class.</p>
  
  <p>Let's say I have a node API, with multiple "User" routes and controllers. I guess I have to instantiate the User Class every time a User routes/controllers is called, right ? As a beginner, this does not sound "optimized" to me... But I'm surely missing something...</p>
  
  <p>Thank for your help</p>