please dont rip this site
Microsoft® JScript
JScript Variables
| Tutorial |

Variables are used in JScript to store values in your scripts. They allow a way to store, retrieve, and manipulate values using names that may help in understanding what a script does.

Declaring Variables

Although not required, it is considered good practice to declare variables before using them. This is done using the var statement. The only time you must use the var statement is when declaring variables that are local to a function. At all other times, using the var statement to declare variables before their use is a recommended practice.

Some examples of variable declaration:

var mim = "A man, a plan, a canal, Panama!";  //  The variable mim is cast to string type.
//  The sentence in quotes, the value of which is assigned to mim, is a string literal.

var ror = 3;        //  The variable ror is cast to numeric type.
var nen = true;        //  The variable nen is cast to Boolean type.

var fif = 2.718281828        //  The variable fif is cast to numeric type.

Variable names must be of a certain format:

JScript is case-sensitive, so the variable myCounter is different from MYCounter. Some examples of legal variable names:

Some illegal variable names:

A special case is provided for instances in which you want to declare a variable and, in some sense, initialize it, but not give it any particular value; this special case is the null value.

var zaz = null;
var notalot = 3 * zaz;        //  At this point, notalot becomes 0.
If you declare a variable without assigning any value whatever to it, it exists but is undefined.

var godot;
var waitingFor = 1 * godot;        //  Generates an error because godot is undefined.
You can declare a variable implicitly by assigning a value to it. You cannot, however, use a variable that has never been declared at all.

lel = "";        //  The variable lel is declared implicitly here.

var aMess = vyv + zez;        //  The variables vyv and zez have never been declared, and do not exist.
//  Their use generates an error at run-time.
As JScript is a loosely-typed language, variables in JScript technically have no type. They can be thought of has having a type equivalent to the data they hold. This is important for when variables holding differing types of data are used in the same expression. This is called coercion.


It is possible, under some circumstances, to force the automatic conversion (or coercion) of a variable or a piece of data into a different type. Numbers can easily be included in strings, but strings cannot be included directly in numbers, so explicit conversion functions, parseInt() and parseFloat(), are provided.

var theFrom = 1;
var theTo = 10;
var doWhat = "Count from ";
doWhat += theFrom + " to " + theTo + ".";        
After this code is executed, the doWhat variable contains "Count from 1 to 10." The number data have been coerced into string form.

var nowWhat = 0;
nowWhat += 1 + "10";        //  In this case, because "10" is a string  
                            //  the "+=" operator concatenates.
After this code is executed, the nowWhat variable contains "0110" because string data cannot be coerced into numeric form.

var nowThen = 0;
nowThen += 1 + parseInt("10");        //  In this case, "+=" adds.
After this code is executed, the nowThen variable contains the integer 11.

© 1996 by Microsoft Corporation.

file: /Techref/language/asp/js/306.htm, 5KB, , updated: 1996/11/22 11:12, local time: 2024/5/23 06:20,

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF=""> Microsoft&#174; JScript Language Tutorial </A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!