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?
javascript closures google-chrome-devtools
marked as duplicate by Bergi
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.
add a comment |
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?
javascript closures google-chrome-devtools
marked as duplicate by Bergi
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 afterouter
runs, it can't be referenced anymore, so it gets GC'd, though maybe smart compilers would see thaty
is never used and not bother assigning it. Might be engine-dependent.
– CertainPerformance
23 hours ago
add a comment |
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?
javascript closures google-chrome-devtools
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?
This question already has an answer here:
Why does Chrome debugger think closed local variable is undefined?
5 answers
javascript closures google-chrome-devtools
javascript closures google-chrome-devtools
asked 23 hours ago
Guillaume Renoult
718616
718616
marked as duplicate by Bergi
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
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 afterouter
runs, it can't be referenced anymore, so it gets GC'd, though maybe smart compilers would see thaty
is never used and not bother assigning it. Might be engine-dependent.
– CertainPerformance
23 hours ago
add a comment |
1
I'd think the variable is created, but afterouter
runs, it can't be referenced anymore, so it gets GC'd, though maybe smart compilers would see thaty
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
add a comment |
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:
However on Firefox variable "y" is accessible:
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.
add a comment |
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:
However on Firefox variable "y" is accessible:
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.
add a comment |
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:
However on Firefox variable "y" is accessible:
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.
add a comment |
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:
However on Firefox variable "y" is accessible:
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.
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:
However on Firefox variable "y" is accessible:
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.
answered 6 hours ago
Guillaume Renoult
718616
718616
add a comment |
add a comment |
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 thaty
is never used and not bother assigning it. Might be engine-dependent.– CertainPerformance
23 hours ago