<head>
section to assure that it is loaded by the browser before it is called. A function can be placed in this section also.
jscode.js
[c]
function displaymessage()
{
//all statements go inside curly braces
alert("Hello!! Welcome to SPLessons ");
}
//Calling the function explicitly
displaymessage();
[/c]
Output
If a function missed to give arguments(parameters) while calling the function, then the values are set to undefined.
[html]
<!Doctype html>
<html>
<head>
<script type="text/javascript">
//function with two arguments
function addNumbers(firstNumber,secondNumber)
{
var sum = firstNumber + secondNumber;
document.write("The Sum is ",sum);
}
//Only one argument 10 is passed
addNumbers(10);
</script>
</head>
<body>
</body>
</html>
[/html]
Output
[c]
The Sum is NaN
[/c]
"NaN" is nothing but Not a Number. Value 10 will be assigned to the first argument firstNumber and the second argument secondNumber will be undefined. Hence, the output will be NaN.