CIT597 Quiz 4
Fall, 2002
Name_________________________________________
  1. Name the three primitive types in JavaScript.

    boolean, number, string

  2. Under what conditions will a==b be true but a===b be false?

    a and b are different types but can be cast to the same value

  3. If param="x" and expr="x*x", use these variables to create a function named square that returns the square of its argument.

    var square = new Function(param, "return " + expr + ";");


  4. In JavaScript, functions are "first class objects." Briefly mention two things that you can do with functions as a consequence of this fact.

    Assign a function to a variable
    Pass a function as an argument to another function


  5. Does the declaration  var a  declare a local or a global variable?

    If in a function, it is local, otherwise it is global


  6. True or false:
    1. Every variable is a property of an object TRUE

      .
    2. Every object belongs to a class. TRUE

    3. Every class has a prototype. TRUE

    4. JavaScript has a "wrapper class" for every primitive type. TRUE

    5. A method is a property whose value is a function. TRUE
    1. You can attach properties to a function. TRUE

    2. Within a method, this and callee refer to the same object. FALSE

    3. When embedded in HTML, JavaScript is not case sensitive. FALSE

    4. Anonymous functions cannot be recursive. FALSE

    5. Functions may be declared within other functions. TRUE
  7. What are the two possible values for the action method attribute of the HTML form tag?
    GET and POST

  8. Write the JavaScript to do each of the following:
    1. Assuming that x and y are variables, put the sum x+y into the HTML document.

      document.write(x + y);

    2. Load a new URL, given by the variable url, into the window.
      location = url;
      or
      window.location = url;
    3. In an HTML button, put up an alert box when the user clicks the button.
      <input type="button" name="someName" value="someValue" onClick="alert('someMessage');">
      Note: All parts are required; the semicolon is optional; note that single quotes must be used inside double quotes (or the other way around)