const friends = [
{
"fName": "mumu",
"lastName": "baru",
"langs": ["python", "r"]
},
{
"fName": "isfaq",
"lastName": "hussie",
"langs": ["js", "python"],
},
{
"fName": "mrX",
"lastName": "das",
"langs": ["c#", "java"]
}
]
function friendLang(name, prop) {
for (i = 0; i < friends.length; i++) {
if (friends[i].fName === name) {
return friends[i][prop] || "no such property"; \ Why does it work here
}
}
return "no such friend";
}
console.log(friendLang("mumu", "address"));
this returns no such property Why does the || operator work in the above code base but not in the following -
const friends = ["mumu", "mrX", "isfaq"];
function nameCheck(name) {
for (let i = 0; i < friends.length; i++) {
if (friends[i] === name) {
return `Yay ${name} exists!` || `Sorry, ${name} does not exist`;
}
}
}
console.log(nameCheck("mrY"));
this returns "undefined"
Where can I learn in depth about the usage of || operator in return scenarios and the different ways returns are put in place like the line return "no such friend"; in the first code base. I want to understand it completely.
I am sorry if the question or any part of this comes off as silly. Just getting started with Js