Limitations
JS Console has some limitations you should be aware of when using the Code panel editor. These limitations are those of the underlaying Mozilla Midas editor.
Line length
Midas automatically introduces a line break (actually a break tag: <br />) when a line is longer than 128 characters.
Any line break is converted to new line (\n) before evaluating the code to run. So, if the new line character is occuring in the middle of a string, it will raise an unterminated string error.
The workaround is to take care to limit the length of your code lines to a value less than 128 characters (a good habit anyway as the code is easier to read), or to manually introduce the line break in the middle of the string and put a forward slash character (\) at the end of the line (the usual way to indicate a line break within a string in JavaScript).
Line break
HTML markup language uses the <br> tag to represent a line break. As mentioned in the previous limitation, any <br> tag in the code is converted to a new line before evaluating the code. So what to do if you want to use strings containing the <br> chain (to generate HTML content for instance)?
The workaround is to use a global constant (defined in the
jsconsoleuser.js file, located in your Mozilla profile directory) to represent the <br> tag. The constant provided is named
LINE_BREAK_TAG, and it can be use anywhere in your scripts (you can change this constant name if you want).
For instance, this code will raise an
unterminated string error:
var markup = '<div>A line break<br> in a div</div>';
But, this code will not:
var markup = '<div>A line break' + LINE_BREAK_TAG + ' in a div</div>';
Tabulations
When you type in a tabulation character, Midas automatically translates it to four non breakable space characters (entity ). This entity is converted to a normal space to avoid raising a syntax error when the code is run.
So if you need to use a string containing the chain, use another form to represent this entity, namely the   chain. There will be no conversion.
The NOBREAKSPACE_ENTITY is provided (defined in the jsconsoleuser.js file, located in your Mozilla profile directory) to represent this entity (you can change this constant name if you want).
Skipping Midas
The Code panel has very basic editing features, far from those provided by any descent text editor used to develop code.
If you want to take advantage of a powerful text editor (
jEdit for instance), you can write your scripts in this editor, save the file when you want to run the code, then switch to JS Console window and load the file in the Code panel where you can run it.
If you need to modify the code, go back to your editor, make the changes then, switching again to JS Console window, use the reload command to immediatly get the modified code in your Code panel and run it.
This way you can have a powerful editor to write the code and a powerful console to run it.
Report limitations
If you discover limitations not mentioned here, please report them sending a mail to JS Console mailing-list.
Use the context menu to navigate in the documentation pages