# Understanding Private properties

**URL:** <https://forum.freecodecamp.org/t/understanding-private-properties/166063>\
**Category:** General\
**Created:** [December 30, 2017, 4:37pm UTC](https://forum.freecodecamp.org/t/understanding-private-properties/166063 "2017-12-30T16:37:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcarlomany](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rcarlomany](https://forum.freecodecamp.org/u/rcarlomany)\
**Post date:** [December 30, 2017, 4:37pm UTC](https://forum.freecodecamp.org/t/understanding-private-properties/166063/1 "2017-12-30T16:37:39Z")

</div>

I completed the challenge, but I don’t understand the purpose of a private property. In the Bike constructor, why can’t I just use the public method:

* * *

this.setGear = function (val) {  
gear = val;  
};

* * *

and then, just delete everything else in the constructor?

**Your code so far**

````auto
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 Bike = function() {

  // Only change code below this line.
  var gear = 5;
  
  this.setGear = function (val) {
    gear = val;
  };
  
  this.getGear = function () {
    return gear;
  };
};

var myCar = new Car();

var myBike = new Bike();

myBike.getGear();
myBike.setGear(3);```
**Your browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36```.

**Link to the challenge:**
https://www.freecodecamp.org/challenges/make-object-properties-private
````

---

<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 16, 2021, 5:12pm UTC](https://forum.freecodecamp.org/t/understanding-private-properties/166063/3 "2021-01-16T17:12:53Z")

</div>

Closed on January 16, 2021, 5:12pm UTC


