+ 2

What makes a function anonymous in JavaScript?

Are constructor functions anonymous

13th Apr 2022, 6:54 PM
steve Purpose
steve  Purpose - avatar
6 Respuestas
+ 5
Anonymous functions are the ones without a name that cannot be called. var anon1 = function(){}; //This function does not have a name, you can only call it if you assign it in a variable like so. Also, arrow functions are always nameless.
13th Apr 2022, 11:07 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
To add to Valen.H. ~ 's great answer, you can call a nameless function without assigning it but you can't reuse it! function(){}(); should work edit: no it don't! but (() => alert("toto"))() does!
14th Apr 2022, 5:06 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
Ok.Thanks a lot
14th Apr 2022, 2:22 AM
steve Purpose
steve  Purpose - avatar
0
If that is the case,can you please explain this to me..why we call Drive() but calling person() returns an error.we only call person like (). https://code.sololearn.com/WYhL5awtmEuj/?ref=app https://code.sololearn.com/W9NqzL3q1xWp/?ref=app
14th Apr 2022, 2:28 AM
steve Purpose
steve  Purpose - avatar
0
Thanks for the solution ..I'll try it even though I'm still trying to wrap my head around your answer
14th Apr 2022, 5:24 PM
steve Purpose
steve  Purpose - avatar
0
Sorry I didn't read your comment. To answer you, the error is that you don't call person, you assign the result of a "function(){}()" like expression to person, but this expression is invalid. You can store function(){} in a variable then call it. To sum it up function(){} - can be stored - can be used only if stored () => {} - can be stored - can be called even if not stored
14th Apr 2022, 6:19 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar