Is it possible to create a private variable in a Javascript “object”?

asked by Caustic Dave from Michigan

Private variables can be created by using the ‘var’ syntax before defining the variable.
That limits its scope to within the object it was created in.

Example

function fName(){
   //functions are objects in javascript
   var firstname = “steve”;
   // firstname is a private variable for the object fName 
}

lastname = “albridge” ;
// lastname is a global/public variable 

Additional Reference

OOP in JS, Part 1 : Public/Private Variables and Methods
Private Static Members in Javascript
Private Members in JavaScript - Douglas Crockford