Call a function defined later in JavaScript

Description

The following code shows how to call a function defined later.

Example


<!--from  ww w  .  ja  v a2 s  .  co  m-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
document.writeln(sum(10,10)); //call before defined
function sum(num1, num2){
return num1 + num2;
}
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Call a function defined later in JavaScript