Java Reference
In-Depth Information
What is Javascript?
Having bought this topic, you are probably already well aware that JavaScript is some sort of
computer language , but what is a computer language? Put simply, a computer language is a series of
instructions that tell the computer to do something. That something can be one of a wide variety of
things, including displaying text, moving an image, or asking the user for information. Normally,
the instructions, or what is termed code , are processed from the top line downward. This simply
means that the computer looks at the code you've written, works out what action you want it to
take, and then takes that action. The act of processing the code is called running or executing it.
In natural English, here are instructions, or code, you might write to make a cup of instant coffee:
1.
Put coffee crystals in cup.
2.
Fill kettle with water.
3.
Put kettle on to boil.
4.
Has the kettle boiled? If so, then pour water into cup; otherwise, continue to wait.
5.
Drink coffee.
You'd start running this code from the first line (instruction 1), and then continue to the next
(instruction 2), then the next, and so on until you came to the end. This is pretty much how most
computer languages work, JavaScript included. However, on some occasions you might change the
flow of execution or even skip over some code, but you see more of this in Chapter 3.
JavaScript is an interpreted language rather than a compiled language. What is meant by the terms
interpreted and compiled ?
Well, to let you in on a secret, your computer doesn't really understand JavaScript at all. It needs
something to interpret the JavaScript code and convert it into something that it understands; hence
it is an interpreted language . Computers understand only machine code , which is essentially a string
of binary numbers (that is, a string of zeros and ones). As the browser goes through the JavaScript,
it passes it to a special program called an interpreter , which converts the JavaScript to the machine
code your computer understands. It's a bit like having a translator translate English to Spanish, for
example. The important point to note is that the conversion of the JavaScript happens at the time
the code is run; it has to be repeated every time this happens. JavaScript is not the only interpreted
language; others exist, including PHP and Ruby.
The alternative compiled language is one in which the program code is converted to machine code
before it's actually run, and this conversion has to be done only once. The programmer uses a
compiler to convert the code that he wrote to machine code, and this machine code is run by the
program's user. Compiled languages include C#, Java, and many others. Using a real‐world analogy,
it's a bit like having a Spanish translator verbally tell you in English what a Spanish document says.
Unless you change the document, you can use it without retranslation as much as you like.
Perhaps this is a good place to dispel a widespread myth: JavaScript is not the script version of the Java
language. In fact, although they share the same name, that's virtually all they do share. Particularly
good news is that JavaScript is much, much easier to learn and use than Java. In fact, languages like
JavaScript are the easiest of all languages to learn, but they are still surprisingly powerful.
 
Search WWH ::




Custom Search