Tuesday, December 17, 2013

JavaScript Tutorial 1 - Variables

To start off learning JavaScript the first thing to learn is what is a variable and how they are used. Variables are stated by using the "var" statement followed by the variable name. For example...

Var x = 20;

Variables can display three different types of data here is a list of all three...

var string = "text";

var boolean = true;

var float = 56.43;

Note whenever you use a string variable the text has to be enclosed by quotation marks.This is the basic syntax for Variables.

It can get more complicated though, you can set a variable to another variable like this...

var x = 78;
var y = x;
y = 78

Simple right? You can also set a variable to a user response using the prompt statement, it can be used like this...

var Q = prompt("What is your name?");

Now Q is equivalent to whatever the user types in.This should give you a basic idea of how variables work in JavaScript.

No comments:

Post a Comment