Pergunta de entrevista da empresa PayPal

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

Respostas da entrevista

Sigiloso

29 de mar. de 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

Sigiloso

15 de dez. de 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

Sigiloso

22 de set. de 2015

fn is "Bob" and not a method.