Constants

Constants are a special kind of variable, store a value that never changes during the course of the program.
The syntax to create a Constant is:
`const CONSTANT_NAME:DataType = value;`
- "const" is the special keyword, reserved to define a constant.
As you can see, this syntax looks a lot like a variable declaration but with the var keyword replaced with "const".
Most programmers use all caps for the name of the constants to differentiate them from variables.
- Example (we define two constants and output their value):
```const BROTHER:String = 'Victor';
const BROTHER_AGE:uint = 33;

// output with "trace()" the value of these constants
trace(BROTHER+ ' - '+ BROTHER_AGE);     // in the Output panel will display:  Victor - 33
```
If you try to change the value of a constant, you get an error messages.

Operators

Operators are special symbols used to take one, two or more operands (values, variables, expresions) and return a value.
For example, the most known operators are: + (addition), and - (subtraction).
The operators can be used to change, combine and evaluate data in a script.
Operators can be divided into multiple groups:

Arithmetic operators

• 2 + 3 , var1 + var2
• -   - subtraction
• 2 - 3 , var1 - var2
• *   - multiplication
• 2 * 3 , var1 * var2
• /   - division
• 2 / 3 , var1 / var2
• %   - modulo (divides the first number by the second and returns the leftover portion only)
• 8 % 3 (return 2) , var1 % var2
When there's more than one arithmetic operator, the execution follows the arithmetic rules (will first execute multiplication, division or modulo, and then addition and subtraction, if you use Parentheses, their code will be evaluated first before moving on to other operations).
- Example:
```var num:Number = 3 + 4 * 5;         // result 23
var num:Number = (3 + 4) * 5;       // result 35
```

The "+" operator can also be used to join (concatenate) strings.
- Example:
```var str:String = 'ActionScript course ';
var str2:String = str + 'coursesweb.net';

trace(str2);          // ActionScript course coursesweb.net
```

Increment (++) and decrement ( – – )

Increment (++) and decrement ( – – ) operators are used to add or substract 1 from a number. They require only one argument:

```var num:Number = 15;
num++;         // 16
num--;         // 15
```

Compound arithmetic operators

The compound arithmetic operators provide a shorthand solution to performing arithmetic on numbers.
• +=
• var1 += nr; (equivalent to: var1 = var1 + nr; // "nr" can be a number or a variable)
• -=
• var1 -= nr; (equivalent to: var1 = var1 - nr; // "nr" can be a number or a variable)
• *=
• var1 *= nr; (equivalent to: var1 = var1 * nr; // "nr" can be a number or a variable)
• /=
• var1 /= nr; (equivalent to: var1 = var1 / nr; // "nr" can be a number or a variable)
• %=
• var1 %= nr; (equivalent to: var1 = var1 % nr; // "nr" can be a number or a variable)

Relational and equality operators

Relational and equality operators are used to compare two values and return true or false.
• >   - greater than
• 3 > 2 , var1 > var2
• <   -less than
• 2 < 3 , var1 < var2
• >=   - greater than or equal to
• 3 >= 2 , var1 >= var2
• <=   - less than or equal to
• 2 <= 3 , var1 <= var2
• ==   - equality
• 8 == 5+3 , var1 == var2
• !=   - inequality
• 7 != 5+3 , var1 != var2
• ===   - strict equality (both value and DataType)
• 8 === 5+3 , var1 === var2
• !==   - strict equality (both value and DataType)
• 8 !== "8" (the first value is a numeric type, the second value is String type), var1 !== var2
- the (=) operator is an assignment operator, assigns a value to a variable (e.g.   var a_name = 'value';).

Logical operators

The logical operators are used to compare multiple comparative statement.
• &&   - AND (return true if both expression are true)
• (2 <= 3) && (8 > 7)
• ||   - OR (return true if at least one of the expression is true)
• (2 >= 3) || (8 > 7)

Here is an example with some of the elements presented in this lesson (see the comments in code):
1. Open a new Flash document (ActionScript 3.0), right-click on Frame 1 and choose "Actions".
2. Add the following code in the "Actions panel":
```const SHAPE:String = 'square';     // declare a constant

// declare 2 variables
var side:int = 8;
var measure:String = ' pixels';

// apply operators to "side" variable
side += 3;     // equivalent to: latura = latura + 3;
side--;

// If "side" is greater than 8, apply "trace()"
if(side > 8) { trace(SHAPE+ ' - '+ side+ measure); }
```
3. Press "Ctrl+Enter" and see the result in the "Output panel".
- Displays: square - 10 pixels
- If the expression inside the parenthese of "if()" statement is true, the program executes the code between its curly brackets.

Daily Test with Code Example

PHP-MySQL
Which tag is used to add definition lists into a <dl> element?
<dt> <dd> <li>
```<dl>
<dt>HTML</dt>
<dd> - Hyper Text Markup Language</dd>
<dd> - Language for web pages</dd>
</dl>```
Which CSS property can hide an element on page, letting an empty space in its place?
display position visibility
```#id {
visibility: hidden;
}```
Click on the event which is triggered when the mouse clicks on an object.
onclick onmouseover onfocus
```document.getElementById("id").onclick = function(){
}```
Indicate the PHP variable that contains the contents of both \$_GET, \$_POST, and \$_COOKIE arrays.
\$_SESSION \$_GET \$_REQUEST
```if(isset(\$_REQUEST["id"])) {
echo \$_REQUEST["id"];
}```
Constants and Operators

Last accessed pages

1. Add, Change, and Remove Attributes with jQuery (33772)
2. Select in two MySQL tables (4217)
3. Ajax-PHP Rating Stars Script (12497)