DEV Community

Discussion on: What’s your favorite JS interview question?

Collapse
 
akashkava profile image
Akash Kava • Edited

What will be output of

(() => console.log(this)).bind("done")()

var fx = (() => console.log(this));
fx.call("done");

Enter fullscreen mode Exit fullscreen mode

Try in chrome, you will not see "done"

(() => console.log(arguments))("a");
Enter fullscreen mode Exit fullscreen mode
Collapse
 
themindfuldev profile image
Tiago Romero Garcia • Edited

Great question! I believe this is because arrow functions can't be bound and also don't have arguments, for that we need to use regular function definitions:

(function() { console.log(this) }).bind("done")();

var fx = (function() { console.log(this) });
fx.call("done");

(function() { console.log(arguments) })("a");
Collapse
 
misterwhat profile image
Jonas Winzen

You can't bind anything to an arrow functions this. But you can bind arguments to them. ie:

((arg) => console.log(arg)).bind(null, "done")()

would work.

Thread Thread
 
themindfuldev profile image
Tiago Romero Garcia

Oh nice! Thanks for explaining that.