March 9, 2001 - Finding the Object's Value | WebReference

March 9, 2001 - Finding the Object's Value

Yehuda Shiran March 9, 2001
Finding the Object's Value
Tips: March 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

When you want to get a uniform feedback about object names and content, the best way is to ask for their string version. Use the Object object's method of toString(). When the object consists of a number, like:

var myNum = new Number(35);

the toString() method returns the string "35". When the object is user-defined, the method returns [object Object]. Try it for the following Employee object:

function Employee() {
  this.dept = "HR";
  this.manager = "John Johnson";
}
function printProp() {
  var Ken = new Employee();
  alert(Ken.toString());
}