Monday, January 19, 2015

JavaScript toString() and valueOf() methods

toString() and valueOf() for the Object class

Object is the base class for every object in JavaScript. The Object class has two methods toString and valueOf that serve for conversion purpose and every JavaScript object inherits these two methods.
  • the toString() method returns a string representing that object
  • the valueOf() method returns a primitive value representing that object