CIT597 Answers to Quiz 3 (JavaScript)
Fall, 2007
Name_________________________________________

Please keep all answers short and to the point. Read each question and answer it; don't add information that wasn't asked for.

  1. (5 points) Within a function, how would you declare a new global variable x?

    By assigning it a value, without using the keyword var.

  2. (5 points) Within a function, how would you define a new local variable y (where y isn't a parameter)?

    var y       or     var y = value

  3. (10 points) Name the three primitive types in JavaScript.

    number, string, and boolean

  4. (5 points) What is the same about the way that the keywords class, int, and static are treated in a JavaScript program?

    They are all illegal.
    They would each result in a syntax error.
    They are reserved keywords, but have no meaning.

  5. (5 points) What does the keyword void do?

    Applied to any value, it returns the value:  undefined.


  6. (5 points) Why should JavaScript functions be defined in the <head> rather than in the <body> of an HTML page?

    So they are certain to be available when needed.


  7. (10 points) After executing the following three statements, what is the value of y?
         var f = function(x) { return x + 3; }
          x = 10;
          y = f;


    The function itself; that is, function(x) { return x + 3; }


  8. (5 points) Write a literal array containing the values "CIT" and 597, and assign it to a variable array.


    array = ["CIT", 597]     or     var array = ["CIT", 597]

  9. (10 points) What does arguments.callee refer to?

    The function that was called with these arguments.


  10. (10 points) Tell two things you can do with a previously defined function func that you cannot do in Java.

    Assign it to a variable.
    Assign it to a property (instance variable).
    Pass it as a parameter.
    Assign properties to it.

  11. (5 points) In the HTML DOM, document is a field of what object? (Give its exact name, as it would appear in a program.)

    window

  12. (15 points) Name any three of the arrays in a document object.

    anchors, applets, embeds, forms, images, links


  13. (5 points) In order to refer to a button object without having to count out its position in an array, the button tag should be given an attribute named    name .

  14. (5 points) What is the easiest way to show a debugging message from a JavaScript program?

    Display an alert.