Page 109 - DCAP202_Fundamentals of Web Programming
P. 109
Fundamentals of Web Programming
Notes var obj3=new Boolean(“true”);
var obj4=new Date();
var obj5=new String(“9191 9999”);
document.write(Number(obj1));
document.write(Number(obj2));
document.write(Number(obj3));
document.write(Number(obj4));
document.write(Number(obj5));
Result:
123
0
1
1342720050291
NaN
For date object it returns the number of milliseconds since January 1,1970 UTC.
String()
String() function converts the object argument passed to it to a string value.
var obj1=new Boolean(0);
var obj2=new Boolean(1);
var obj3=new Date();
document.write(String(obj1));
document.write(String(obj2));
document.write(String(obj3));
Result:
false
true
Thu Jul 19 2012 23:28:08 GMT+0530 (India Standard Time)\
parseInt()
parseInt() function takes string as a parameter and converts it to integer.
document.write(parseInt(“50”));
document.write(parseInt(“77 days”));
document.write(parseInt(“this is 7”));
Result:
50
77
NaN
102 LOVELY PROFESSIONAL UNIVERSITY