JavaScript Variables

JavaScript Variables

Summary: in this tutorial, you will learn about JavaScript variables and how to to declare the variables in JavaScript.

JavaScript Variables

A variable is a container/box for storing data values.

A JavaScript Variable is a box to store data

You give variable a name, then give it a value. When you call or use that name it will return what it has inside of it.

  1. Create a variable

To create a variable in JavaScript we use the keyword var like so:

var message = "Hello World";

a) the var is a JavaScript keyword

b) message is the variable name (you can name anything )

c) “Hello World” is a string data type (for now just remember it as plain text )

d) the semicolon ; just ends a JavaScript statement

So all together this: var message = “Hello World”; is called a statement.

Now let’s see what we have in this statement. Read the following.

1) Variable Declaration

When we wrote var message;
This is called variable declaration.
It’s just fancy word for saying create a variable
Remember that this is also a statement.

var message;

2) Assign Value

Now we can take the variable that we created var message;
and assign a value to it like so:

message = "Hello World";

When you assign you don’t have to type again because var is a JavaScript keyword, it recognizes that variable.

So here = is called the assignment operators.

That’s it for this tutorial. Watch the video from my Youtube Channel for practical use.

Leave a Reply

Your email address will not be published. Required fields are marked *