Basic JavaScript - Using Objects for Lookups

Tell us what’s happening:
Describe your issue in detail here.

So I am just getting the jist of javascript but right now im just a little bit stuck and fixated on the role of the " " in the (result = " ") .
I was wondering if anyone can explain to me empty string and when to use it.

-Thank you very much!

Your code so far

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

  // Only change code below this line
   const lookup = {
        "alpha": "Adams",
        "bravo": "Boston",
        "charlie": "Chicago",
        "delta": "Denver",
        "echo": "Easy",
        "foxtrot": "Frank"
  result = lookup[val]

  // Only change code above this line
  return result;


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0

Challenge: Basic JavaScript - Using Objects for Lookups

Link to the challenge:

I think someone was just thinking about having a default, but never followed through with the idea. Personally I would have skipped that line and later just done:

return lookup[val] || ''

thereby ensuring that a string gets returned - it defaults to an empty string.

Don’t assume that the “hint” answers are good. Some of them are really bad and some don’t work. They aren’t maintained or updated.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Thank you very much, I see now, It does make sense, I’ve noticed that the " " always seems to get me confused more than anything. Thank you very much though, much appreciated.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.