0

I am test JavaScript dictionary on node console as follows

$ node
> var dict = {};
undefined
> dict["t"] = "table";
'table'
> console.log(dict);
{ t: 'table' }
undefined
> dict["f"] = "field";
'field'
> console.log(dict);
{ t: 'table', f: 'field' }
undefined
> console.log(dict.t);
table
undefined
> console.log(dict.f);
field
undefined
> console.log(dict['f']);
field
undefined
> var str = "f";
undefined
> console.log(dict[str]);
field
undefined

The dictionary works fine but what are those "undefined" mean? What did I miss here?

Thanks,

3
  • 5
    The console prints out the value of the last expression evaluated. console.log() returns undefined, and similarly a var declaration results in undefined. Commented Apr 3, 2016 at 23:21
  • why var declaration would return undefined? Commented Apr 4, 2016 at 1:08
  • 2
    I guess that since it's a statement and not specifically an expression statement, the value is undefined Commented Apr 4, 2016 at 4:33

1 Answer 1

2

This comment should really have been an answer:

The console prints out the value of the last expression evaluated. console.log() returns undefined, and similarly a var declaration results in undefined. – Pointy

Sign up to request clarification or add additional context in comments.

2 Comments

So the undefined does not indicate any error and I do not have to try and get rid of the "undefined"?
@Shawn right - nothing's wrong with your code. It's just the console doing its thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.