obj is just the parameter name of the list function you are creating. It does not really matter. You can call it foo or object , or anything else that makes sense to you. The value of the argument that you pass to the call to the list function (above, namely friends ) is stored in the parameter in the scope of the function. That is, obj essentially becomes friends when working inside the list code.
prop is similar: it's just a variable that is created as part of the JavaScript for...in syntax. for in iterates over the property names of the object that is an argument to the in construct and stores them one at a time in prop . Again, you could call it whatever you want:
var list = function (foo) { for (var bar in foo) {
However, as I am sure you have learned, it makes sense to assign variable names to some values, so obj is short for an "object", since the list function works on any common object and prop not suitable for a "property".
Keep in mind that for...in iterates over property names. To access the correction value, you must use:
if (obj.hasOwnProperty(prop)) {
The search function does this, but without the recommended hasOwnProperty check.
source share