PayPal interview question

Explain this: var Bob = { name: "Bob", name_fn: function(){ return this.name; } } console.log(Bob.name_fn()) //"Bob" var fn = Bob.name_fn console.log(fn()) //undefined

Interview Answers

Anonymous

29 Mar 2016

when you call fn() its scope is in global. The function call should be scoped properly to work. You should use call or apply to make it work.

2

Anonymous

15 Dec 2020

It's essential to demonstrate that you can really go deep... there are plenty of followup questions and (sometimes tangential) angles to explore. There's a lot of Software Engineer III experts who've worked at PayPal, who provide this sort of practice through mock interviews. There's a whole list of them curated on Prepfully. prepfully.com/practice-interviews

Anonymous

22 Sept 2015

fn is "Bob" and not a method.