Java Reference
In-Depth Information
The Null Type
The Null type has only one value that is called null . Even though the value null is
considered to be of primitive type, it is typically used where an object is expected but
there is no valid object to be specified. The following snippet of code shows how to use
the value null :
var person = null;
print("person is", person);
person is null
The Number Type
Unlike Java, Nashorn does not distinguish between integers and floating-point numbers.
It has only one type called Number to represent both types of numeric values. Numbers
are stored in a double-precision 64-bit IEEE floating-point format. All numeric constants
are called number literals. Like Java, you can represent number literals in decimal,
hexadecimal, octal, and scientific notations. Nashorn defines three special values of
number type: non-a-number, positive infinity, and negative infinity. In scripts, these
special values are represented by NaN , + Infinity , and -Infinity , respectively. The
positive infinity value can also be represented as simply Infinity , without a leading +
sign. The following snippet of code shows how to use number literals and special number
type values:
var empId = 100; // An integer of type Number
var salary = 1500.678; // A lfoating-point number of type Number
var hexNumber = 0x0061; // Same as 97 is decimal
var octalNumber = 0141; // Same 97 in decimal
var scientificNumber = 0.97E2; // Same 97 in decimal
var notANumber = NaN;
var posInfinity = Infinity;
var negInfinity = -Infinity;
// Print all values
print("empId =", empId);
print("salary =", salary);
print("hexNumber =", hexNumber);
print("octalNumber =", octalNumber);
print("scientificNumber =", scientificNumber);
print("notANumber =", notANumber);
print("posInfinity =", posInfinity);
print("negInfinity =", negInfinity);
 
Search WWH ::




Custom Search