Using Objects for Lookups

I understand converting the switch statement to an object but i have absolutely no idea what

let result = "";

or

result = lookup[val];

do for the code.

Below is the code before and after the task was answered.

" Convert the switch statement into an object called lookup. Use it to look up val and assign the associated string to the result variable."

// Setup
function phoneticLookup(val) {
  let result = "";

  // Only change code below this line
  switch(val) {
    case "alpha":
      result = "Adams";
      break;
    case "bravo":
      result = "Boston";
      break;
    case "charlie":
      result = "Chicago";
      break;
    case "delta":
      result = "Denver";
      break;
    case "echo":
      result = "Easy";
      break;
    case "foxtrot":
      result = "Frank";
  }

  // Only change code above this line
  return result;
}

phoneticLookup("charlie");

After

// Setup
function phoneticLookup(val) {
  let result = "";

  // Only change code below this line
  
  var lookup = {
    alpha: 'Adams',
    bravo:'Boston',
    charlie: 'Chicago',
    delta: 'Denver',
    echo:'Easy',
    foxtrot:'Frank'
  }
  result = lookup[val];
  // Only change code above this line
  return result;
}

When you call the phoneticLookup function, the argument will always be some sort of string.
It might an empty string, alpha, charlie, etc.
But it will be a string

so result starts off as an empty string

let result = "";

then you need to update result with the correct value based on the function call
that is why this is here

lookup is the name of the object.
then you need to use bracket notation to get the value here

if val is alpha, then it is the same as writing this

lookup["alpha"]

if value were bravo then it would be the same as writing this

lookup["bravo"]

and it would go on for the rest of the key names in the object.

but since we don’t know what val is and we want to reuse this function again and again, then we just pass in val like this

lookup[val]

instead of hardcoding values like this

lookup["alpha"]
lookup["bravo"]
lookup["charlie"]
lookup["delta"]
lookup["echo"]
lookup["foxtrot"]

Thanks, that solved it for me.