运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript Global Variables</h2> <p>If you assign a value to a variable that has not been declared, it will automatically become a GLOBAL variable:</p> <p id="demo"></p> <script> myFunction(); // code here can use carName as a global variable document.getElementById("demo").innerHTML = "I can display " + carName; function myFunction() { carName = "Volvo"; } </script> </body> </html>