Functions in JavaScript
Built-in Functions
• JavaScript provides several built-in functions
that can be used to perform explicit type
conversions. Some of them are:
– eval(),
– parseInt()
– parseFloat()
Built-in Functions….
• The eval() function can be used to convert a string expression to a
numeric value
• The parseInt() function is used to convert a string value to an
integer.
• The parseInt() function returns the first integer contained in a
string or NaN(Not a number) if the string does not begin with an
integer
• The parseFloat() function is used to convert a string value to an
float.
• The parseFloat() function returns the first float contained in a
string or NaN(Not a number) if the string does not begin with an
float.
Passing Parameters to Functions
• When calling a function, some values can be
passed to the function; these values are called
arguments or parameters
Return values
• Javascript functions can return values using
return statement.
Class Work
H/W: Question 1: Why while loop is called top
tested and do…while loop is called bottom
tested?
Question 2: WAP to display the sum of even
numbers upto n where n is integer number
entered by the user
Question 3: WAP to display the sum of first
natural numbers upto n where n is the number
entered by the user