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