js|jscript| Data | data type
Jscript has three primary data types, two types of composite data, and two special data types.
The primary (basic) data types are:
String
Numerical
Boolean
The composite (reference) data type is:
Object
Array
Special data types are:
Null
Undefined
String data type
A string value is a series of 0 or 0 Unicode characters (letters, digits, and punctuation marks) that are queued together. The string data type is used to represent text in JScript. The script can contain string literals that are placed in a pair of matching single or double quotes. Strings can contain double quotes, either with single quotes or single quotes, and double quotes on both sides of the double quotation mark. The following is an example of a string:
"Happy am I; From Care I ' m free! '
"Avast, ye lubbers!" roared the technician.
"42"
C
Note that there is no type in JScript that represents a single character. To represent a single character in Jscript, you should create a string that contains only one character. A string containing 0 characters ("") is a null (0-length) string.
Numeric data types
There is no difference between integer and floating-point values in JScript; a JScript value can be either of them (all the values within JScript are represented as floating-point values).
Integer value
Integer values can be positive integers, negative integers, and 0. Can be expressed in 10, 8, and 16. Most of the digits in Jscript are expressed in decimal notation. The prefix "0" indicates the 8-in integer value, which can contain only 0 to 7 digits. A number with a prefix of "0" that contains the number "8" or "9" is interpreted as a decimal number.
Plus prefix "0x" (0 and x| X) Represents a 16-in-integer value. Can contain numbers 0 through 9, and letters A through F (uppercase or lowercase). Use the letters A through F to represent a single digit of decimal 10 through 15. That means 0xF equals 15, while 0x10 equals 16.
Octal and hexadecimal numbers can be negative, but cannot have decimal places, and cannot be represented by scientific notation (exponent).
Floating-point value
A floating-point value is a number with a decimal part. It can also be expressed in scientific notation. This means that uppercase or lowercase "e" is used to represent 10 of the second party. The eight-byte IEEE754 floating-point standard that JScript uses numerically. This means that the number can be maximized to ±1.7976931348623157x10308, the smallest to ±5x10-324. Numbers starting with "0" and containing a decimal point are interpreted as decimal floating-point numbers.
Note that the number starting with "0x" or "00" and containing the decimal point will be an error. The following is an example of a number in Jscript.
Numeric description equivalent decimal number
.0001, 0.0001, 1e-4, 1.0e-4 four equal floating-point numbers. 0.0001
3.45e2 floating-point numbers. 345
42 integers. 42
0378 integers. Although it appears to be a octal number (starting with 0), 8 is not a valid octal number, so it is a decimal number. 378
3,778-In-system integer. Note that although it looks 1 smaller than the number above, the actual value is very different. 255
0.0001 floating-point numbers. Although it starts with 0, it is not a octal number because it has a decimal point. 0.0001
00.0001 error. The two-0 start is represented as octal, but the octal number cannot have a decimal portion. N/A (compilation error)
A 0Xff hexadecimal integer. 255
0X37CF hexadecimal integer. 14287
0x3e7 hexadecimal integer. Note that ' E ' is not considered an exponent. 999
0x3.45e2 error. Hexadecimal numbers must not have a decimal part. N/A (compilation error)
In addition, Jscript contains special value numbers. They are:
NaN (not a number). Used when doing mathematical operations on inappropriate data, such as strings or undefined values.
is infinitely large. In Jscript, if a positive number is too large, use it to represent.
Negative infinity. In Jscript, if a negative number is too large, use it to represent.
Positive 0 and minus 0. Jscript distinguishes between positive 0 and negative 0.
Boolean data type
Although string and numeric types can have countless different values, the Boolean data type has only two values. They are literal true and false. A Boolean is a truth value that represents the validity of a state (indicating that the state is true or false).
Comparisons in scripts usually get a Boolean result. Consider the next line of Jscript code.
y = (x = = 2000);
Here to compare whether the value of variable x is equal to the number 2000. If equal, the result of the comparison is a Boolean value of true and assigns it to the variable Y. If x is unequal to 2000, the result of the comparison is a Boolean value of false.
Boolean values are especially useful in structural control. You can combine a comparison that directly creates a Boolean value with a statement that uses that Boolean value. Consider the following example of a Jscript code.
if (x = = 2000)
Z = z + 1;
Else
x = x + 1;
When the Boolean value is true, the If/else statement in Jscript performs an action (so that z = z + 1), and another operation (x = x + 1) is performed when the Boolean value is false.
You can use an arbitrary expression as a comparison expression. Any expression with a value of 0, null, undefined, or empty string is interpreted as false. An expression of any other value is interpreted as true. For example, you can use an expression such as the following:
if (x = y + z)//This may not be the desired result – as follows!
Note that the above code does not check that x is equal to Y+z because only an equal sign (Assignment) is used. Instead, the above code assigns y+z to the variable x, and then checks to see if the entire expression has a zero value. To check if x is equal to Y+z, use the following code.
if (x = = y + z)//This is different from the code above!
For more information about comparisons, see procedures for controlling your program.
Null data type
Data type null has only one value in Jscript: null. Keyword NULL cannot be used as the name of a function or variable.
A variable containing null contains either "No value" or "no object." In other words, the variable does not hold a valid number, string, Boolean, array, or object. You can clear the contents of a variable by assigning a null value to it.
Note that in Jscript, NULL is not equal to 0 (unlike in C and C + +). It should also be noted that the typeof operator in JScript reports that the null value is of type Object, not type null. This potential confusion is for backward compatibility.
Undefined data type
Return the undefined value as follows:
object property does not exist,
A variable was declared but never assigned a value.
Note You cannot test whether a variable exists by comparing it to undefined, although you can check whether its type is "undefined". In the following code example, suppose the programmer wants to test whether the variable x has been declared:
This method doesn't work.
if (x = = undefined)
Make some action
This method also does not work-must check
string "Undefined"
if (typeof (x) = = undefined)
Make some action
This method works.
if (typeof (x) = = "undefined")
Make some action
Consider comparing the undefined value with null.
Someobject.prop = null;
The result of the comparison is true when the following conditions
If the attribute Someobject.prop contains a null value,
If the property someobject.prop does not exist.
To check whether an object property exists, you can use the new in operator:
if ("prop" in Someobject)
Someobject has attributes prop