Most Popular
1500 questions
8124
votes
29 answers
What does "use strict" do in JavaScript, and what is the reasoning behind it?
Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error:
Problem at line 1 character 1: Missing "use strict" statement.
Doing some searching, I realized that some people add "use strict"; into their…

Mark Rogers
- 93,029
- 18
- 84
- 134
7755
votes
39 answers
How do I check out a remote Git branch?
Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.
Now I'm trying to check out the remote test branch.
I've tried:
git checkout test which does nothing
git checkout…

Juri Glass
- 80,959
- 8
- 32
- 46
7710
votes
58 answers
How do I redirect to another webpage?
How can I redirect the user from one page to another using jQuery or pure JavaScript?

venkatachalam
- 101,783
- 30
- 71
- 76
7656
votes
27 answers
How to modify existing, unpushed commit messages?
I wrote the wrong thing in a commit message.
How can I change the message? The commit has not been pushed yet.

Laurie Young
- 132,296
- 13
- 46
- 54
7625
votes
86 answers
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 the Scheme example given on Wikipedia,…

e-satis
- 544,085
- 107
- 288
- 324
7620
votes
41 answers
How do I revert a Git repository to a previous commit?
How do I revert from my current state to a snapshot made on a certain commit?
If I do git log, then I get the following output:
$ git log
commit a867b4af366350be2e7c21b8de9cc6504678a61b`
Author: Me
Date: Thu Nov 4 18:59:41 2010…

Crazy Serb
- 76,390
- 8
- 33
- 46
7568
votes
41 answers
How to remove local (untracked) files from the current Git working tree
How do you delete untracked local files from your current working tree?

readonly
- 321,454
- 105
- 202
- 204
7417
votes
3 answers
How to check whether a string contains a substring in JavaScript?
Usually I would expect a String.contains() method, but there doesn't seem to be one.
What is a reasonable way to check for this?

gramm
- 18,653
- 6
- 25
- 26
7366
votes
41 answers
var functionName = function() {} vs function functionName() {}
I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.
The previous developer used two ways of declaring functions and I can't work out if…

Richard Garside
- 84,924
- 10
- 78
- 86
7355
votes
92 answers
Is Java "pass-by-reference" or "pass-by-value"?
I always thought Java uses pass-by-reference.
However, I've seen a blog post that claims that Java uses pass-by-value.
I don't think I understand the distinction they're making.
What is the explanation?

user4315
- 4,765
- 5
- 21
- 9
7342
votes
39 answers
What does if __name__ == "__main__": do?
Given the following code, what does the if __name__ == "__main__": do?
# Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while True:
lock.acquire()
time.sleep(sleeptime)
…

Devoted
- 95,941
- 41
- 87
- 110
7313
votes
11 answers
Why is subtracting these two times (in 1927) giving a strange result?
If I run the following program, which parses two date strings referencing times 1 second apart and compares them:
public static void main(String[] args) throws ParseException {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); …

Freewind
- 183,968
- 149
- 399
- 663
7182
votes
31 answers
Does Python have a ternary conditional operator?
If Python does not have a ternary conditional operator, is it possible to simulate one using other language constructs?

Devoted
- 95,941
- 41
- 87
- 110
7151
votes
63 answers
What is the difference between String and string in C#?
Example (note the case):
string s = "Hello world!";
String s = "Hello world!";
What are the guidelines for the use of each? And what are the differences?

Lance Fisher
- 25,464
- 20
- 92
- 121
6988
votes
31 answers
How can I make Git "forget" about a file that was tracked, but is now in .gitignore?
There is a file that was being tracked by Git, but now the file is on the .gitignore list.
However, that file keeps showing up in git status after it's edited. How do you force Git to completely forget about it?

Ivan
- 85,778
- 15
- 48
- 57