Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why JavaScript returns [object Object] from valueOf() instead of [object]?

Tags:

javascript

Is there a specific reason that JavaScript returns [object Object] as a return value from valueOf() method?

Why not only [object] but [object Object] ?

like image 973
pencilCake Avatar asked Jun 06 '11 08:06

pencilCake


People also ask

Why is object object being returned?

[object Object] is a string version of an object instance. This value is returned by a JavaScript program if you try to print out an object without first formatting the object as a string. It's no wonder developers get confused about this object: there are no error messages or warnings that tell us what is going on.

What does this valueOf () return in JavaScript?

The valueOf() method returns the primitive value of the specified object.

What is the use of valueOf () method in JavaScript?

The valueof() method in JavaScript is used to return the primitive value of a number. This method is usually called internally by JavaScript and not explicitly in web code. Return Value: The valueof() method in JavaScript returns a number representing the primitive value of the specified Number object.


1 Answers

The second Object is the interface the object implements. For example, document.body.valueOf() would return [object HTMLBodyElement].

like image 189
duri Avatar answered Sep 23 '22 09:09

duri