GitHub Repository Submission

When using GitHub mode, paste your repository URL below and click Save URL to store it. The saved URL will be automatically included with every message you send until you choose to clear it. Learn more

Your GitHub repository URL is saved. LSBot will automatically fetch your latest code from this repository for each message. To change the URL, clear it first and save a new one.

Exercise 14

Identify all of the variables, object property names, primitive values, and objects shown in the following code (assume the code has not been executed). Don't panic if you miss a few items - this exercise is more challenging than it looks.

function hello(greeting, name) {
  return greeting + ' ' + name;
}

function xyzzy() {
  return { a: 1, b: 2, c: [3, 4, 5], d: {} };
}

const howdy = hello('Hi', 'Grace');
let foo = xyzzy();

Solution

  • Variables: hello, xyzzy, greeting, name, howdy, and foo. Remember that function names and parameters are variables. In addition, constants created with const are variables that can't be reassigned. Property names in an object are not variables.

  • Property Names: a, b, c, d. It's also worth noting that array indexes are property names, so 0, 1, and 2 are property names for the [3, 4, 5] array. (Don't worry if you missed the array indexes as property names.)

  • Primitive values: ' ', 1, 2, 3, 4, 5, 'Hi', and 'Grace' are the most obvious primitive values. It's worth noting that object property names are usually strings, and strings are primitive values. Thus, we should also include 'a', 'b', 'c', and 'd' in the list and 0, 1, and 2 for the array indexes of [3, 4, 5].

  • Objects: The functions hello and xyzzy are both objects, as are the following:

    • { a: 1, b: 2, c: [3, 4, 5], d: {} }
    • [3, 4, 5]
    • {}.

Since we didn't run the code, 'Hi Grace' is not one of the primitive values in this code. That primitive won't be created until we run the code.

Video Walkthrough

Hi! I'm LSBot. I can help you think through the selected exercise by giving you hints and guidance without revealing the solution. Your code from the editor will be automatically detected. Want to know more? Refer to the LSBot User Guide .

Detected solution
Loading...

Submit your solution for LSBot review.

Hi! I'm LSBot. Your code from the editor will be automatically detected. I'll review your solution and provide feedback to help you improve. Ask questions about your solution or request a comprehensive code review. Want to know more? Refer to the LSBot User Guide .

Detected solution
Loading...