Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Foundations Objects Basic Objects

Raymond LeDuc
Raymond LeDuc
2,499 Points

Why the double logs in the console?

// JavaScript Objects

var ray = { 
    name: "ray",
    skills: ['JavaScript', 'HTML', 'CSS' ],
    "favorite color": "blue"
    };

console.log(ray["name"]);
console.log(ray["favorite color"]);

in the console log will log it like: ray blue ray blue

Hi Raymond,

I added markdown to help make the code more readable. If you're curious about how to add markdown like this on your own, checkout this thread on posting code to the forum . Also, there is a link at the bottom called Markdown Cheatsheet that gives a brief overview of how to add markdown to your posts.

I copy / pasted your code into the JavaScript console, inside the browser's dev tools, and the output was one set of 'ray', and 'blue'.

Cheers!

1 Answer

Raymond - it's a little confusing but your code console.log(ray["name"]); - the portion ray["name"] evaluates to "ray". In plain english this code says "log to the console the value with the key "name" inside the object ray." Similarly console.log(ray["favorite color"]); is asking to log to the console the value inside the object ray which has a key of "favorite color". In this case this should result in "blue". I hope this helps.