Of course there cannot be "2 parameters in a typeof". One simple reason is this: typeof is, syntactically, operand, not a function, so, formally, it can have operand, no "parameters". Only one operand, no ifs no buts:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof[
^].
Moreover, having more then this only operand cannot make any sense.
The question makes no sense in the following sense: code can be right or wrong only if its purpose is known. Of course, it should be, in case of JavaScript, lexically correct. One wring comma or semicolon can make whole script invalid, not just the point with the error. (JavaScript is not the language which is executed one by one, as many mistakenly think; if the code has an error on lexical level, nothing executes, not even some correct part of it.)
Now, here is one problem with the type check you perform: for example, let's assume that some object is, say, string, but you could misspell the word 'string'. The check will always fail, even for strings, and nothing can tell you that the real reason is misspelled type name. So, I devised the following technique:
if (typeof message == typeof '') { }
[EDIT] I'll be very glad to see if someone suggests something better. [END EDIT]
At the same time, in nearly all cases, development should not rely on the type check. After all, JavaScript has too few types distinguished on this level. Even though I actually use the technique shown above, I only do it in some special cases, such as in my string formatting or object dump methods. It's better to rely on techniques where the type is exactly known.
For objects of the type 'object', you can check up that the two objects have the same origin checking up their constructors:
var obj1 = [1, 2, 3];
var obj2 = [4, 5];
var ofTheSameType12 = obj1.constructor === obj2.constructor;
function MyObject(id) { this.id = id; this.comment = 'some comment'; }
var obj3 = new MyObject(1);
var obj4 = new MyObject(200);
var ofTheSameType34 = obj3.constructor === obj3.constructor;
function MyOtherObject(id) { this.id = id; this.comment = 'some comment'; }
var obj5 = new MyObject(1);
var obj6 = new MyOtherObject(1);
var ofTheSameType56 = obj5.constructor === obj6.constructor;
var ofTheSameType56NonStrict = obj5.constructor == obj6.constructor;
—SA