DEV Community

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

akashkava profile image
Akash Kava • Edited on

What will be output of

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

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

Try in chrome, you will not see "done"

(() => console.log(arguments))("a");
themindfuldev profile image
Tiago Romero Garcia • Edited on

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) });"done");

(function() { console.log(arguments) })("a");
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.