A constant expression can always be degenerated to a simpler constant form.
For example 100 + 101 is a constant expression, but could be replaced by the value 202.
A constant expression involving strings is "abcdef" + "ABCDEF". This yields the result "abcdefABCDEF".
In JavaScript you should always try to avoid the use of string concatenation unless you really have to use it. It is very useful. However, in Netscape and MSIE, over-using a string concatenation in a loop can lead to significant memory leaks. It is quite easy to leak several megabytes of memory in a few minutes simply by concatenating strings and passing them to a document.write(). The garbage does eventually get collected, but not until the page is refreshed. This means that a page that implements a ticker for instance can leak horribly until the page is refreshed. There are techniques you can employ to minimize this effect and you could trigger a garbage collection by reloading the page periodically under script control.
Prev | Home | Next |
Constant | Up | Constraint |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |