3 ms·
Except, now you have one that you expect and the other you don't. This doesn't make the language anything but more inconsistent. I prefer consistency inside a
by toolz 12y ago
Except, now you have one that you expect and the other you don't. This doesn't make the language anything but more inconsistent. I prefer consistency inside a language far more than familiarity between languages.
- ajanuary 12y agoRemember, it's not the function that's throwing the exception, it's the runtime. In order to make it not throw an exception, we'd have to special case typeof to make the runtime behave differently just for it. /That/ is inconsistent.
- erkl 12y agoThis throws an error: typeof x; // throws an error let x = 1; This doesn't: typeof x; // returns "undefined" var x = 1; While using variables before declaring them is bad practice, I think it's fair to argue that this behaviour is inconsistent.
- deleted 12y ago[deleted]
- ajanuary 12y agolet x = 0; function typeof_wrapper(y) { return typeof y; } (function() { typeof_wrapper(x); // throws an error let x = 1; })(); (function() { typeof_wrapper(x); // returns "undefined" var x = 1; })(); Again, typeof isn't throwing the error, the runtime is, because a variable declared with "let" is being referenced before the declaration. It's not inconsistent, it's one of the main points of "let". You're essentially arguing that a feature added because the old behaviour was undesirable is inconsistent because it's not exhibiting the old undesirable behaviour.
- deleted 12y ago[deleted]