![[Image: 1xbAFr3.png] [Image: 1xbAFr3.png]](http://i.imgur.com/1xbAFr3.png)
Introduction:
> Javascript is client-side dynamic programming language. It syntactically resembles Java but being a scripting language such as VBS it is being interpreted rather than compiled. In Javascript every procedure is a function no matter whether it returns a value or not. Also, Javascript is case-sensitive which means that, for example, "A" is interpreted in one way and "a" in another.
Variables:
In Javascript we declare variables with the keyword var. You can also use variables without the need of declaring them:
Code:
Code:
var glblExample;
var glblExample = 1;
There are three types of variables:
- Integers - containing numeric values (e.g. 4,88,33)
- Strings - containing alpha values (e.g. keeper, hackforums)
- Booleans - containing logical operators (true() and false())
Code:
Code:
var Firstone = 7;
var Secondone = 19;
var Both;
var Both = Firstone + Secondone;
Code:
Code:
var Firstone = "7";
var Secondone = 19;
var Both;
var Both = Firstone + Secondone;
Creating objects:
The creation of objects in Javascript is done with the keyword new. The format is the following:
Code:
Code:
var Example = new ClassName;
Code:
Code:
var Example = new String('Keeper');
Code:
Code:
var Example = 'Keeper';
Arrays are objects that allow you to store a number of variables into a single one. In arrays you can assign the values to the variables and refer to them without the need of defining a new name for each one.
Simple Arrays:
Every array is an instance for the class Array. As we explained above, we create classes with the keyword new. Let's take a basic example of an array:
Code:
Code:
var Hackers = new Array(4);
Hackers[0] = 'Kevin Mitnick'
Hackers[1] = 'Robert Morris'
Hackers[2] = 'Steve Wozniak'
Hackers[3] = 'Adrian Lamo'
You can also declare the elements in the array the following way:
Code:
Code:
var Hackers = new Array('Kevin Mitnick', 'Robert Morris', 'Kevin Paulsen', 'Adrian Lamo');
Multi-dimensional arrays are arrays containing arrays. Let's say, we've decided to make our array a little bit more complex by adding another column to it, showing whether the hacker is blackhat, whitehat or grayhat. To create a two-dimensional array, we'll consider each line as a new array.
Code:
Code:
var Mitnick = new Array('Kevin Mitnick', 'Blackhat');
var Morris = new Array('Robert Moriss', 'Blackhat');
var Steve = new Array('Steve Wozniak', 'Whitehat');
var Lamo = new Array('Adrian Lamo', 'Grayhat');
var Hackers = new Array(Mitnick, Morris, Steve, Lamo);
Below are the comparison operators:
- == equality in values
- != inequality in values
- === equality, both in type of data and values
- !== inequality, both in type of data and values
- < less than
- > greater than
- <= less than or equal to
- => greater than or equal to
- ! NOT
- && AND
- || OR
If
The construction and purpose of the operator if is more than obvious.
Code:
Code:
if(condition){
construction 1;
construction 2;
}
Else
Else is an expansion for if. It defines the code, that is going to be executed if the value of the condition is false.
Code:
Code:
if(condition){
construction 1;
construction 2;
}
else {
construction 3;
construction 4;
}
The cycle for is a fundamental way for organising the repetition of the programming code.
Code:
Code:
function Keeper(){
for(a = 0; a < 5; a++){
document.forms[0].elements[0].value =
document.forms[0].elements[0].values + '\n' + "The value of a is: " + a;
}
}
The value of a is: 0
The value of a is: 1
The value of a is: 2
The value of a is: 3
The value of a is: 4
While
The purpose of the cycle while is the same as the one of for.
Code:
Code:
function Keeper(){
while(a < 5){
document.forms[0].elements[0].value =
document.forms[0].elements[0].values + '\n' + "The value of a is: " + a;
a ++;
}
}
Do while
do while guarantees at least a single repetition of the code. In this cycle the condition is placed after the code which is to be executed.
Code:
Code:
function Keeper(){
do {
document.forms[0].elements[0].value =
document.forms[0].elements[0].values + '\n' + "The value of a is: " + a;
a ++;
}
while (a < 5)
}
I tried to put it as most noob friendly as I could. I will for sure make a part 2 for the embedded objects and other stuff. For any questions leave a reply with them. Thanks for reading!