Why doesnt return work in this situation? but console.log does work?


var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"

var mary = {
firstName: "Mary",
lastName: "Johnson",
phoneNumber: "(650) 888-8888",
email: "mary.johnson@example.com"

var contacts = [bob, mary];

// printPerson added here
var printPerson = function(person)
return person.firstName +" "+ person.lastName ;


because the exercise wants you to use return

return (function handing you something back) and console.log (logging something to the console) are very different things


thats the thing i dont understand, i have been having the impression that you can use return in a function and i expect it will work the same way as console.log....or u can use return to stop a loop in a while loop...i am very confused about this return thing...i need some examples to help me understand the diff


simplest example i can think of:

var example = function(){
    return "Hello world"
x = example()

the function example returns a string. so then when you call the function, i store whatever the function returned in a variable (x), which i then log to the console

so the function literal hand me something back (on which, if i want, i could do further manipulation)

console.log() only logs to the console


okay got it thank you very much :smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.