Home > Articles > Programming

  • Print
  • + Share This
This chapter is from the book

Giving Computers Programs

Figure 1.2 shows the code for a simple program that creates a web page with an interactive button, all created by a computer programmer. As a matter of fact, that computer programmer is about to be you after you create the code using JavaScript. JavaScript is a programming language that enables you to improve websites by letting you customize the look and feel of your site’s presentation, increasing interaction with your website users, and validating any data they enter. You may think JavaScript is specifically for web masters and site designers, but it’s a simple language and learning its basics can help you learn basic programming concepts.

FIGURE 1.2

FIGURE 1.2 A program’s instructions are somewhat cryptic, but readable by people.

Another advantage to JavaScript is that most programming languages need you to install an interpreter or compiler on your computer in order to execute your code. With JavaScript (and HTML), you only need a text editor. You type in your code, save it with an .html extension, and then open the saved file with your web browser.

A computer is only a machine. To give a machine instructions, your instructions might be fairly readable, as Figure 1.2’s are, but the code (another name for a program’s instructions) must be fairly rigid and conform to a predefined set of rules and regulations according to the programming language you use. Therefore, to write a program in the JavaScript programming language, you must conform to JavaScript’s rules of proper command spelling and placement. This programming language grammar is called syntax. (And you thought syntax was just a levy placed on cigarettes and liquor!)

Despite its name, JavaScript is not tied to the Java programming language (which is covered in Part III, “Object-Oriented Programming with Java,” of this book). In fact, the name has caused some confusion as computer fans thought that JavaScript was either an extension or spin-off of Java, but it got the name because Java was a hot new language at the time, and some thought the connection of the scripting language to the web development language would benefit the adoption and growth of JavaScript. Misleading name aside, the more you learn JavaScript, the more easily you will be able to learn additional programming languages. Although computer languages have different goals, syntaxes, and reasons for being, they are often similar in structure.

Source Code

Even after you make the effort to learn a computer language such as JavaScript, and after you go to the trouble of typing a well-formed and syntactically accurate program such as the one in Figure 1.2, your computer still will not be able to understand the program! The program you write is called source code. It is the source code that you write, manipulate, and correct. Your computer, on the other hand, can understand only machine language, a compact series of computer-readable instructions that make no sense to people. They make sense to some advanced computer gurus, but my general assertion stands that they don’t make sense to people.

Listing 1.1 shows machine language. Can you decipher any of it? Your computer can. Your computer loves machine language. Actually, it’s the only language your computer understands. And different computers understand their own version of a machine language so what works on one type of computer will not necessarily work on another. It’s best to stay away from machine language and let products such as JavaScript convert your higher-level language into machine language’s cryptic 1’s and 0’s. To convert source code such as your JavaScript program to machine language, you need an interpreter (or for other languages, a compiler).

LISTING 1.1 Machine language is extremely difficult for people to decipher.

01100100
10111101
10010011
10010100
00001111
01010101
11111110

All programs you run on your computer, phone, or tablet, including Microsoft Word, Internet Explorer, and programming languages, are already converted into machine language. That’s why you can click a program’s icon and the program begins immediately. No interpretation or compilation is required. By providing you with the machine language only, software vendors serve two purposes:

  1. They give you programs that execute quickly without the intervening compiling step.
  2. They ensure that you don’t change the source code, thereby protecting their intellectual property.
  • + Share This
  • 🔖 Save To Your Account