code in the below shown results of few conversions of data types using toString()
method.
all other data types can convert to strings using toString()
method but when try to convert object to string using toString()
method it gives odd result it is "[object Object]"
var b =1
b.toString();// produce "1"
var x=function(){var y=1;};
x.toString();// produce "function (){var y=1;}"
var z = [1,2];
z.toString();// produce "1,2"
var a = new Date;
//a = Date {Thu Dec 25 2014 22:44:32 GMT+0530 (Sri Lanka Standard Time)}
a.toString();// produce "Thu Dec 25 2014 22:44:32 GMT+0530 (Sri Lanka Standard Time)"
var obj = { name: 'John' }
obj.toString();// produce "[object Object]"
i wanna know when we try to convert object to string using toString()
method why it gives a odd result .
instead of giving "[object Object]" why wont toString()
method returns this value "{ name: 'John' }"