Private variable vs local variable?


whats the different between private variable and local variable?


private variable is specific to a class and cannot be inherited. Any variable within a block is a local variable and hence it is mentioned explicitly as local.

var Test = function(){
    var test = 0;
    this.addOne = function(){
    this.showTest = function(){
        return test;

var newTest = function(){};

newTest.prototype = new Test();

var myTest = new newTest();

Seems like you can inherit them.

@kevinmogi Local variables are tied to the scope of a function and cannot be accessed from outside of it, and private variables are variables that are tied to the scope of an object, in the sense that you cannot access them from outside other than by using functions that are part of the object as well.