Values and Variables

In JavaScript, a piece of information is a value. There are different kinds of values; the kind you’re most familiar with are numbers. A string value is characters—such as a word or words—enclosed in quotes. Other kinds of JavaScript values are listed in Table 1.2.

Table 1.2. Value Types
TypeDescriptionExample
NumberAny numeric value3.141592654
StringCharacters inside quote marks“Hello, world!”
BooleanTrue or Falsetrue
NullEmpty and meaningless 
ObjectAny value associated with the object 
FunctionValue returned by a function 

Variables contain values. For example, the variable myName is assigned the string “Dori”. Another way to write this is myName = "Dori". The equals sign can be read as “is set to.” In other words, the variable myName now contains the value “Dori”.

✓ Tips

  • JavaScript is case sensitive. This means that myname is not the same as myName, and neither is the same as MyName.

  • Variable names cannot contain spaces or other punctuation, or start with a digit. They also can’t be one of the JavaScript reserved words. See Appendix B for a list of JavaScript reserved words.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.164.228