Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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["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'.


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.