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)
In the first case, `objf` will indeed be undefined. As the function doesn't return anything, it wouldn't be sensible to just invent something and return that.

In the second case, `objf` will be the `Window` object.