2
Microsoft’s terminology.
strongly recommend that you learn how to use your editor’s bracket-matching
feature.
Code folding
Somewhat related to bracket matching is code folding. Code folding refers to the
ability to temporarily hide code that’s not relevant to what you’re doing at the
moment, allowing you to focus. The term comes from the idea of folding a piece
of paper over on itself to hide unimportant details. Like bracket matching, code
folding is handled differently by different editors.
Autocompletion
Autocompletion (also called word completion or IntelliSense
) is a convenience
feature that attempts to guess what you are typing before you finish typing it. It
has two purposes. The first is to save typing time. Instead of typing, for example,
encodeURIComponent
, you can simply type
enc
, and then select
encodeURICompo
nent
from a list. The second purpose is called discoverability. For example, if you
type
enc
because you want to use
encodeURIComponent
, you’ll find (or “dis‐
cover”) that there’s also a function called
encodeURI
. Depending on the editor,
you may even see some documentation to distinguish the two choices. Autocom‐
pletion is more difficult to implement in JavaScript than it is in many other lan‐
guages because it’s a loosely typed language, and because of its scoping rules
(which you will learn about later). If autocompletion is an important feature to
you, you may have to shop around to find an editor that meets your needs: this is
an area in which some editors definitely stand out from the pack. Other editors
(vim, for example) offer very powerful autocompletion, but not without some
extra configuration.
A Comment on Comments
JavaScript—like most programming languages—has a syntax for making comments in
code. Comments are completely ignored by JavaScript; they are meant for you or
your fellow programmers. They allow you to add natural language explanations of
what’s going on when it’s not clear. In this book, we’ll be liberally using comments in
code samples to explain what’s happening.
In JavaScript, there are two kinds of comments: inline comments and block com‐
ments. An inline comment starts with two forward slashes (
//
) and extends to the
end of the line. A block comment starts with a forward slash and an asterisk (
/*
) and
ends with an asterisk and a forward slash (
*/
), and can span multiple lines. Here’s an
example that illustrates both types of comments:
4 | Chapter 1: Your First Application