Which part of the code executes inner function? [duplicate]












2
















This question already has an answer here:




  • What does a comma do in JavaScript expressions?

    5 answers



  • What is the (function() { } )() construct in JavaScript?

    23 answers




I came across this question in one of the online quizes. The solution I came up with was function. BUT, the console logs number.



var f = (
function f(){return "1";},
function g (){return 2;}
)();
console.log(typeof f);


My thinking was: var f becomes an IIFE, so typeof f should be a function.



Now, apparently, function g() inside var f executes and returns its value to var f, so the console logs number (or 2, if I just log f).



Questions:



1.What is the explanation for function comma anotherFunction. This is not an object, and also not a variable declaration (like var x, y;)?



2.Somehow the second function is the one that is being returned, but what part of the code is actually executing it?



(I thought that () just before the console.log call is executing the outer f function (which should just define inner functions f() and g(), but not execute any of them ). The second one gets executed, so , obviously, I was wrong.










share|improve this question













marked as duplicate by melpomene, Nina Scholz javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • you should remove the space after the g

    – andrea-f
    Nov 21 '18 at 19:15






  • 1





    There is no "outer function".

    – melpomene
    Nov 21 '18 at 19:15






  • 1





    Who in their right mind would even write such a thing...

    – Ben Steward
    Nov 21 '18 at 19:16






  • 1





    maybe you have a look to the comma operator.

    – Nina Scholz
    Nov 21 '18 at 19:19






  • 1





    @NinaScholz That does not fully answer the question. Please read it in full. - "Somehow the second function is the one that is being returned, but what part of the code is actually executing it?"

    – Spencer Wieczorek
    Nov 21 '18 at 19:23


















2
















This question already has an answer here:




  • What does a comma do in JavaScript expressions?

    5 answers



  • What is the (function() { } )() construct in JavaScript?

    23 answers




I came across this question in one of the online quizes. The solution I came up with was function. BUT, the console logs number.



var f = (
function f(){return "1";},
function g (){return 2;}
)();
console.log(typeof f);


My thinking was: var f becomes an IIFE, so typeof f should be a function.



Now, apparently, function g() inside var f executes and returns its value to var f, so the console logs number (or 2, if I just log f).



Questions:



1.What is the explanation for function comma anotherFunction. This is not an object, and also not a variable declaration (like var x, y;)?



2.Somehow the second function is the one that is being returned, but what part of the code is actually executing it?



(I thought that () just before the console.log call is executing the outer f function (which should just define inner functions f() and g(), but not execute any of them ). The second one gets executed, so , obviously, I was wrong.










share|improve this question













marked as duplicate by melpomene, Nina Scholz javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • you should remove the space after the g

    – andrea-f
    Nov 21 '18 at 19:15






  • 1





    There is no "outer function".

    – melpomene
    Nov 21 '18 at 19:15






  • 1





    Who in their right mind would even write such a thing...

    – Ben Steward
    Nov 21 '18 at 19:16






  • 1





    maybe you have a look to the comma operator.

    – Nina Scholz
    Nov 21 '18 at 19:19






  • 1





    @NinaScholz That does not fully answer the question. Please read it in full. - "Somehow the second function is the one that is being returned, but what part of the code is actually executing it?"

    – Spencer Wieczorek
    Nov 21 '18 at 19:23
















2












2








2









This question already has an answer here:




  • What does a comma do in JavaScript expressions?

    5 answers



  • What is the (function() { } )() construct in JavaScript?

    23 answers




I came across this question in one of the online quizes. The solution I came up with was function. BUT, the console logs number.



var f = (
function f(){return "1";},
function g (){return 2;}
)();
console.log(typeof f);


My thinking was: var f becomes an IIFE, so typeof f should be a function.



Now, apparently, function g() inside var f executes and returns its value to var f, so the console logs number (or 2, if I just log f).



Questions:



1.What is the explanation for function comma anotherFunction. This is not an object, and also not a variable declaration (like var x, y;)?



2.Somehow the second function is the one that is being returned, but what part of the code is actually executing it?



(I thought that () just before the console.log call is executing the outer f function (which should just define inner functions f() and g(), but not execute any of them ). The second one gets executed, so , obviously, I was wrong.










share|improve this question















This question already has an answer here:




  • What does a comma do in JavaScript expressions?

    5 answers



  • What is the (function() { } )() construct in JavaScript?

    23 answers




I came across this question in one of the online quizes. The solution I came up with was function. BUT, the console logs number.



var f = (
function f(){return "1";},
function g (){return 2;}
)();
console.log(typeof f);


My thinking was: var f becomes an IIFE, so typeof f should be a function.



Now, apparently, function g() inside var f executes and returns its value to var f, so the console logs number (or 2, if I just log f).



Questions:



1.What is the explanation for function comma anotherFunction. This is not an object, and also not a variable declaration (like var x, y;)?



2.Somehow the second function is the one that is being returned, but what part of the code is actually executing it?



(I thought that () just before the console.log call is executing the outer f function (which should just define inner functions f() and g(), but not execute any of them ). The second one gets executed, so , obviously, I was wrong.





This question already has an answer here:




  • What does a comma do in JavaScript expressions?

    5 answers



  • What is the (function() { } )() construct in JavaScript?

    23 answers








javascript iife






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 19:13









YozexYozex

438




438




marked as duplicate by melpomene, Nina Scholz javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by melpomene, Nina Scholz javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 19:22


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • you should remove the space after the g

    – andrea-f
    Nov 21 '18 at 19:15






  • 1





    There is no "outer function".

    – melpomene
    Nov 21 '18 at 19:15






  • 1





    Who in their right mind would even write such a thing...

    – Ben Steward
    Nov 21 '18 at 19:16






  • 1





    maybe you have a look to the comma operator.

    – Nina Scholz
    Nov 21 '18 at 19:19






  • 1





    @NinaScholz That does not fully answer the question. Please read it in full. - "Somehow the second function is the one that is being returned, but what part of the code is actually executing it?"

    – Spencer Wieczorek
    Nov 21 '18 at 19:23





















  • you should remove the space after the g

    – andrea-f
    Nov 21 '18 at 19:15






  • 1





    There is no "outer function".

    – melpomene
    Nov 21 '18 at 19:15






  • 1





    Who in their right mind would even write such a thing...

    – Ben Steward
    Nov 21 '18 at 19:16






  • 1





    maybe you have a look to the comma operator.

    – Nina Scholz
    Nov 21 '18 at 19:19






  • 1





    @NinaScholz That does not fully answer the question. Please read it in full. - "Somehow the second function is the one that is being returned, but what part of the code is actually executing it?"

    – Spencer Wieczorek
    Nov 21 '18 at 19:23



















you should remove the space after the g

– andrea-f
Nov 21 '18 at 19:15





you should remove the space after the g

– andrea-f
Nov 21 '18 at 19:15




1




1





There is no "outer function".

– melpomene
Nov 21 '18 at 19:15





There is no "outer function".

– melpomene
Nov 21 '18 at 19:15




1




1





Who in their right mind would even write such a thing...

– Ben Steward
Nov 21 '18 at 19:16





Who in their right mind would even write such a thing...

– Ben Steward
Nov 21 '18 at 19:16




1




1





maybe you have a look to the comma operator.

– Nina Scholz
Nov 21 '18 at 19:19





maybe you have a look to the comma operator.

– Nina Scholz
Nov 21 '18 at 19:19




1




1





@NinaScholz That does not fully answer the question. Please read it in full. - "Somehow the second function is the one that is being returned, but what part of the code is actually executing it?"

– Spencer Wieczorek
Nov 21 '18 at 19:23







@NinaScholz That does not fully answer the question. Please read it in full. - "Somehow the second function is the one that is being returned, but what part of the code is actually executing it?"

– Spencer Wieczorek
Nov 21 '18 at 19:23














0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?