The address for this web page is:
On to the next lesson!


To understand a programming language, you need to understand the data types supported by that language. In this lesson, we begin our study of JavaScript data types.



JavaScript supports a variety of data types:
  • Numbers (like 7 or 3.2 or -4.3e5)
  • Strings (like "cat" or 'Carol'; a sequence of characters inside single or double quotes)
  • Boolean values (true or false)
  • Objects (a collection of similar things)
  • Functions (to automate a desired sequence of operations)
  • Arrays (like [1,2,3])
Each of these is discussed in more detail in this lesson, or later lessons.


A literal is a specific data value that appears directly in a program. Here are examples of literals:
  • 12   (a number)
  • "12"   (a string)
  • 1.2   (a number)
  • "hello world"   (a string)
  • 'Hi'   (a string)
  • true   (a Boolean value)
  • null   (a special value that indicates "no value")


An identifier is simply a name given to something of interest. Identifiers are used to name variables, functions, and to provide labels for loops in JavaScript code.


  • first character must be an ASCII letter (uppercase or lowercase), an underscore (_), or a dollar sign ($)
    (Note: Numbers aren't allowed as the first character, so JavaScript can easily tell numbers and identifiers apart.)
  • subsequent characters may be any letter or digit, an underscore, or a dollar sign.
  • don't begin with two consescutive underscores: JavaScript often uses identifiers of this kind for internal purposes
  • Certain "reserved words" cannot be used as identifiers, because they have special meaning to JavaScript, e.g., if, true, while, and continue.


A primitive data type (number, string, or boolean value) holds a single data value. An object, on the other hand, is a compound data type: it collects many data values into a group and allows us to store and retrieve those values by name.

More precisely, an object is a collection of named pieces of data; the named values are usually referred to as properties of the object. We also need tools to work with the objects: these tools (functions) are called the methods of the object.

To refer to a property of an object, you put the object name, followed by a period, followed by the property name.

For example, if an object named   image   has properties named   width   and   height, then we would refer to those properties like this:

As a second example, to invoke the   write()   method (function) of the document object, you would write:
document.write("Hello there!");


All numbers in JavaScript are represented internally as floating-point values. (Think of a "floating-point value" as a decimal. In other programming languages, there is a distinction between integer values (...,-3,-2,-1,0,1,2,3,...) and other numbers.)

  • INTEGER LITERALS: all integers between -253 and 253 can be represented exactly
    An octal value begins with the digit zero. This is followed by an octal number: i.e., a sequence of digits, each between 0 and 7.
    For example, 012 is the octal name for the number ten.
    A hexadecimal value begins with   0x   or   0X  . This is followed by a hexadecimal number: i.e., a sequence of digits 0 through 9, or the letters a (or A) through f (or F). For example, 0A2 is the hexadecimal name for the number 162.
  • FLOATING POINT LITERALS: these use traditional scientific notation. Examples:
    3.14   -2.71   .12345   6.02e+23  6.02E+23   -1.3e-15


The   toString()   method is used to convert a number to a string. The argument of   toString()   (that is, the number inside the parentheses) gives the base of the desired output.

For example:

x = 10;
y = x.toString(8);
document.write("The value of y is " + y + "<BR>");
will give the octal (base 8) representation of the number ten:

The value of y is 12

Note: This result is NOT a number; it is a STRING!
Shorthand notation (the number MUST be in parentheses):
y = (10).toString(8);

Printable version of Index Card J3a

Printable version of Index Card J3b

Printable version of Index Card J3c

Printable version of Index Card J3d

Printable version of Index Card J3e

Printable version of Index Card J3f


(AJ3.1) Please continue with the tutorial located at:
Work through the first part of the lesson titled:
Using Buttons for JavaScripts
(You'll do the second part in tomorrow's class.) Be sure that you can do all the following:
  1. Write the code to put a button on your page. (This is a good review of some "Form" stuff!) Know how to label the button with desired text. Don't forget to assign a NAME to the button (if you ever want to refer to it).
  2. What does the attribute "onClick" do? Is it case-sensitive? Is "window.status" case-sensitive? Be able to write code that will make a desired message appear in the status bar at the bottom of the browser when you click a button. What happens if you put double-quotes (",") inside double-quotes (",")? Does it still work?
  3. Be able to write code that will change the background color when a button is clicked. Is "document.bgColor" case-sensitive?
  4. How can you GO SOMEWHERE when a button is linked? That is, how can you use a button as a link?
  5. Make a button that says "Click here to go to!" that takes you to  when it is clicked.
  6. Put your knowledge from the last lesson and this one together to do the following:
    WITHOUT LOOKING AT ANYTHING, be able to write the code that will create a button that does the following:
On to the next lesson!
© 2001 Carol J.V. Fisher    All Rights Reserved