HTML and CSS Reference
In-Depth Information
Language basics
The JavaScript language relies on a solid standard, as defined by the ECMA-262 and ISO/IEC
16262:2011 papers. Unlike what happens with other popular programming languages like C#,
JavaScript code is not compiled before execution. Instead, JavaScript code is interpreted and then
executed on the fly. For this reason, JavaScript programs need a runtime environment (the engine that
translates and executes the code you write) in order to run. On the Windows 8 platform, JavaScript
is supported by a runtime environment named Chakra that, like the Buddhist force it is named after,
pushes vital energy throughout the body of HTML pages.
Note The majority of programming languages (such as C#, Visual Basic, C++, and Java) let
developers express an intended behavior by using a high-level syntax. The code expressed
in this way, though, must first be “compiled” to a lower-level language that is much closer
to the actual behavior of the machine. Put another way, the programming language
commonly used by developers is a mere abstraction over the behavior of the machine.
A classic compiled language needs a special tool—the compiler—to transform high-level
syntax into lower-level syntax. You can't run your program until you have successfully
compiled it. Other languages—such as JavaScript—are not compiled. This doesn't mean
they don't need any adaptation to run; a non-compiled (interpreted) language simply has
its “compilation step” performed during execution just before a given line is executed.
Let's now navigate through the basics of the language, digging out aspects of the type system, the
use of variables and functions, and good and bad programming habits.
The JavaScript type system
The JavaScript type system is composed of a few primitive types and a few built-in objects. When you
write JavaScript code, however, the range of types you can work with is actually much larger.
In addition to built-in objects, you can also rely on objects provided by the host as well as objects
you import from externally linked frameworks. For Windows 8 applications, in particular, you need to
import the Windows 8 JavaScript (WinJs) library—the gateway to the native Windows 8 application
programming interface (API).
This chapter, though, focuses on the native type system as defined in the aforementioned
JavaScript ECMA-262 standard definition.
Primitive types and built-in objects
In JavaScript, the primitive types are number, string, Boolean, undefined, Object and Function . Built-in
objects are Array, Math, Date, and RegExp, plus a few objects that are just functionally richer wrappers
for some primitive types. Such wrapper objects are named String, Boolean, and Number, and they just
add more capabilities to the corresponding primitive type.
Search WWH ::

Custom Search