Which equals operator (== vs ===) should be used in JavaScript comparisons?

The strict equality operator (===) behaves identically to the abstract equality operator (==) except no type conversion is done, and the types must be the same to be considered equal. Reference: Javascript Tutorial: Comparison Operators The == operator will compare for equality after doing any necessary type conversions. The === operator will not do the … Read more

How do I execute a program or call a system command?

Use the subprocess module in the standard library: import subprocess subprocess.run([“ls”, “-l”]) The advantage of subprocess.run over os.system is that it is more flexible (you can get the stdout, stderr, the “real” status code, better error handling, etc…). Even the documentation for os.system recommends using subprocess instead: The subprocess module provides more powerful facilities for … Read more

How do I discard unstaged changes in Git?

For all unstaged files in current working directory use: git restore . For a specific file use: git restore path/to/file/to/revert That together with git switch replaces the overloaded git checkout (see here), and thus removes the argument disambiguation. If a file has both staged and unstaged changes, only the unstaged changes shown in git diff … Read more

What is the difference between “let” and “var”?

Scoping rules The main difference is scoping rules. Variables declared by var keyword are scoped to the immediate function body (hence the function scope) while let variables are scoped to the immediate enclosing block denoted by { } (hence the block scope). function run() { var foo = “Foo”; let bar = “Bar”; console.log(foo, bar); … Read more

How to disable text selection highlighting

UPDATE January, 2017: According to Can I use, the user-select is currently supported in all browsers except Internet Explorer 9 and its earlier versions (but sadly still needs a vendor prefix). These are all of the available correct CSS variations: .noselect { -webkit-touch-callout: none; /* iOS Safari */ -webkit-user-select: none; /* Safari */ -khtml-user-select: none; /* … Read more