Deny variable declaration without var

How can I prevent variable declarations without using the var keyword? Can I install NetBeans to warn me about this?

For example, I need a warning or something like that:

 var testing = 5; // ... testin = 2; // Woops, typo! 
+4
source share
2 answers

I can think of at least a few possibilities for you. One of them is JSLint, as mentioned above. Another is to use a new Javascript function called "strict mode" ( described here among other places )

I heard that Firefox nightly builds now support strict mode, as well as pre-release versions of Chrome. Soon, all new browser versions will support it.

+2
source

I just stumbled upon this question and thought it was worth noting that ECMAScript 5 now has the "use strict" option. Just put "use strict"; (including quotation marks) along the line either at the top of your script (use it everywhere) or inside a function to just use it in one place. See http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ for more details. Very comfortably!

+1
source

Source: https://habr.com/ru/post/1337899/


All Articles