March 14, 2001 - Finding the Object's Value with valueOf()
March 14, 2001 Finding the Object's Value with valueOf() Tips: March 2001
Yehuda Shiran, Ph.D.
|
Object
object's method of valueOf()
. When the object consists of a number, like:
var myNum = new Number(35);
the valueOf()
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.valueOf());
}