What is JavaScript?

See more about:

A program is a set of instructions. For example, a human might make coffee in the morning by running the following program:

  • Empty the old coffee grounds from the coffee maker.
  • Find the container with the new coffee grounds.
  • Put four scoops of coffee grounds into the coffee maker’s basket.
  • Fill the coffee maker with water, to the 12-cup line.
  • Turn the coffee maker on.

We can describe this as follows:

  • The programming language is English.
  • The thing running the program is a human.
  • The purpose of the program is to make coffee.
  • The event that triggered the program was getting up in the morning.

For the programs you’ll be writing:

  • The programming language will be JavaScript.

A programming language defines what instructions you can give. In English, you can give the instruction “Empty the old coffee grounds.” But the instruction “Flargle the murping kringe blunks” makes no sense.

In JavaScript, the instruction alert('Your pants are on fire!') is legal, that is, it follows the rules of the language. But the instruction Flargle the murping kringe blunks makes no sense. You need to know what instructions you can give in JS.

  • The thing running the program is a Web browser.

Browsers run JS. Servers can too, but it’s unusual. They use other languages like PHP. In CoreDogs, all JS programs run in browsers.

JS programs have access to things that browsers know about, like headings, lists, and paragraphs. They don’t have access to things on the server side, like databases. If a JS program wants to get at a database, it needs to ask a server to do it.

There are edge technologies that let JS programs access databases and other things that are usually restricted to the server side. But they’re not well-developed. We won’t cover them in ClientCore.

  • The purpose of the program is to help the user.

That’s the bottom line.

  • The events that trigger the program will be things like the user clicking on a button.

You’ll bind your code to events like clicking.

Exercise: Program for dog walking

Imagine you’re a human (I know, it’s hard, but give it a try). Write a program for taking your dog for a walk.

(Log in to enter your solution to this exercise.)

What now?

On the next page, let’s see how you can include JS code on your page.


Lessons

User login


Dogs