Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups

Tell us what’s happening:
What is the relation between var result = “” and result = lookup[val]; ? I’m more confused on var result="".

Your code so far
// Setup
function phoneticLookup(val) {
var 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;
}

// Change this value to test
console.log(phoneticLookup(“foxtrot”));


// Setup
function phoneticLookup(val) {
var 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;
}

// Change this value to test
console.log(phoneticLookup("foxtrot"));

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36.

Challenge: Using Objects for Lookups

Link to the challenge:

var result = ""; just declared the variable as an empty string. In the beginning it has no realtionship with lookup[val]; The relationship is created by the statement result = lookup[val]; Namely, that result now has the value of the property in lookup with the name saved in val

var result = ""; is very explicitly declared at the top, since it’s value gets test. There could simply be a var result; Or result could be declared later, together with the assignment: var result = lookup[val]; Arguably, the way it is written is more explicit and clearer, if not strictly necessary.

Hey Michael, thank you so much. This was a clear explanation and I feel good about it now.