Is This Guide For Me?
If any of these apply to you, you’ll benefit from reading this guide:
- You’ve never used a programming language before.
Ready? Let’s get started!
CodePen is a website that allows you to write code and make live demos, and it will be the easiest way to start following along and practicing.
A programmer writes programs, just as an author writes a book.
A comment is a human-readable note written in the code.
Comments are written in plain English with the purpose of explaining the code. Although comments don’t technically perform any function in the program, it’s crucial to get into the habit of proper documentation to help you or future collaborators understand the intent of your code.
- A single line comment, written as two forward slashes
//followed by the comment.
// This is a single line comment.
- A multi-line comment, which is sandwiched between
*/and can span many lines.
/* This is a comment. It's a multi-line comment. Also a haiku. */
A variable is a container that stores data values.
You know a variable as something that can change. In basic algebra, it’s a letter that represents a number.
x is a common variable name, but it can just as easily be represented by
z, or another name.
x has no value or meaning, but you can apply a value to it.
x = 5
5. You can think of
x as a container that’s storing
5, which is a number.
Variables are created and declared using the
var x = 5; // the variable x contains the numeric value of 5.
x), assigns the number data type (
5) with a single equals sign (
=), and explains it in plain English with a comment (
//). The statement ends with a semi-colon (
Variables only need to be declared with
var the first time they’re used, and as the name suggests, a variable can change.