kindly enlighten me as I am new to javascript. I have sample 1 and 2 below and I wonder why sample 2 can't display the right expected result when keyword "return" is being used. I know plus(+) sign could solve the issue in question, just wondering when to used comma(,) for concatenation in javascript when it comes to variables.
sample-1
var person = {
firstName: "John",
lastName : "Smith",
fullName : function() {
console.log("my name is ",this.firstName +" ",this.lastName);
}
}
person.fullName(); //my name is John Smith
sample-2
var person = {
firstName: "John",
lastName : "Smith",
fullName : function() {
return "my name is ",this.firstName +" ",this.lastName;
}
}
person.fullName(); //"Smith"