源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>局部变量carName不能从函数之外的代码访问:</p> <p id="demo"></p> <script> myFunction(); document.getElementById("demo").innerHTML = "carName的类型是 " + typeof carName; function myFunction() { var carName = "Volvo"; } </script> </body> </html>
运行结果