According to below given code the output i expect is=> steve and bill. But the last object's data that is information about Bill also prints out automatically. how to stop it.? and why is that.?


var friends = new Object();
name: 'Steve',
company: 'Apple inc',
name: 'Bill',
company: 'Microsoft',

var list = function(groupName){
for(var names in groupName){


tl;dr: It's the console's problem. You won't experience it in normal web dev. Your code is fine.

Long answer:
The console shows the return value of the last statement, if you skip calling the list function (as you have currently done), then the last statement's value evaluates to bill object's information.

if you do call the list function, as here, then the last statement is list() and so the return value would be the value returned value by list, which is of course undefined, so nothing is seen in the console, except the value logged by console.log.


thanks @gaurangtandon :relaxed: