Type Casting - Part 4

Notes:

JavaScript eval() function:

eval(value) :
As a name itself indicating, eval function tries to evaluate the given value and returns a number.
Otherwise returns an error.

Where:
Value can be: a number, expression, string, or JavaScript statement.
Ex:
document.write(eval(2)); //2
document.write(parseInt(2)); //2
document.write(parseFloat(2)); //2
document.write(eval(3.142)); //3.142
document.write(parseInt(3.142)); //3
document.write(parseFloat(3.142)); //3.142
document.write(eval(2+2)); //4
document.write(parseInt(2+2)); //4
document.write(parseFloat(2+2)); //4
document.write(eval(1.6+1.6)); //3.2
document.write(parseInt(1.6+1.6)); //3
document.write(parseFloat(1.6+1.6)); //3.2
document.write(parseInt("24sometext")); //24
document.write(parseFloat("24sometext"));//24
//document.write(eval("24sometext")); //error
document.write(parseInt("2+2")); //2
document.write(parseFloat("1.6+1.6")); //1.6
document.write(eval("1.6+1.6")); //3.2
document.write(eval("var a=10,b=20,c=a+b;c;"));//30

Interview Questions: