Call function inside a function in JavaScript

Description

The following code shows how to call function inside a function.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
<!--   w  ww. j a va  2  s . co  m-->
function get_added_text(textpart1,textpart2)
{
var added_text=textpart1+" "+textpart2;
return added_text;
}

function write_text()
{
var thetext=get_added_text("Hi","there!");
document.write(thetext);
}
write_text();
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Call function inside a function in JavaScript