Function in programming language can be called anywhere in a program and it can be used again and again in the entire program you have to make a function once and you can call that function whenever you want. The programmer need not write the same code again and again it allows the programmer to divide the whole program into the small functions.
Like other languages, JavaScript supports to write code using functions. JavaScript have predefine functions but it also provide the feature top write your own functions as well.
FUNCTION DEFINITION
Before writing a function in JavaScript we need to define it. With the help of function keyword we define JavaScript function followed by a different function name with list of parameters (it can be empty as well) and a block with the curly braces in which the function is defines. Example of creating a function in Javascript
<script type="text/javascript">
function sayJavaScript()
{
alert("JavaScript function");
}
</script>
Predefine Functions
valueOf()-It return the primitive value of object.
parseInt()-this function parses a string and returns an integer.
parseFloat() - this function parses a string and returns a floating point number.
isNaN(value) - this function determines whether a value is an illegal number (Not-a-Number).
This function returns true if the value is NaN, and false if not.
eval()-this function evaluates or executes an argument.
eval() evaluates the expression, if the argument is an expression . eval() executes the statements if the argument is one or more JavaScript statements.
escape(string)- this function encodes a string.
A string portable can be made portable with this function, so it can be transmitted across any network to any computer that supports ASCII characters.
String() -this function converts the value of an object to a string.
0 Comment(s)