Pages

Wednesday, September 7, 2016

Bonjour tout le monde! (JavaScript)

The Wikipedia article "Hello, World!" program (retrieved on 7 Sep 2016) begins by explaining a computer programming tradition:

A "Hello, World!" program is a computer program that outputs or displays "Hello, World!" to the user. Being a very simple program in most programming languages, it is often used to illustrate the basic syntax of a programming language for a working program. It is often the very first program people write when they are new to the language.
Each distinct language is unique (why?), so "Hello, World!" programs written in different languages also tend to be unique.

Writing and executing (i.e. running) a "Hello, World!" program in JavaScript, an interpreted language, is easy if you have access to a modern web browser. For example, in the version of Chrome that I'm using to compose this post, if I press the F12 key on my keyboard a curious looking frame appears on the right-hand side of my browser window. When I select Console on the toolbar in this frame I see, immediately below the toolbar, an error message (Uncaught TypeError:. . .) followed by a warning ('KeyboardEvent.keyIdentifier' . . .) followed by a command prompt. My Chrome browser window currently looks like this:


One JavaScript flavor of "Hello, World!" can be produced simply by typing the following command at the command prompt and pressing the Enter key. Try it!

alert("Hello, World!")

Here's another flavor. Try this one too!

alert('Hello, World!')

And another! Keep trying!!

alert('Hello, World!');

What's similar and different about each of these flavors of "Hello, World!"?

Here's yet another way of writing "Hello, World!" in JavaScript:

console.log('Hello, World!');

What happens when you execute that flavor (the one above)?