# Access private properties

**URL:** <https://forum.freecodecamp.org/t/access-private-properties/160944>\
**Category:** General\
**Created:** [November 26, 2017, 3:45pm UTC](https://forum.freecodecamp.org/t/access-private-properties/160944 "2017-11-26T15:45:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomer-n](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tomer-n/32/71826_2.png) [@tomer-n](https://forum.freecodecamp.org/u/tomer-n)\
**Post date:** [November 26, 2017, 3:45pm UTC](https://forum.freecodecamp.org/t/access-private-properties/160944/1 "2017-11-26T15:45:10Z")

</div>

hello,

I learned in the last lesson about private Properties inside the function constructor.

what i don’t understand is, how can i access or use functions with methods?

when i try to create a new instance of this constructor function, i get undefined. here is what i tried:

```auto
//this is the constructor:

var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var suburu = new Car();
console.log(suburu.accelerate(5)); // returns undefined 

```

---

<div class="post-metadata">

**Author:** ![PortableStick](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/portablestick/32/65591_2.png) [@PortableStick](https://forum.freecodecamp.org/u/PortableStick)\
**Post date:** [November 26, 2017, 4:28pm UTC](https://forum.freecodecamp.org/t/access-private-properties/160944/2 "2017-11-26T16:28:25Z")

</div>

You’re using the function just fine, but it doesn’t have a return value. Try changing `accelerate` like this:

```auto
this.accelerate = function(change) {
    speed += change;
    return speed;
  };

```

---

<div class="post-metadata">

**Author:** ![TomerPacific](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tomerpacific/32/158967_2.png) [@TomerPacific](https://forum.freecodecamp.org/u/TomerPacific)\
**Post date:** [November 26, 2017, 7:40pm UTC](https://forum.freecodecamp.org/t/access-private-properties/160944/3 "2017-11-26T19:40:04Z")

</div>

Hey @tomer-n,  
like @PortableStick, you are using methods associated with the Car class, but those methods do not have a return value.  
If you would have printed the Suburu’s object speed after the function you called, you would have seen that the speed is now 15.

I attached a link with a good example on Javascript ES6 classes:

[https://googlechrome.github.io/samples/classes-es6/](https://googlechrome.github.io/samples/classes-es6/)

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:33pm UTC](https://forum.freecodecamp.org/t/access-private-properties/160944/4 "2021-01-17T20:33:47Z")

</div>

Closed on January 17, 2021, 8:33pm UTC


