The World's Most Misunderstood Programming Language: Chapter 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Chapter 

The World’s Most Misunderstood


Programming Language
In This Chapter
▶ Getting to know JavaScript
▶ Figuring out what JavaScript does
▶ Understanding why you need JavaScript

“People understand me so poorly that they don’t even understand my


complaint about them not understanding me.”
— Søren Kierkegaard

J avaScript hasn’t always been as highly regarded as it is today. Some


people have called it the best and worst programming language in the
world. Over the last few years, there have been a great number of improve-
ments made to the way programmers write JavaScript and to JavaScript
interpreters. These improvements have made JavaScript a much better lan-
guage today than it’s been in the past.

In this chapter, you discover what JavaScript is and a little bit of the history
of the language. You also find out what JavaScript does and why you need to
know it.

Don’t forget to visit the website to check out the online exercises relevant to
this chapter!
8 Part I: Getting Started with JavaScript

What Is JavaScript?
Back in the very early days of the web, browsers were simple readers for web
pages (see Figure 1-1). They had virtually no capabilities themselves, except
for the ability to display text in various sized fonts. As soon as Microsoft
released its Internet Explorer browser, the browser wars were on, and the fea-
tures started flying! One browser introduced the ability to display images, then
another introduced the capability to have different fonts, and then blinking
text, moving text, and all sorts of other wacky capabilities were introduced!

Figure 1-1:
The first
web brow­
sers weren’t
much to
look at.

It wasn’t long before someone got the idea that browsers could actually do
useful things themselves, rather than just acting as fancy document display
programs.

The Eich‐man cometh


JavaScript got its start back in 1995 at Netscape. The creator of JavaScript,
Brandon Eich, wrote JavaScript in record time (some say in as few as ten
days!) by borrowing many of the best features from various other program-
ming languages. The rush to market also created some interesting quirks (or,
less politely described, mistakes) in the design of the language. The result
is a sort of Esperanto‐like language that looks deceptively familiar to people
who are experienced with other programming languages.
Chapter 1: The World’s Most Misunderstood Programming Language 9
Mocha‐licious
The original name of JavaScript was Mocha. It was renamed LiveScript with
the first beta deployment of Netscape Navigator and was then changed to
JavaScript when it was built into the Netscape 2 browser in 1995. Microsoft
very quickly reverse‐engineered JavaScript and introduced an exact clone
of it in Internet Explorer, calling it Jscript in order to get around trademark
issues.

Netscape submitted JavaScript to the standards organization known as


Ecma International, and it was adopted and standardized as EMCAScript
in 1997.

Brandon Eich, the creator of JavaScript, famously commented about


the name of the standardized language; stating that ECMAScript was an
“unwanted trade name that sounds like a skin disease.”

Not only is ECMAScript an unappealing name for a programming language,


the name given to the language by Netscape and which most people refer
to it as, is rather unfortunate as well. If you already know how to program
in Java or if you learn how to at some point, it’s a very good idea to keep in
mind that the two languages may have some similarities, but they are, in fact,
quite different animals.

We need more effects!


When JavaScript debuted, it quickly became very popular as a way to make
web pages more dynamic. So‐called Dynamic HTML (DHTML) was an early
result of JavaScript being built into web browsers, and it enabled all sorts of
fun effects, like the falling snowflake effect (see Figure 1-2), pop‐up windows,
and curling web page corners, but also more useful things like drop‐down
menus and form validation.

JavaScript grows up
Now entering its third decade, JavaScript has become the world’s most
widely used programming language and virtually every personal computer in
the world has at least one browser on it that can run JavaScript code.

JavaScript is flexible enough that it can be used and learned by nonpro-


grammers, but powerful enough that it can (and is) used by professional
programmers to enable functionality on nearly every website on the Internet
today, ranging from single‐page sites to gigantic sites like Google, Amazon,
Facebook, and many, many others!
10 Part I: Getting Started with JavaScript

Figure 1-2:
JavaScript
made it pos­
sible to have
snowflakes
falling on
your web
page.

Dynamic scripting language


JavaScript is often described as a dynamic scripting language. In order
to understand what this means, we need to first define a couple of
terms and provide some context.

Common misconceptions about JavaScript


Over the years, JavaScript has had some pretty purely as a marketing strategy because
nasty things said about it. While sometimes Java was incredibly popular at the time
rumors are interesting, they aren’t always true. JavaScript came out.
The following list explains some common mis­
✓ Myth: JavaScript is new. Reality: JavaScript
conceptions about JavaScript:
has been around for over 20 years! Some
✓ Myth: JavaScript is not a real programming of the professional JavaScript program­
language. Reality: JavaScript is often used mers we know weren’t even born when
for trivial tasks in web browsers, but that JavaScript was created.
doesn’t make it any less of a programming
✓ Myth: JavaScript is buggy and runs
language. In fact, JavaScript has many
differently in different browsers. Reality:
advanced features that have raised the bar
While this used to be true in some cases,
for programming languages and are now
browser makers decided to support the
being imitated in languages such as PHP,
standardized version of JavaScript long
C++, and even Java.
ago. Every browser will run JavaScript the
✓ Myth: JavaScript is related to Java. Reality: same today.
Nope. The name JavaScript was invented
Chapter 1: The World’s Most Misunderstood Programming Language 11
Computer programs are sets of instructions that cause computers to do
things. Every computer programming language has a set of instructions and
a certain way that humans must write those instructions. The computer can’t
understand these instructions directly. In order for a computer to under-
stand a programming language, it needs to go through a conversion process
that translates human‐readable (and writable) instructions into machine
language. Depending on when this translation takes place, programming lan-
guages can be roughly divided into two types: compiled and interpreted (see
Figure 1-3).

Figure 1-3:
Program­
ming
languages
are clas­
sified
according
to when the
compilation
takes place.

Compiled programming languages


Compiled programming languages are languages in which a programmer must
write the code and then run it through a special program called a compiler
that interprets the given code and then converts it into machine language.
The computer can then execute the compiled program.

Examples of compiled languages include C, C++. Fortran, Java, Objective‐C,


and COBOL.

Interpreted programming languages


Interpreted languages are technically still compiled by the computer into
machine language, but the compiling takes place by the user’s web browser

You might also like