Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1665 What is the difference between square brackets, i.e. [], and parenthesis', i.e. ()?

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>

Feedback on 'Q1665 What is the difference between square brackets, i.e. [], and parenthesis', i.e. ()?'

©2018 Martin Webb