|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Variables are temporary holders of information. They can hold:
(Note: As with most modern programming languages, JavaScript supports array variables in addition to the basic scalar variables used to hold the above data types. We'll concentrate on single-value variables for this column and devote a separate column to arrays.)
JavaScript variables "belong" to the script document that created them; the variables are lost when the document is unloaded. In addition, the contents of a variable are erased when you assign a new value to them. Though a variable created in one document script is not usually seen by another document script, JavaScript does provide ways to share variables between scripts. You do this by referencing the name of the document along with the name of the variable.
Several JavaScript instructions create and store variables, but the basic way to accomplish this manually is with the equals (=) assignment operator. The basic syntax is:
VariableName = value
The first argument is the name of the variable. Variable names can be very long, but you are restricted in the characters you may use. For more information on valid variable names, see the section on Variable name limits.
The second argument is the contents of the variable. You can put all sorts of stuff into a variable, including a number, a string, a math expression (such as 2+2), and various other things that we'll get to in a bit.
Pascal users may be tempted to construct the variable assignment using :=. Be aware that this syntax is not supported in JavaScript.
Following is a more specific rundown of the four most common contents you can place in JavaScript variables, including examples.
Numbers in variables
A number is one or more digits stored in the computer in such a way that JavaScript can perform math calculations with them.
JavaScript supports both integers and floating-point values. To place a number in a variable, just provide the variable name,
the equals sign (the variable assignment operator), and the value you want to use. For example, the following is what you
do to place the number 10 in a variable named MyVar:
MyVar = 10;
Strings in variables
A string is one or more text characters arranged in memory in single file. Strings can contain numbers (digits), letters,
punctuation, or a combination of these elements. Math calculations cannot be performed on strings. Strings are assigned to
JavaScript variables by being enclosed in a set of single or double quotes: