To Lecture Notes

IT 231 -- Jan 25, 2024

Review Exercises

  1. What is the difference between a function and a method?
    Answer: A function is standalone; it is not called from an object or class. A method is called from an object or a class, for example
    parseInt("23412"); //<-- Function, which is standalone.
    Math.random( )     //<-- Method, called from the Math class.
    s.toUpperCase( )   //<-- Method, called from the String object s.
    
  2. What does the toString method do for an object? Test the toString method for an Array object.
    Answer: The toString method converts the object calling the toString method into a string. For example:
    var a = [4, 2, 6, 9, 2, 4];
    console.log(a.toString( ));
    // Output: 4,2,6,9,2,4
    
  3. What is an anonymous function? How do you use one?
    Answer: an anonymous function is a function without a name. To use an anonymous function just place the code for the anonymous function in place of the name of the function when passing it to another function. You can also assign an anonymous function to a variable to use later.
  4. What is arrow notation for functions?
    Answer: you use a fat arrow ( => ) instead of the function keyword to define the function. See the following two sections.

Two Rules for Writing Functions in Arrow Notation

  1. If the function has exactly one parameter, parentheses are not needed around the parameter. Otherwise parentheses are needed for the parameters. (Empty parentheses for zero parameters.)
  2. If the body of the function consists of a one-line return statement, curly braces are not needed for the body. Otherwise curly braces are needed (for no return statement or more than one line).

Review Exercises for Functions in Arrow Notation

SetInterval Example

Practice Quiz 3a

Looping over Array Items

Tutorial 2b

Using the HttpStatusCodes Module