Couldn't understand how closure works in JavaScript for ( var i = 0; i &lt; 5; i++ ) {     setTimeout(function() {         alert( i );     }, i * 100 );  }   I took the above example from the internet to understand closures. But I could not understand why it alerts value 5 for 5 times. Instead of alerting 1,2 3,4 ,5. But the following way can be done. Can someone explain why. I am new to JavaScript so please provide some elaborate answers.  var createFunction = function( i ) {     return function() {         alert( i );     }; };  for ( var i = 0; i &lt; 5; i++ ) {     setTimeout( createFunction( i ), i * 100 ); }
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 have seen  given on Wikipedia, but unfortunately it did not help.
Find a combinatorial argument for the following binomial identity:   $$n(n+1)2^{n-2} = \sum_{k=1}^{n}k^2\binom{n}{k} .$$   Algebraic proofs can be found at  , and a related identity at  . Why (and how) did using cat on binary files mess up the terminal? If I understand the cat manual correctly:       concatenate files and print on the standard output   cat will take files as argument and print them on standard output. What I don't get is if I use the command:    cat img.png &gt; copy.png   I will obtain 2 png files identical while if I just    cat img.png     I have all chance that my terminal get messed up and misinterpret what I type.     How's that possible?   Binary values are still binary data. Why it does not simply shows a series of 0 and 1 or the interpretation of those binary data in ASCII or whatever the encoding in terminal is?   Is this behavior also possible by cating a text file containing strange characters?   Should a mechanism to prevent this behavior  like try{}catch{} statement should be implemented? Singular or plural following a list Postgis, get the points that are x meters near another point, in meters Set limit to one author when using "et al." in biblatex In the header of my document I set the maximal author names to 2:  \usepackage[style=authoryear-icomp, maxbibnames=9, maxcitenames=2, backend=biber]{biblatex}   Now, when I cite texts with two authors, LaTeX gives me the following:     (Author_A/ Author_B 2012: 232)   When I have three authors or more, LaTeX makes it:     (Author_A/ Author_B et al. 2012: 232)   But I want LaTeX to just name the first author if there are more than two authors ... like this:     (Author_A et al. 2012: 232)   Any tips on how to achieve this ? How do I figure the dice and bonuses for attack rolls and damage rolls? I'm building my character, a Half-Elf Ranger, and I'm a little confused about how to work out the attack bonus and the damage bonus.  So, please tell me if I've got this right:   I'm proficient with a longbow. That means my attack roll is 1d20 + prof bonus + Dex modifier. The damage roll however is 1d8 + Dex modifier.   I'm just a little confused about working out the numbers (without even going into spells and when to roll for attack, etc.) transforming ordinary generating function into exponential generating function Annoying Viber notification Because of  I'd like to prevent apt-get upgrade and Update Manager from updating the "libgtk2.0-0" package.   How can this be achieved? How do I report a bug? I found a problem with an application on Ubuntu.   Questions :   How do I best report the issue?  What sort of information should I provide? Bank Deposit Scam I was on Instagram and saw someone's post about making extra cash.  I inboxed her for details and she said her manager will deposit funds into my account, then I would send them $2000 to split between the both of them.  She stated that I would need to overnight my bankcard to her so her manager can process the deposit.  She didn't ask for anything (neither SSN nor routing or account number) but the bank card only.  I assume that it is a scam.  Can anyone elaborate on this type of scam?  She claim it's not a scam. Why can't light escape from a classical black hole? Wild Magic Surge - What does "You cast ..." mean for your spell slots? In response to  question, I started to think about what it means when a Wild Magic Surge results in a "You cast spell-X".  So, "specific beats general" gives:   You can cast a second spell when you would not normally be allowed to You can cast a spell you don't know If the surge forces you to cast a concentration spell you would lose any concentration spell that you currently had active Subject to what the specific entry says you can target it how you like Unless the specific entry prohibits it you could use metamagic on the spell   I am pretty confident in all of the above but if anyone disagrees please address in an answer.  Here comes the question.  How does this impact on your available spell slots?  "You cast ..." to me suggests that if you have an applicable slot available then you have to use it to cast the spell because that is the general rule for casting spells but if you don't then "specific beats general" and it is cast anyway.  Specific examples:     You cast fireball as a 3rd-level spell centered on   yourself   This must be a 3rd level spell:   if you have a 3rd level slot available you have to use it? if you don't, if you have 5 sorcery points and a bonus action available must you use these to get that slot? if you don't have any of that then the spell goes off anyway?      You cast confusion centered on yourself.   No level specified and confusion is a 4th level spell:   if you have a 4th level slot available you have to use it? if you have a 4th, a 6th and an 8th level slot you can choose which one to use? if you have only a 5th level slot but also 6 sorcery points and a bonus action, you could choose to use the 5th level slot or use the points to create a 4th level slot? if you don't have any 4th level or higher slots but you have 6 sorcery points and a bonus action available must you use these to get that slot? if you don't have any of that then the spell goes off anyway?   And so on ... I'm using Android 4.4.2 (on ). I've a Windows PC at home which has highspeed broadband internet connection. I don't have wireless router or access point. I just want to use PC's internet connection on my phone. I've tried multiple methods but none seems to work.  Method 1: Using native Android 4.4.2 option  In my phone when I connect my phone, in Settings &gt; Wireless &amp; networks &gt; USB Internet (sharing Windows PC internet via USB cable) checkbox, which I checked then it asked me to choose my Windows version (which is Windows 8.1 but since it didn't show that option) I chose Windows 8.  It gives me further instructions as showing in the following picture:    Here is the problem, there is no sharing tab (see the following screen shot)   Method 2: As described in   I learned on this site that it is called Reverse tethering. I read and followed the procedure mentioned in    I followed all the steps described in that answer, until executing the command.   Install USB drivers from Android SDK [DONE] Connect USB cable and activate USB Tethering (You should see on a new network interface.) [DONE] Bridge the 2 network interfaces [DONE] On your computer execute adb shell netcfg usb0 dhcp [PROBLEM]   When I execute adb shell netcfg usb0 dhcp it says: error: device not found. I tried the same thing with USB Debugging in Developer settings, ON &amp; OFF. The error remains the same.  Method 3: Rooting the device and using an app  I read here and there that there is another method, in which we can directly use an app but it requires rooting the device. My phone is a new phone and warranty becomes void if I root it.   EDIT: I've tried the method suggested in answer, at the 4th step of method 2, I'm facing this problem: Show that $n-m$ is a multiple of 9 when $n$ and $m$ have same digits I have just proved the divisibility rule for 3 and 9.  Let $n\in\mathbb{N}$. Let $m$ be a number that appears when you shuffle the digits in $n$. Show that $n-m$ is a multiple of 9.  Can anyone offer some help? 3rd iterate of a continuous function equals identity function If $ f: \mathbb{R} \to \mathbb{R} $ is continuous, and $\forall x \in \mathbb{R} :\;(f \circ f \circ f)(x) = x  $, show that $ f(x) = x $.  The condition that $f$ is continuous on $\mathbb{R}$ is crucial for the proof. I can find functions such as $\displaystyle\frac{x-3}{x+1}$ that satisfies  $ (f \circ f \circ f)(x) = x $. I have tried to negate the conclusion to see if there's a contradiction, but got stuck. How to change text format of summary/trimmed field? Is there a straightforward way to change the summary/trimmed text to "full html" in Drupal 8?  There are workarounds such as creating separate body fields and using them as the summary but I am specifically asking about changing the text format of default summary/trimmed field of "Text (formatted, long, with summary)".  To put it another way, how to I add the CKEditor bar to the summary/trimmed text. Are PPAs safe to add to my system and what are some "red flags" to watch out for? Travelling as an unmarried Western couple in Indonesia We currently have some indexes where ALLOW_PAGELOCKS is set to off. This presumably was done in order to reduce deadlocks. However I doubt that it would really had an effect back then.   Now I am trying to understand WHEN SQL Server actually chooses to start locking pages rather than keys in a clustered index. I asked Jonathan Keyhaisas recently and he told me that this could happen if I am touching rows on several subsequent pages. However I didn't manage to get any exclusive page locks by updating rows in a clustered index with a sample query.   Could you help me understand page locks better with a sample query and table? I am running SQL Server 2008 SP4.  Thanks in advance  Martin