Miscellaneous Strict Warnings

Finally, lets take a look at some other odd strict warnings:

Error #1:


    "test for equality (==) mistyped as assignment (=)?"

We've all seen this one before.

var a = 3, b = 4
if (a = b) {

The above will fire the alert, because it sets a = b and returns a, instead of checking to see if a == b.

Error #2:


    "trailing comma is not legal in ECMA-262 object initializers"

var obj = { m1,m2, }

Note the last comma in the object definition. You don't need it and don't want it.

Error #3:


    "function eval must be called directly, and not by way of a function of another name."

This applies only to the eval() function, and you can reproduce it by:

e = eval;
For obvious reasons I don't think you need to worry about this one.

Error #4:


    "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;


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.