@prajwalchoudhary4824

Th reason it's returning NaN is because when u r invoking res, this keyword points to global this and global this is window object  in non strict mode so when u add window.a which is undefined with window.b which is also undefined u get NaN but if you do res.bind(obj) then it points to correct object or like how u did either way is fine.

@evilgaming000

Or you can just call the sum function when assiging to the res variable like 
const res = obj.sum();
In this case "this" will refer to the "obj" object not to the global object

@anshumanupadhyaycodes

Bind is not necessary, a simple call on obj will work

@ayushsrivastava9210

Simplest : console.log(obj.sum())

@STONEcreator999

Soo much valueble.
Keep it up brother.
Sure these short videos will reach millions of views in some lucky day.

@tinolbhoyar4646

You should  also explain what bind does

@krishnachaitanya7138

I don't see any point in asking this question const res = obj.sum() if u directly call like this it ll return the result bcz it has the reference to the obj but res don't have reference to the obj bcz it's a copy of that sum func , to fix it we need not to bind we can simply use obj.sum() will fix it but if they want to access the res() function then we can bind and pass the reference

@Jmfufghf

the most important question is why would you write confusing garbage code like that in the first place?  as a senior engineer i would write clear easy to understand functions

@abhishekpatnaik144

they tried to confuse ur friend to make him think like it forms a closure but function inside object doesnt form closure.

@vishal_sharma_rha

It will refer to parent object and with the help of call apply and bind method we can invoke it

@n_fan329

Or console.log(res.call(obj))

@professor3259

not sure how all developers are trying to give his out put as correct one because the output is 3 ..... because when called obj.sum -> this will give function defination ....ƒ sum (){
        return this.a + this.b
    }

..... but if doning obj.sum() .... then for the sum() this will points towards the obj object ... then a and b will be 1 and 2 respectively and answer will be 3

@Ravikumar-dt2mo

Use arrow function

@DipsikhaBanerjee-x4v

res is not a function then what is the point of invoking it? Only remove the bracket from res and place it as obj.sum() and you will get output as 3

@aurelian3401

Add paranthesis to sum, when you invoke it, because is a function, not a property.

@rishikeshwagh392

Line no 9 causes the problem in my opinion because of named function this refers to context of caller please correct if i am wrong

@CallousCoder

In a normal proper language it should return 3. Proves again how rotten JS is 😂

@doguparthisrinuswaru6418

If let a,b then result is 3??

@sangram597

We can also use arrow function ?

@rsp1841

it was good . but not clear visible , in between your talk with sentence will show so code are not clear visible
sir , sorry for disturb .