JS Errors vs. Warnings

37 views
Skip to first unread message

Jonas Smithson

unread,
Dec 30, 2013, 12:05:19 AM12/30/13
to fir...@googlegroups.com
I'm not sure whether this is strictly a Firebug question or really a JavaScript question...

In the popdown menu under Firebug's Console tab, I normally keep Show JavaScript Errors enabled, and Show JavaScript Warnings disabled. Out of curiosity I just turned the Warnings on and reloaded a page I'm building. As before, the page shows no errors, but now it shows three warnings (with the exclamation mark in a yellow circle icon).

Two of the warnings say something like "TypeError: function foo does not always return a value".  I don't understand why that's an issue. Is a function required to always return a value? I never heard that. And why would that be a "type error" anyway? I associate type errors with something like trying to pass a non-number to something that needs a number, etc.

The third warning says "SyntaxError: in strict mode code, functions may be declared only at top level or immediately within another function". I never heard that either. In this case, I have a long, complex function with various nested functions and other code in logical order. It would be much less clear (to me, not to the computer) if I declared all the functions up top. And what does "immediately within another function" mean anyway?

What I also don't understand is that, as I said, these messages only appear when I turn on "Warnings", not when I just turn on "Errors"... so why do they have the word Error in the message, like "TypeError" or "SyntaxError"?

The code runs fine on every browser I've tested it on. Are these warnings -- or errors, or whatever the heck they are -- anything for me to be really concerned about?

Thanks, Jonas


Sebastian Zartner

unread,
Dec 30, 2013, 3:42:14 AM12/30/13
to fir...@googlegroups.com
I'm not sure whether this is strictly a Firebug question or really a JavaScript question...
Please note that these warnings come from Firefox. Firebug is just displaying them. So this is a JavaScript/ECMAScript question.
 
Two of the warnings say something like "TypeError: function foo does not always return a value".  I don't understand why that's an issue. Is a function required to always return a value? I never heard that. And why would that be a "type error" anyway? I associate type errors with something like trying to pass a non-number to something that needs a number, etc.
I can't the definition right now but the rule is to either have no return inside the function or to always have a return value. So this normally happens when you have a return statement within an if-block but not in the else-block.

The third warning says "SyntaxError: in strict mode code, functions may be declared only at top level or immediately within another function". I never heard that either. In this case, I have a long, complex function with various nested functions and other code in logical order. It would be much less clear (to me, not to the computer) if I declared all the functions up top. And what does "immediately within another function" mean anyway?
What I also don't understand is that, as I said, these messages only appear when I turn on "Warnings", not when I just turn on "Errors"... so why do they have the word Error in the message, like "TypeError" or "SyntaxError"?
That's specified by the ECMAScript standard. Strict errors are generally displayed as warnings inside Firebug.

The code runs fine on every browser I've tested it on. Are these warnings -- or errors, or whatever the heck they are -- anything for me to be really concerned about?
The Mozilla Wiki provides a detailed description about strict mode code restrictions.

Sebastian
Reply all
Reply to author
Forward
0 new messages