Page 351 - Webapplication11_C11_Flipbook
P. 351
Method Description Example
parseFloat( ) The parseFloat() method returns the first decimal number after parsing parseFloat(“20.45”)
a value as a string. NaN is returned if the initial character cannot be Output: 20.45
converted. parseFloat(“44 56”)
Output:44
eval( ) A JavaScript expression is passed as a string argument to this method. eval(“5*4”)
After that, eval( ) evaluates the expression and returns the result. It Output: 20
returns undefined if no result is received.
String A value is converted to a string. String(false)
Output: false
String(Boolean(1))
Output: true String(“65”)
Output: 65
Boolean Checks if an expression is true. Boolean(20 > 7)
Output: true
X=null; Boolean(X)
Output: false
Example:
<!DOCTYPE html>
<HTML>
<BODY>
<H1>JavaScript Global Methods</H1>
<H2>The eval() Method</H2>
<SCRIPT>
let x = 10;
let y = 20;
let text = "x * y";
let result = eval(text);
document.write(result);
</SCRIPT>
</BODY>
</HTML>
Output of the above code is as follows:
JavaScript Part 1 349

