2.2 - Variables

Review

Web browsers can run a scripting language called JavaScript. The syntax is very similar to C, C++, C#, Java, etc...

Last class we learned about something called the console.

2.2 - Variables

A shortened version of the lesson is below.

A more detailed lesson is in the repository:  2.2 - Variables

Synopsis:

Variables hold data in the memory of the computer.

let w = 2;

let apples = 7;

let myList = w + apples;  // sets the variable 'myList' to 9

console.log(myList);      // output the value of 'myList'

Note - you might see the keyword var being used online instead of let. You should always use let when creating a variable. I will essentially assume you cheated if I see var in your code.

Variables can be modified and reused:

When modifying the value of a variable you do not need to use the let keyword again - the variable already exists!

let age = 7;

age = 25;

age = age + 1;

Variables can be different types of data:

let my_number = -45;
let my_string = "Some text, in quotes";
let my_boolean = true;   // or false

Strings

Booleans

(Tutorial on variables) (w3schools reference)