Question: I have found different behavior of code when function is called / returned in different ways. It is quite confusing. So to clear my doubts I have stripped down the whole code to minumum:

Let us consider a simple function:

```
function f()
{
   //some code
}

var objf = f();

```

**Q1. Now `objf` is undefined. Why? What does `f()` returns?**

```
function f()
{
   //some code
   return this;
}

var objf = f(); 

```

**Q2. What does `f()` returns? global object?**

Answer: 
Q1. Functions in javascript always return values. The default value is `undefined`, except for constructors, where the default return value is `this`. Since no return value is specified in your Q1 example, the interpreter returns the default value, `undefined`.

Q2. `this` is a javascript keyword that gets updated by the interpreter depending on application context. In the case of a function that is not called from an object, as in your Q2 example, `this` will refer to the global object.

[How does the "this" keyword work?](https://stackoverflow.com/questions/3127429/javascript-this-keyword)
When you do...

```
function f()
{
   //some code
}

var objf = f();

```

...you're getting the return value of the "f" function, which in this case is undefined, once there's no "return something" statement.

If you do...

```
function f()
{
   //some code
}

var objf = new f();

```

...you'll instance a new object based on the "f" function prototype. Your objf variable will receive a new object reference, even if your "f" function is empty.

And doing this...

```
function f()
{
   //some code
   return this;
}

var objf = f(); 

```

..."this", in your case, will be the global object, that's the window object for browsers. 
The this keywork is a reference to the object to which the function is bound, look at this:

```
someobj = {
  f:function(){
    return this;
  }
}

var objf = someobj.f();

objf === someobj; //==>true!!!

```