To Lecture Notes

IT 231 -- Jan 23, 2024

Review Exercises

  1. What is the difference between the =, ==, and === operators?
    Answer: = is the assignment operator. It assigns the value on the right side to the variable on the left. For example:
    var n = 25;
    
    == is the "tolerant" comparison operator. It returns true if the expressions are equal after converting then to number values. For example:
    3 == "3"
    
    returns true because 3 and "3" are equal after converting both to numbers.

    === is the strict comparison operator. It returns true if the expressions are equal and have the same datatype. For example:
    3 === "3"
    
    returns false because, although both expressions are equal to 3 when converted to numbers, they are different datatypes so the strict comparison operator declares them not equal.
  2. Rewrite these JavaScript statements using expression interpolation:
    var name = "Alice";
    var greeting = "Hello, " + name + ", how are you?";
    Answer:
    var name = "Alice";
    var greeting = `Hello, ${name}, how are you?`;
    
  3. What is the output of this script?
    function f(s, t) {
        return "*" + s + "*" + t + "*";
    }
    console.log(f("Illinois", "Wisconsin"));
    // Output:
    *Illinois*Wisconsin*
    
  4. Rewrite the return value of the function f in the preceding problem using expression interpolation. Answer:
    return `*${s}*${t}*`;
    
  5. Give some examples of string constants. Answer:
    "apple"  "123"  "!@#$%^&*()"  " " (space)  
    "" (null string = string of length zero)
    
    Single quotes can also be used for JavaScript strings:
    'apple'  '123'  '' (null string = string of length zero)  
    ' ' (space)  '!@#$%^&*()'
    
  6. How do you define a JavaScript array?
    Answer: Use square brackets ( [ ] ) to delimit the array and use commas to separate the array items, for example:
    var arr = ["dog", "cat", "mouse", "goldfish"];
    
  7. What is the JavaScript array-lookup operator?
    Answer: The array lookup operator is [ ]. For example, a[3] has the value "goldfish".
  8. What does it mean that JavaScript arrays are zero-based?
    Answer: It means that the index of the first item is zero = 0.

Practice Quiz 3a

Practice Problems

Anonymous Functions Example

Arrow Notation for Anonymous Functions