Page 201 - Web_Application_v2.0_C12_Fb
P. 201
Output of the preceding program is as follows:
Hello, Alice!! hello
Types of Functions
There are several types of functions in JavaScript, each serving different purposes and offering various
syntactic styles.
Built-in functions
Built-in functions in JavaScript are ready-made functions provided by the language. They help perform
common tasks such as converting data types, handling strings, or working with numbers, making coding
faster and more efficient.
Some built-in functions are as follows:
parseInt( ): Built-in function to convert to an integer.
parseFloat( ): Built-in function to convert to a floating-point number.
isNaN( ): Built-in function to check if something is Not a Number. For a number it returns False, otherwise
it returns true.
alert(“message”): If you want to make sure that information reaches the user, an alert box is commonly
utilised.
confirm(“message”): If you want the user to verify or accept information, a confirm box is frequently
utilised.
prompt(“message”): If you want the user to enter a value before seeing a page, a prompt box is frequently
utilised.
Example 11: To demonstrate the use of parseInt, parseFloat, and isNaN function
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>JavaScript Built-in Functions Example</TITLE>
</HEAD>
<BODY>
<H2>JavaScript Built-in Functions Demo</H2>
<SCRIPT>
// Using parseInt()
var intNumber = parseInt("42");
document.writeln("parseInt('42'): " + intNumber+"<BR>");
document.writeln(" Type: " + typeof intNumber + "<BR><BR>");
// Using parseFloat()
var floatNumber = parseFloat("3.14");
document.writeln("parseFloat('3.14'): " + floatNumber+"<BR>");
document.writeln(" Type: " + typeof floatNumber + "<BR><BR>");
// Using isNaN()
var checkNaN1 = isNaN("Hello");
JavaScript Part 2 199

