Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | General | Q1665 [ previous next ]

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

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. ()?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.