JavaScript
supports all the structured programming syntax in C
(e.g., if
statements, while
loops, switch
statements, etc.). One partial exception is scoping:
C-style block-level scoping is not supported (instead,
JavaScript has function-level scoping). JavaScript 1.7,
however, supports block-level scoping with the let
keyword. Like C, JavaScript makes a distinction between
expressions and statements. One syntactic difference
from C is automatic semicolon insertion, in which the
semicolons that terminate statements can be omitted |
The DOM
interfaces for manipulating web pages are not part of
the ECMA Script standard, or of JavaScript itself.
Officially, they are defined by a separate
standardization effort by the W3C; in practice, browser
implementations differ from the standards and from each
other, and not all browsers execute JavaScript.
To deal with these
differences, JavaScript authors can attempt to write
standards-compliant code which will also be executed
correctly by most browsers; failing that, they can write
code that checks for the presence of certain browser
features and behaves differently if they are not
available .In some cases, two browsers may both
implement a feature but with different behavior, and
authors may find it practical to detect what browser is
running and change their script's behavior to match.
Programmers may also use libraries or toolkits which
take browser differences into account.
Furthermore, scripts will
not work for all users. For example, a user may:
- use an old or rare
browser with incomplete or unusual DOM support,
- use a PDA or mobile
phone browser which cannot execute JavaScript,
- have JavaScript
execution disabled as a security precaution,
- or be visually or
otherwise disabled and use a speech browser
To support these users,
web authors can try to create pages which degrade
gracefully on user agents (browsers) which do not
support the page's JavaScript.
|