Is a closure variable not created if not used? [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • Why does Chrome debugger think closed local variable is undefined?

    5 answers




In this example, Google Chrome Devtools won't find variable "y" in closure scope, but it will show "x".



My guess is that "y" won't appear because it's not used.



Am I right?



enter image description here










share|improve this question













marked as duplicate by Bergi 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();
}
);
});
});
6 hours ago


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.











  • 1




    I'd think the variable is created, but after outer runs, it can't be referenced anymore, so it gets GC'd, though maybe smart compilers would see that y is never used and not bother assigning it. Might be engine-dependent.
    – CertainPerformance
    23 hours ago















up vote
0
down vote

favorite













This question already has an answer here:




  • Why does Chrome debugger think closed local variable is undefined?

    5 answers




In this example, Google Chrome Devtools won't find variable "y" in closure scope, but it will show "x".



My guess is that "y" won't appear because it's not used.



Am I right?



enter image description here










share|improve this question













marked as duplicate by Bergi 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();
}
);
});
});
6 hours ago


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.











  • 1




    I'd think the variable is created, but after outer runs, it can't be referenced anymore, so it gets GC'd, though maybe smart compilers would see that y is never used and not bother assigning it. Might be engine-dependent.
    – CertainPerformance
    23 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • Why does Chrome debugger think closed local variable is undefined?

    5 answers




In this example, Google Chrome Devtools won't find variable "y" in closure scope, but it will show "x".



My guess is that "y" won't appear because it's not used.



Am I right?



enter image description here










share|improve this question














This question already has an answer here:




  • Why does Chrome debugger think closed local variable is undefined?

    5 answers




In this example, Google Chrome Devtools won't find variable "y" in closure scope, but it will show "x".



My guess is that "y" won't appear because it's not used.



Am I right?



enter image description here





This question already has an answer here:




  • Why does Chrome debugger think closed local variable is undefined?

    5 answers








javascript closures google-chrome-devtools






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 23 hours ago









Guillaume Renoult

718616




718616




marked as duplicate by Bergi 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();
}
);
});
});
6 hours ago


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 Bergi 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();
}
);
});
});
6 hours ago


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.










  • 1




    I'd think the variable is created, but after outer runs, it can't be referenced anymore, so it gets GC'd, though maybe smart compilers would see that y is never used and not bother assigning it. Might be engine-dependent.
    – CertainPerformance
    23 hours ago














  • 1




    I'd think the variable is created, but after outer runs, it can't be referenced anymore, so it gets GC'd, though maybe smart compilers would see that y is never used and not bother assigning it. Might be engine-dependent.
    – CertainPerformance
    23 hours ago








1




1




I'd think the variable is created, but after outer runs, it can't be referenced anymore, so it gets GC'd, though maybe smart compilers would see that y is never used and not bother assigning it. Might be engine-dependent.
– CertainPerformance
23 hours ago




I'd think the variable is created, but after outer runs, it can't be referenced anymore, so it gets GC'd, though maybe smart compilers would see that y is never used and not bother assigning it. Might be engine-dependent.
– CertainPerformance
23 hours ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













It looks like it's engine dependent.



On Google Chrome (Version 70.0.3538.77 (Official Build) (64-bit)), I can't see "y" variable:



Chrome



However on Firefox variable "y" is accessible:



Firefox



I'm not sure how these engines work, I assume Chrome during compile time have a look at variable "y" and says "hey it's not used in this scope, we don't need it". Whereas Firefox includes it.






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    It looks like it's engine dependent.



    On Google Chrome (Version 70.0.3538.77 (Official Build) (64-bit)), I can't see "y" variable:



    Chrome



    However on Firefox variable "y" is accessible:



    Firefox



    I'm not sure how these engines work, I assume Chrome during compile time have a look at variable "y" and says "hey it's not used in this scope, we don't need it". Whereas Firefox includes it.






    share|improve this answer

























      up vote
      0
      down vote













      It looks like it's engine dependent.



      On Google Chrome (Version 70.0.3538.77 (Official Build) (64-bit)), I can't see "y" variable:



      Chrome



      However on Firefox variable "y" is accessible:



      Firefox



      I'm not sure how these engines work, I assume Chrome during compile time have a look at variable "y" and says "hey it's not used in this scope, we don't need it". Whereas Firefox includes it.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        It looks like it's engine dependent.



        On Google Chrome (Version 70.0.3538.77 (Official Build) (64-bit)), I can't see "y" variable:



        Chrome



        However on Firefox variable "y" is accessible:



        Firefox



        I'm not sure how these engines work, I assume Chrome during compile time have a look at variable "y" and says "hey it's not used in this scope, we don't need it". Whereas Firefox includes it.






        share|improve this answer












        It looks like it's engine dependent.



        On Google Chrome (Version 70.0.3538.77 (Official Build) (64-bit)), I can't see "y" variable:



        Chrome



        However on Firefox variable "y" is accessible:



        Firefox



        I'm not sure how these engines work, I assume Chrome during compile time have a look at variable "y" and says "hey it's not used in this scope, we don't need it". Whereas Firefox includes it.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 6 hours ago









        Guillaume Renoult

        718616




        718616















            Popular posts from this blog

            横浜市

            Rostock

            Europa