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