Why i cant use dot operator instead of [ ] while assigning result variable

Tell us what’s happening:

Your code so far

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

  // Only change code below this line
  var link = {
    "delta" : "Denver",
    result= link.val;
  // Only change code above this line
  return result;

// Change this value to test

Your browser information:

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

Link to the challenge:

link does not have a property val.

console.log(link[val]); //works
console.log(link["alpha"]); // works
console.log(link.alpha);  //works
console.log(link.val); // does not work

This (the object[] syntax) means “evaluate what is in the brackets”:


Object keys are strings, so JS will try to evaluate to a string.

So in phoneticLookup("charlie");, val is "charlie", so link[val] is going to evaluate to link["charlie"] which is the same as link.charlie. Notice how link.charlie is the last step.


Is saying look for a key named “val” on the object link. There isn’t a key called "val", as @alhazen1 says