Confused between when to use dot and when to use bracket notation

why are we using bracket notation instead of dot notation in

result = lookup[val];
  **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;
}

console.log(phoneticLookup("charlie"));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.

Challenge: Using Objects for Lookups

Link to the challenge:

Dot notation only works with the exact, character for character identical, property name. I.e. myOject.theExactPropertyName

The only way to access based on the contents of a variable is with bracket notation. I.e. myObject[varHoldingPropName]

ahaaaaaa yes!! yes!!

I got it I just solved a same challenge just a few days ago.
thank you so much!!!

1 Like

Uffdah, autocorrect made a mess of one of my examples. Fixed now!