JavaScript Basics Tutorial

An overview of Javascript fundementals

Variables

JavaScript variables are containers for storing data values. The let keyword is used to define a variable that can be reassigned, and the const keyword to define a variable that cannot be reassigned. All JavaScript variables must be identified with unique names. Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume).

Example


    let greeting = "Hello";     //'let' means the variable can be reassigned. This a variable of a string datatype

    const question = "How are you";     //'const' means the variable cannot be reassigned

    let num = 7;    //this is a variable of a number datatype

            
All JavaScript variables must be identified with unique names. Identifiers can be short names (like x and y) or more descriptive names (age, sum, total, volume). The general rules for constructing variable names are:
  • Names can contain letters, digits, underscores, and dollar signs.
  • Names must begin with a letter
  • Names can also begin with $ and _
  • Names are case sensitive (y and Y are different variables)
  • Reserved words (like JavaScript keywords) cannot be used as names

Exercise

Follow the instructions below by filling in the missing spaces in the code.

  1. Create a variable called city, and assign it the value joburg
  2. create a varibale called age, and assign it the value 22
//1
let  = "";

//2
let  = ;

  try Again!
            
Home
Conditional Statements  next