The Grammar Hammer
About let
You use the let
keyword to tell JavaScript
you are making a new variable. Once the variable is created,
you do not need to use let
on that variable again.
In some older references, you will see var
used
instead of let
. You should use let
instead.
Later we will see why this is a better way of doing things.
Variables are just symbols you store data under. The rules for variable names are simple.
- The first character must be alpha or an _
- Subsequent characters can be alphanumeric or _
You will often see camel notation in JavaScript, which sets off words
with capital letters. Example: numberOfItems
. Your
python programming peers use snake notation that looks like
this: number_of_items
. Use variable names that
are evocative of their roles.
Semicolons A semicolon in JavaScript is like a period in English. It means a sentence has come to a full stop. All of the statements you learn about in this initial part of the course are called worker statements and they are complete senetences.
Therefore, they should end with a semicolon.
Making and Running JS Programs.
console.log
This function
prints stuff to the console. Let's do some exercises with
it. Make this file hello.js
.
//Program helloWorld.js
console.log("Hello, World");
To run it do the following.
- Open
empty.html
in your browser. - Copy the program.
- Paste the program into the console.
- Hit the enter key.
Often you will want to refresh the browser between runs, especially if you get error messages.