spacer
Yehuda Shiran May 5, 2002
Defining Constant Variables
Tips: May 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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.;
To learn more on JScript .NET, go to Column 108, JScript .NET, Part II: Major Features.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint