Microsoft® JScript™ Copying, Passing, and Comparing Data |
JScript Tutorial Previous | Next |
In Microsoft JScript, how data is handled depends on its data type.
Numbers and Boolean values (true and false) are copied, passed, and compared by value. When you copy or pass by value, you allocate a space in computer memory and put the value of the original into it. If you then change the original, the copy is not affected (and vice versa), because the two are separate entities.Objects, arrays, and functions are copied, passed, and compared by reference under most circumstances. When you copy or pass by reference, you essentially create a pointer to the original item, and use the pointer as if it were a copy. If you then change the original you change both it and the copy (and vice versa). There is really only one entity; the "copy" is not actually a copy, it's just another reference to the data.
Last, strings are copied and passed by reference, but are compared by value.
Note You can change this behavior for objects and arrays by specifying the assign( ) method for them.
Tip Because of the way the ASCII and ANSI character sets are constructed, "Zoo" compares as less than "aardvark." That is, capital letters precede lowercase ones in sequence order.
When you pass a parameter to a function by value, you are making a separate copy of that parameter, a copy that exists only inside the function. If, on the other hand, you pass a parameter by reference, and the function changes the value of that parameter, it is changed everywhere in the script.
When you perform a test by value, you compare two distinct items to see whether they are equal to each other. Usually, this comparison is performed on a byte-by-byte basis. When you test by reference, you are checking to see whether two items are pointers to a single original item. If they are, then they compare as equal; if not, even if they contain the exact same values, byte-for-byte, they compare as unequal.Copying and passing strings by reference saves memory; but because you cannot change strings once they are created, it becomes possible to compare them by value. This lets you test whether two strings have the same content even if one was generated entirely separately from the other.
© 1997 by Microsoft Corporation. All rights reserved.
file: /Techref/inet/iis/jscript/htm/js925.htm, 4KB, , updated: 1997/10/2 03:09, local time: 2024/11/28 04:04,
18.221.8.126:LOG IN
|
©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? <A HREF="http://sxlist.com/techref/inet/iis/jscript/htm/js925.htm"> Copying, Passing, and Comparing Data</A> |
Did you find what you needed? |
Welcome to sxlist.com!sales, advertizing, & kind contributors just like you! Please don't rip/copy (here's why Copies of the site on CD are available at minimal cost. |
Welcome to sxlist.com! |
.