A variable allows us to store values. In JavaScript before assigning values to a variable we have to declare that variable. A variable has a name, a type, value and scope. The value of a variable can change as the program is executed and that variable is modified. To declare a variable we use the reserved word var, then we give a name to our variable and assign a value to it as shown below.

  • var myname = “Jesus”;
  • var: Reserved word for variable declaration.
  • myname: Name of the variable.
  • = Assigment operator.
  • “Jesus” String value assigned to the variable.
  • ; End of statement.

Reserved Words

Reserved words are words that javascript uses as part of the programming language and this words cannot be used as variable name we cannot have a variable called var for example.

JavaScript Keywords

break case catch continue
debugger default delete do
else false finally for
function if in instanceof
let new null return
switch this throw true
try typeof undefined var
while with

JavaScript Types

Array Boolean Date Function
Math Number Object RegExp

JavaScript Object

Document Event Window

JavaScript Unused but Reserved Words

abstract boolean byte char
class cons double enum
export extend final float
goto implements import int
interface long native package
private protected public short
static super synchronized throws
transeint void volatile yield

Concatenation can be very useful when using variables we could have a program that displays the name imputed by a user.

        var name= prompt(“Enter your name”);
        Alert(“Welcome ” + name);