languages/
Syntax, runtimes, compilers, JITs, type systems and memory management.
13 results
languages/javascript-closures-how-a-function-remembers-a-variable-after-the-func.md
JavaScript closures: how a function remembers a variable after the function that made it has finished
A function in JavaScript can still use a variable long after the function that created it has finished. That is called a closure, and you…
languages/ruby-blocks-how-a-method-borrows-a-piece-of-your-code-and-runs-it-with.md
Ruby blocks: how a method borrows a piece of your code and runs it with yield
Ruby code is full of curly-brace chunks like `list.each { |x| ... }`. Who runs that chunk, and when? This article follows a block from the…
languages/reference-counting-how-python-knows-when-to-throw-an-object-away.md
Reference counting: how Python knows when to throw an object away
You never tell Python to free memory, yet unused objects disappear. How does it know when one is finished with? CPython keeps a tally on…
languages/generators-how-a-python-function-can-pause-in-the-middle-and-pick-up-w.md
Generators: how a Python function can pause in the middle and pick up where it left off
A generator is a Python function that can pause halfway, hand you a value, and carry on later from the same line with its variables intact…
languages/javascript-s-event-loop-why-settimeout-0-runs-after-the-code-below-it.md
JavaScript's event loop: why setTimeout(…, 0) runs after the code below it
Why does `setTimeout(fn, 0)` run after the lines below it, and why does a promise callback beat it? JavaScript has one worker and two…
languages/rust-ownership-why-let-b-a-makes-a-unusable.md
Rust ownership: why let b = a makes a unusable
Why does Rust refuse to compile `let b = a;` followed by a use of `a`? Because of ownership: every value has exactly one owner, and…
languages/ruby-strings-why-changing-b-also-changes-a.md
Ruby strings: why changing b also changes a
In Ruby, `b = a` does not copy a string: it puts a second label on the same object. So `b << "s"` changes `a` too, while `b += "s"` does…
languages/python-default-arguments-why-a-function-remembers-the-last-call.md
Python default arguments: why a function remembers the last call
Call a small Python function twice and the second call remembers the first. The cause is a default value like `basket=[]`, which Python…
languages/go-slices-why-appending-to-a-copy-can-change-the-original.md
Go slices: why appending to a copy can change the original
Change a copy of a Go slice and sometimes the original changes too. The reason is that a slice is only a small window onto an array, with a…
languages/why-does-5-3-give-53-in-javascript-type-coercion-step-by-step.md
Why does "5" + 3 give "53" in JavaScript? Type coercion, step by step
Why does `"5" + 3` give `"53"` while `"5" - 3` gives `2`? It is not random. JavaScript follows a short recipe called type coercion: it…
languages/why-does-0-1-0-2-give-0-30000000000000004-in-python.md
Why does 0.1 + 0.2 give 0.30000000000000004 in Python?
Type 0.1 + 0.2 into Python and you get 0.30000000000000004. It is not a bug: computers store fractions in binary, and one tenth has no…
languages/why-does-my-javascript-loop-run-one-time-too-many.md
Why does my JavaScript loop run one time too many?
A loop tells JavaScript to repeat some code until a condition says stop. A for loop packs three pieces onto one line: a setup that runs…