源代码 :
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>开源教程(ossoft.cn)</title> </head> <body> <p>局部变量在声明的函数外不可以访问。</p> <p id="demo"></p> <script> myFunction(); document.getElementById("demo").innerHTML = "carName 的类型是:" + typeof carName; function myFunction() { var carName = "Volvo"; } </script> </body> </html>
运行结果