Miscellaneous Strict Warnings
Finally, lets take a look at some other odd strict
warnings:
Error #1:
We've all seen this one before.
var a = 3, b = 4
if (a = b) {
alert("true")
}
The above will fire the alert, because it sets a = b and
returns a, instead of checking to see if a == b.
Error #2:
var obj = { m1,m2, }
Note the last comma in the object definition. You don't need it and
don't want it.
Error #3:
This applies only to the eval() function, and you can
reproduce it by:
e = eval;
e("alert(1)");
For obvious reasons I don't think you need to worry about this one.
Error #4:
- JSMSG_USELESS_EXPR
"useless expression"
This one is also fairly rare, but you can see it from time to time if
you simply forget to do something with a variable on a line...
var y = function () {
var x;
x; // throws warning
x = 1;
}
y()
Conclusion
As you can see, strict warnings are really simple stylistic bugs. But
fixing them generally leads to better, more robust code and coding
practices. So, while you continue to study the science of JavaScript, take
the time to check your code for these minor faults. You'll find it helps
your coding ethic quite a lot.
|