Editor Arrow Download Open
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript local scope</title> </head> <body> <pre> <!-- Use pre element for work document.writeln() method --> <script type="text/javascript"> function myfun(){ // variable var greetings = "Good morning, have a nice day!"; document.writeln(greetings + '<br />'); //function function fun1() { document.writeln("Hello world!" + '<br />'); } fun1(); // object var myObj = { "commercial": ".com", "network": ".net" }; document.writeln(myObj.commercial); } myfun(); // Remove below comments and run it again //document.writeln(greetings); // undefined //document.writeln(myObj.commercial); // undefined //fun1(); // undefined </script> </pre> </body> </html>
  Preview Arrow