不在JavaScript中声明变量时会发生什么?

是的,可以这样做。具有全局作用域时,可以使用变量而无需声明它。下面的“ no var”变量“ points”将查看作用域链,不使用wince var关键字-

<html>
   <body>
      <script>
         var rank = 5;
         points = 50;
         marks = 300;
         //匿名功能
         (function() {
            points = 100; //overwrites global scope points
            var rank = 4; //new rank variable is created in this' function's scope
            var marks = 900;
            document.write(rank+"\r\n"); //prints 4
            document.write(points+"\r\n"); //prints 100
            document.write(marks+"\r\n"); //prints 900
         })();
         document.write('<br/>');
         document.write('<br/>');
         document.write(rank+"\r\n"); //prints 5
         document.write(points+"\r\n"); //prints 100
         document.write(marks+"\r\n"); //prints 300
      </script>
   </body>
</html>