In this tutorial you will learn the basics of programming, which are required to write a script. These notions are similar to those of PHP and other programming languages.

1. Using variables

In a script (or program) we use constants and variables datas. The variables can change their values during program execution. These data are called "variables".

The simplest way to use and refer to a variable is to write it. The name of the variable permits the access at its value and also can change the value if necessary.
You can create a variable and assign a value to it in this way:
- With statement var
var name = value;
- You can change its value just using the variable name (without "var"):
name = other_value;
Variable Types - Unlike other languages (such as Pascal or C), JavaScript has no fixed types of data, that allows you to change the type of a variable in the script, it can recognizes when the data is a string, numerical or other type.
For example:
var x = "xyz";
x = 8;
- Notice that the 'string' values (consisting of letters) are written between quotation marks (simples or doubles), and the 'number' can be written without quotation marks.

The life spam of a variable - A variable written within a function is a local variable, its value is recognized only within that function, it doesn't exist out of that function. Thus, another function can declare a variable with same name, JS (JavaScript) treats the two as different variables ( functions and working with it will be explained in a subsequent lessons ).
The variables created out of the functions can be used everywhere in that script, inclusively inside the functions and other JS script from that HTML page.

2. Operators

To work with datas in a script and manipulate variable values we use operators.
Operators are symbols and identifiers that determines how data are modified and how it is evaluated a combination of expressions and variables.

JavaScript recognizes: Operators are several types: These will be detailed in the next lesson.

Daily Test with Code Example

Which type of <input> creates a date input control, such as a pop-up calendar?
type="text" type="date" type="button"
<input type="date" name="set_date" value="2012-10-15" />
Which CSS property adds shadow effects to the text of an element?
font-style color text-shadow
h2 {
  text-shadow: 2px 3px 3px #a0a1fe;
Click on the function that adds new elements to the end of an array.
pop() shift() push()
var pags = ["lessons", "courses"];
pags.push("download", "tutorials");
alert(pags[2]);            // download
Which function sorts an array by key, in ascending order, maintaining key to data correlations?
asort() ksort() sort()
$lang = array(10=>"PHP", 20=>"JavaScript", "site"=>"");
var_export($lang);     // array ("site"=>"", 10=>"PHP", 20=>"JavaScript")
Variables and Operators

Last accessed pages

  1. PHP MySQL - SELECT, ORDER BY (1424)
  2. PHP Method Chaining (174)
  3. Script Users Register, Login, Online (3481)
  4. PHP MySQL Online Video Course and Tutorials (1074)
  5. HTML5 Quick Tutorial (676)

Top accessed pages

  1. PHP-MySQL free course, online tutorials PHP MySQL code (7718)
  2. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (7484)
  3. Get Attribute (ID, Class, Name, Title, Src) with jQuery (7201)
  4. PHP Chat Script (6635)
  5. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (6585)