# Editing JavaScript

HTML mode has support for editing JavaScript in HTML documents. HTML mode can color keywords in JavaScript and automatically indents the code. There is also a separate JavaScript mode for editing external JavaScript documents, see below.

The coloring of JavaScript keywords is not enabled by default. This because it is more convenient to have it disabled when you are not editing JavaScript. In the JavaScript preferences dialog you can change the default behavior. The following concerns JavaScript:

Electric left braces (see below for Alpha 7.1 and later)
When checked, the left braces, {, will be electric like in C mode. That { is electric means that a carriage return will automatically be inserted and the next line will be indented when you type {. However, the braces only behaves in this way between SCRIPT tags (and STYLE tags when you are editing CSS). Outside SCRIPT and STYLE tags typing { always just inserts a {. By default the {'s are electric.

Electric right braces (see below for Alpha 7.1 and later)
When checked, the right braces, }, will be electric like in C mode. By default the }'s are electric.

Note! If you do not use an American keyboard, you may have to tell Alpha which keyboard you are using. Otherwise the electric braces won't work. This is done in the dialog Config -> Global -> Preferences -> International.

Electric semicolon (see below for Alpha 7.1 and later)
When checked, the semicolons, ;, will be electric like in C mode. Just like the braces they are only electric between SCRIPT and STYLE tags. By default the ;'s are electric.

Color JavaScript keywords
If checked, keywords and comments in JavaScript will be colored. These keywords also include the event handlers. By default JavaScript keywords are not colored. Coloring of JavaScript keywords is not possible if 'simple coloring' is on.

Color of JavaScript keywords
The color of keywords in JavaScript. Applies only if you choose to color JavaScript keywords. The default is magenta.

Color of JavaScript and CSS comments
The color of comments in JavaScript and CSS. Applies only if you choose to color JavaScript or CSS keywords. The default is red.

Note! In Alpha 7.1 and later the preferences for electric braces and semicolons are set in the dialog Config -> Current Mode -> Menus and Features...

# JavaScript mode

JavaScript mode is intended for editing of external JavaScript documents (suffix .js). It may also sometimes be a better choice when you are editing JavaScript inside an HTML document. Select JScr in the mode menu in the status bar to manually switch to JavaScript mode.

The support in JavaScript mode is basically the same as within HTML mode: keyword coloring, indentation and electric braces and semicolons.

The funcs menu behaves differently in JavaScript mode. It lists all functions defined in the document and lets you quickly jump between them.

JavaScript has its own preferences, which you change via Config -> Current Mode -> Preferences... while you are in JavaScript mode.

## Cmd-double-click

Cmd-double-clicking on a keyword or builtin property or function makes Alpha jump to a JavaScript reference guide. This requires that you install the JavaScript reference for Alpha by Wolfgang Haeuptli.

The cmd-double-clicking also works in HTML mode.