Java Reference
In-Depth Information
empId = 100
salary = 1500.678
hexNumber = 97
octalNumber = 97
scientificNumber = 97
notANumber = NaN
posInfinity = Infinity
negInfinity = -Infinity
The Boolean Type
The Boolean type represents a logical entity that be either true or false. Like Java, Nashorn
has two literals, true and false , of the Boolean type:
Var isProcessing = true;
var isProcessed = false;
print("isProcessing =", isProcessing);
print("isProcessed =", isProcessed);
isProcessing = true
isProcessed = false
The String Type
The String type includes all finite, ordered sequences of zero or more Unicode characters.
A sequence of characters enclosed in double quotes or single quotes is known as a string
literal. The number of characters in the sequence is known as the length of the string.
The following are examples of using string literals:
var greetings = "Hi there"; // A string literal of length 8
var title = 'Scripting in Java'; // A string literal enclosed in single quotes
var emptyMsg = ""; // An empty string of length zero
A string literal can contain single quotes if it is enclosed in double quotes and vice
versa. If a string literal is enclosed in double quotes, you need to escape the double
quote using a backslash if you want to include a double quote inside the string. The same
is true for strings enclosed in single quotes. The following snippet of code shows you
some examples:
var msg1 = "It's here and now.";
var msg2 = 'He said, "He is happy."';
var msg3 = 'It\'s here and now.';
var msg4 = "He said, \"He is happy.\"";
 
Search WWH ::




Custom Search