Java Reference
In-Depth Information
This is a useful way of dealing with long strings as it saves us from typing them over and
over again. It's also useful if the value stored in the variable is likely to change (hence the
name, variable).
You can declare and initialize a variable at the same time:
var name = "Jesse";
<< "Jesse"
You can also declare and assign values to multiple variables in a single statement:
var x = 2, y, z = "Hi!"; // y has only been declared, it's
<< undefined
String Properties and Methods
Primitive values and objects have properties and methods. Properties are information about
the object or value, while methods perform an action on the object or value―either to
change it or to tell us something about it.
Note: Object Wrappers
Technically, only objects have properties and methods. JavaScript over-
comes this by creating wrapper objects for primitive values. This all hap-
pens in the background, so for all intents and purposes it appears that prim-
itive values also have properties and methods.
We can access the properties of a string using dot notation. This involves writing a dot fol-
lowed by the property we are interested in. For example, every string has a length prop-
erty that tells us how many characters are in the string:
name = "Heisenberg"; // declare and assign a variable
<< "Heisenberg"
name.length; // call the length method on name
<< 10
Search WWH ::

Custom Search