I have an object defined outside the function, in a global scope. This object is not passed into the function as an argument, but the function does modify it and return the
From your question this is how I think your code looks (more or less):
var o = {};
function f() {
o.prop = true;
return o;
}
o references an object.o you're modify whatever o references. Hence it modifies the original object.o you're returning a reference to the original object.Passing the object to a function results in the reference to the original object being passed. Hence any modifications will affect the original object. For example:
var o = {};
f(o);
console.log(o.prop); // true
function f(o) {
o.prop = true;
}