All Questions

7661
votes
88answers
1168136 views

How do JavaScript closures work?

How would you explain JavaScript closures to someone with a knowledge of the concepts they consist of (for example functions, variables and the like), but does not understand closures themselves? I h...
1588
votes
24answers
408301 views

What is the scope of variables in JavaScript?

What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined glob...
120
votes
3answers
31003 views

Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors?

Note: This is a reference question for dealing with variable scope in PHP. Please close any of the many questions fitting this pattern as duplicate of this one. What is "variable scope" in PHP? A...
323
votes
7answers
188182 views

Short Description of the Scoping Rules?

What exactly are the Python scoping rules? If I have some code: code1 class Foo: code2 def spam..... code3 for code4..: code5 x() Where is x found? Some possible c...
316
votes
2answers
157030 views

How to choose the right bean scope?

I noticed that there are different bean scopes like: @RequestScoped @ViewScoped @FlowScoped @SessionScoped @ApplicationScoped What is the purpose of each? How do I choose a proper scope for my bean...
2206
votes
19answers
2328764 views

Using global variables in a function other than the one that created them

If I create a global variable in one function, how can I use that variable in another function? Do I need to store the global variable in a local variable of the function which needs its access?
437
votes
15answers
121348 views

How do I access previous promise results in a .then() chain?

I have restructured my code to promises, and built a wonderful long flat promise chain, consisting of multiple .then() callbacks. In the end I want to return some composite value, and need to access m...
2631
votes
23answers
590562 views

What's the difference between using "let" and "var" to declare a variable?

ECMAScript 6 introduced the let statement. I've heard it described as a "local" variable, but I'm still not quite sure how it behaves differently than the var keyword. What are the differences? When ...
80
votes
3answers
6833 views

Local variables in Python nested functions

Okay, bear with me on this, I know it's going to look horribly convoluted, but please help me understand what's happening. from functools import partial class Cage(object): def __init__(self, an...
26
votes
6answers
6240 views

Javascript: Do I need to put this.var for every variable in an object?

In C++, the language I'm most comfortable with, usually one declares an object like this: class foo { public: int bar; int getBar() { return bar; } } Calling getBar() works fine (ignoring t...

Previous Next