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 tag is used to include external CSS file in web page?
<body> <script> <link>
<link href="/templ/style.css" rel="stylesheet" type="text/css" />
Which CSS property sets the text size?
font-weight text-decoration font-size
h2 {
  font-size: 1em;
Indicate the JavaScript property that can add HTML code into an element.
text value innerHTML
document.getElementById("someID").innerHTML = "HTML content";
Click on the function that returns the number of characters of a string in PHP.
count() strlen() stristr()
$str = "";
$nr_chr = strlen($str);
echo $nr_chr;       // 22
Variables and Operators

Last accessed pages

  1. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (9426)
  2. Get the Timestamp of First and Last day of Month (170)
  3. Get the value of the selected /checked checkboxes in a form (6252)
  4. PHP Chat Script (9768)
  5. Check the file type before Upload (1518)

Top accessed pages

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