spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column108


JScript .NET, Part II: Major Features

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


Constant Variables and Objects

The const declaration is very common in other programming languages. It allows you to declare a variable as non-changing. The values of variables declared as const remain constant throughout the life of the application. The advantage of using the const declaration is in making the variable's maintenance a lot easier. When you debug a program, it's very helpful to know which variables can change and which variables cannot change. The syntax of the const declaration is as follows:


const name1 [: type1] = value1 [, ... [, nameN
  [: typeN] = valueN]];

where:

name1, ..., nameN 

are the names of the constants being declared. They are, of course, required. Also:

type1, ..., typeN 

are the types of the constants being declared. As mentioned in Page 2, the data types are optional in JScript .NET. Finally:

value1, ..., valueN 

are the values assigned to the constants. Here are some examples:

const index = 5;
const president : String = "Abraham Lincoln";
const factor : int = 35, twoThirds : float = 2./3.;

The constant variables above are all simple, in the sense that the data is stored directly in the address pointed to by the variable, and cannot be changed. When the variable references a complex data type such as the Object or the Array, only the reference to the data remains constant. The content of the Object or the Array can be changed. It allows you to keep the address of an object or an array fixed, and it also keeps you from deleting the reference to them. You can freely change the content of the object or each one of the array elements, but you cannot change the length of the array or the structure of the object. The following example declares an array of 12 objects of the Object data type (ECMAScript Edition 3):

const arrayOfObjects : Object[] = new Object[12];

Anywhere in the application you can assign a value to an element of the array:

arrayOfObjects[7] = "contentOfEighthElement";


Next: How to enumerate variables

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: April 22, 2002
Revised: April 22, 2002

URL: http://www.webreference.com/js/column108/3.html