When I changed ‘prop’ (the value stored in the local variable) to something such as ‘things’ or anything I want name it causes the output ‘undefined’. What is this ‘prop’ and why I cannot change it to something different?
var result = myFunc(“Name”); used to call my function and if I changed the “Name” to “name” it causes the output to be ‘undefined’. Please tell me the reason why I cannot change “Name” to “name”?
The codes below outputs “David” but if you changed the parameter or the value of that local variable “prop” to something it will output “undefined”.
var someObj ={
propName: "David"
};
function myFunc(str){
var s = "prop";
return s + str;
}
var result = myFunc("Name");
console.log(someObj[result]);