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

HTML
CSS
JavaScript
PHP-MySQL
What attribute makes an option from <select> selected?
checked="checked" selected="selected" disabled="disabled"
<select name="a_name">
 <option value="val1">Option 1</option>
 <option value="val2" selected="selected">Option 2</option>
</select>
What CSS value allows to create color gradients for background?
contain repeat-x linear-gradient
#id {
  background: linear-gradient(top left, #1f1, #fff, #11f);
}
What statement creates an array in JavaScript?
[] {} new Object()
var arr = [1, "CoursesWeb.net", "MarPlo.net"];
alert(arr[2]);
Indicate the PHP function used to redirect to other page.
function() header() switch()
header("Location: http://coursesweb.net/");
exit;
Variables and Operators

Last accessed pages

  1. PHP PDO - Introduction and Connecting to Databases (666)
  2. Simple PHP Upload Script (708)
  3. CSS Border (517)
  4. Hide and Show simple effects (195)
  5. New Form elements and attributes in HTML5 (517)

Top accessed pages

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