Most Popular

1500 questions
7854
votes
28 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
  • 90,043
  • 18
  • 79
  • 129
7711
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,405
  • 29
  • 70
  • 76
7659
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
  • 129,506
  • 13
  • 44
  • 54
7629
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
  • 515,820
  • 103
  • 283
  • 322
7624
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,496
  • 8
  • 33
  • 46
7419
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,623
  • 6
  • 24
  • 25
7300
votes
35 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
  • 76,369
  • 8
  • 31
  • 46
7266
votes
40 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
  • 306,152
  • 101
  • 198
  • 201
7174
votes
39 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
  • 82,523
  • 9
  • 75
  • 82
7152
votes
10 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
  • 177,284
  • 143
  • 381
  • 649
7058
votes
89 answers

Is Java "pass-by-reference" or "pass-by-value"?

I always thought Java uses pass-by-reference. However, I've seen a couple of blog posts (for example, this blog) that claim that it isn't (the blog post says that Java uses pass-by-value). I don't think I understand the distinction they're…
user4315
  • 4,725
  • 5
  • 20
  • 9
6903
votes
62 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,328
  • 20
  • 91
  • 121
6822
votes
37 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
  • 90,341
  • 41
  • 85
  • 110
6670
votes
27 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
  • 90,341
  • 41
  • 85
  • 110
6594
votes
34 answers

How do I remove a property from a JavaScript object?

Say I create an object as follows: let myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" }; How should I remove the property regex to end up with new myObject as follows? let myObject = { "ircEvent": "PRIVMSG", …
johnstok
  • 87,006
  • 12
  • 51
  • 76