Home
<!DOCTYPE html> <html> <body> <h1>Demo: JavaScript Variables without var</h1> <p id="p1"></p> <script> function myfunction(){ msg = "Hello JavaScript!"; } myfunction(); document.getElementById("p1").innerHTML = msg; // msg becomes global variable so can be accessed here </script> </body> </html>
Result: