<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript named function scope</title>
</head>
<body>
<pre> <!-- Use pre element for work document.writeln() method -->
<script type="text/javascript">
function myfun(){
var greetings = "Good morning, have a nice day!";
//function
function fun1() {
document.writeln(greetings + '<br />'); // greetings is accessible on here
}
fun1();
}
myfun();
</script>
</pre>
</body>
</html>