MSc-IT Study Material
June 2010 Edition

Computer Science Department, University of Cape Town

Review Questions

  1. What is an array?

    You can find the answer end of the unit.

  2. What is the role of the number 4 in the line:

    Alert( myArray[4] );

    You can find the answer end of the unit.

  3. How many elements, and what are their indices, in the array ages created in the statement:

    var ages = new Array(3)

    You can find the answer end of the unit.

  4. Consider this code working with numeric variables:

           var a1 = 5;
           var b1 = a1;
    
           document.write( "<p> a1 = " + a1 );
    
           b1 = 7;
    
           document.write("<p> a1 = " + a1 );
       

    and this code working with array variables

            var a2 = new Array( 2 );
    
            a2[0] = 5;
            a2[1] = 6;
    
            var b2 = a2;
    
            document.write("<p> a2 = " + a2 );
    
            b2[0] = 7;
    
            document.write("<p> a2 = " + a2 );
       

    Browser output when this code is executed is as follows:

    Why is it that a2 is changed when b2 is changed, but a1 is not changed when b1 changes?

    You can find the answer end of the unit.

  5. Why does document start with a lower case in the statement:

    document.write("sorry, product out of stock"); 

    You can find the answer end of the unit.

  6. What output will the following code produce — try to work this out on paper, don't enter the code and try it out yet!

            <script src="triangle_class.js"></script>
    
            <script>
    
                var triangle1 = new Triangle(10, 20);
                var t2 = triangle1;
    
                t2.width = 5;
    
                document.write("triangle1 has width: " + triangle1.width );
    
            </script>
    	

    You can find the answer end of the unit.

  7. Are JavaScript objects just data structures?

    You can find the answer end of the unit.