RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


JavaScript as a Foundation Language for Your Web Apps

Get an overview of the JavaScript programming language, from its basic structure and underlying paradigms to its high-level constructs, concepts, libraries, and functionalities—all of which are powering the current generation of web applications.

avaScript luminary Douglas Crockford defined JavaScript as "the world's most misunderstood programming language."

Characterized by some dubious design decisions, ambiguous syntax rules, and a troubled history (see Sidebar 1. A Brief History of Why JavaScript Makes Sense), JavaScript could have been dismissed as a second-class scripting language useful only for animating web pages. However, JavaScript has matured into one of the most ubiquitous and pervasive programming languages today, currently powering complex and highly interactive web applications. With JavaScript so widely distributed and so closely tied to the user experience, JavaScript skills are mandatory if you develop web applications nowadays.

This article explains why JavaScript is perfectly suited as a core, foundation language for your web applications. It introduces the lesser known and yet most powerful JavaScript features, and demonstrates how to leverage them to increase your productivity.

Even though you can use JavaScript in standalone interpreters and applications, this article concentrates on running it inside web pages. The following code shows the prototypical web page that you will write your code into throughout this article. It mimics a web application that you will enrich as you explore the features of JavaScript.

        // your code here

It makes no significant difference as far as the language goes whether it's standalone or inside a page, but using the web page simplifies setup and testing. You just need to load the above code in your browser to test the code.

Procedural Programming in JavaScript
JavaScript supports multiple programming paradigms. Just like C, you can adopt procedural programming and layer your instructions one after another. JavaScript does not have namespaces (although there are ways to mimic them), so everything lives in a global one. Inside such a namespace, you can define variables and functions and execute them as shown here:

// variable assignment
var a = 5;
var b = 10;

// global function definition
function adder(first, second) {
  return first + second;

// invocation
var result = adder(a, b);

// DOM Manipulation that changes the web page contents
document.write("The result is: " + result);

Notice that the code adopts some conventions that—even though not enforced by the interpreter—improve the reliability of the code. These include always declaring variables using the var keyword and always terminating statements with the semicolon.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date