LearnFrenzy
Sign in Take a free test

JavaScript Basics · Predict the Output · Question 15

How Node.js prints arrays and objects Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 15 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
console.log([1, "two", true]);
console.log({ name: "Asha", age: 21 });
  • A [ 1, 'two', true ] { name: 'Asha', age: 21 } Correct
  • B 1,two,true [object Object]
  • C [1,"two",true] {"name":"Asha","age":21}
  • D [ 1, two, true ] { name: Asha, age: 21 }
Correct Answer: Option A

console.log inspects arrays and objects (strings shown in single quotes). "1,two,true" and [object Object] are what String() gives, and the JSON form comes from JSON.stringify().

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links