title: TypeError: Cannot read property 'trim' of undefined in Node application
body: <p>I am working on javascript application and have MVC model in the controllers there is a userController.js  file and in models, there is a user.js in the cleanup function file in the Models folder. why I am getting TypeError: Cannot read property 'trim' of undefined this error</p>
  <pre><code>//User.js files code goes here 
  
  let User = function (dataUser) {
    this.dataUser = dataUser
    this.errors = []
  }
  </code></pre>
  <p>// In the cleanup function I checked the input type string and then avoid any bogus entries by using trim and lowercase properties but I am getting an error ie Cannot read property 'trim' of undefined this error</p>
  <pre><code>User.prototype.cleanUp = function () {
    if (typeof this.dataUser.username != &quot;string&quot;) {
      this.dataUser.username = &quot;&quot;
    }
    if (typeof this.dataUser.email != &quot;string&quot;) {
      this.dataUser.username = &quot;&quot;
    }
    if (typeof this.dataUser.password != &quot;string&quot;) {
      this.dataUser.username = &quot;&quot;
    }
    this.dataUser = {
      username: this.dataUser.username.trim().toLowerCase(),
      email: this.dataUser.email.trim().toLowerCase(),
      password: this.dataUser.password
    }
  }
  User.prototype.login = function (callback) {
    this.cleanUp()
    usersCollection.findOne({ username: this.dataUser.username }, (err, attemptedUser) =&gt; {
      if (attemptedUser &amp;&amp; attemptedUser.password == this.dataUser.password) {
        callback(&quot;Success&quot;)
      } else {
        callback(&quot;Invalid  username / password&quot;)
      }
    })
  }
                      
  // userController.js code 
  exports.login = function (req, res) {
    let user = new User(req.body)
    user.login(function (result) {
      res.send(result)
    })
  }
  
                  
                      
                   
  </code></pre>