Archive for October 1, 2007

Difference Between an Argument and a Parameter

Posted in JavaScript, Software, programming with tags , on October 1, 2007 by Joey

It is very common in the programming world for the terms argument and parameter to be used to convey the same meaning. Technically, however, there is a distinct difference between the two.

When a function is defined, the expected variables are listed in parentheses. These are parameters.

For example:

function GetSquarePerimeter(sideLength)
{
return 4*sideLength;
}

In the preceding example, sideLength is a parameter of the Square function.

When a function is called, there is a list of variables that are passed to the function. The evaluation of these variables results in values that are passed to the function. These are arguments.

For example:

var intSideLength = 4;
var intPerimeter = GetSquarePerimeter(intSideLength);

At runtime, when the intSideLength variable is evaluated to 4, it is an argument to the GetSquarePerimeter function call.

JavaScript this Keyword

Posted in Software, programming on October 1, 2007 by Joey

The ‘this’ keyword is indispensable in JavaScript object-oriented programming. When used in a JavaScript constructor function, ‘this’ refers to the object. Through the ‘this’ keyword, properties and methods can be assigned object, also known as a class. For example:

function Square(intSideLength)
{
this.sideLength = intSideLength;
}

In the preceding example the ‘this’ keyword is used to assign the variable ’sideLength’ as a property of the Square class.

The ‘this’ keyword is also frequently passed as a parameter on JavaScript events, such as when a checkbox is clicked. In such an instance, ‘this’ refers to the current object, the checkbox.