You are here: irt.org | FAQ | JavaScript | General | Q1665 [ previous next ]
Parenthesis' hold optional parameters to be passed and received to and by a functions, object methods or object constructors. for example:
<script language="JavaScript"><!--
// first define a simple function:
function functionName(a, b) {
return a*b;
}
// invoke the simple function passing two values:
var c = functionName(2, 3);
//--></script>Square brackets are used in arrays to access an entry in an array either by its position (index) or by its name (associate arrays), for example:
<script language="JavaScript"><!-- // first define an array using the Array object constructor: var a = new Array(); // populate the first entry in the array: a[0] = 'Hello World'; // populate the array entry named 'x': a['x'] = 'dlroW olleH'; // retrieve the values using the window object's alert() method: alert(a[0]); alert(a['x']); //--></script>