edubun
English

Programming

JavaScript and Python from the first line, then algorithms and data structures, with code you edit and run in the page and labs that count every step.

Code editorExplanationPractice

Learning path

  1. 1JavaScriptIntro12 unitsabout 220 min
  2. 2PythonIntro10 unitsabout 168 min
  3. 3AlgorithmsBasic7 unitsabout 191 min
  4. 4Data structuresIntermediate7 unitsabout 192 min

Course map

Programming · Courses: 4

For people who have never written a line

The two language courses start from nothing. JavaScript begins with one console.log line and Python with a file that holds print("Hello, world!"), which is already a complete program. Every code sample on the Python pages was run in Python 3.12 and the output shown is the real output. In JavaScript you edit the code and run it right in the page, and exercises check what your program prints. The two later courses are for learners who can already write a loop and a function and want to know why one method is faster than another.

Counting the work

The algorithm and data structure labs run one step at a time and keep score. Selection sort makes exactly 45 comparisons on any list of 10 values, shuffled or already sorted. Binary search finds a name among a million sorted ones in at most 20 checks. At a billion steps a second, an n² method on a million values takes about 17 minutes and an n log n method about 0.02 seconds. Reading the millionth value of an array takes one step; putting a new value at its front moves a million. A balanced tree of 1,023 keys finds any of them in at most 10 comparisons, but built from sorted input the same keys can take 1,023.

Small surprises in the first weeks

In JavaScript, "5" + 3 gives "53", 0.1 + 0.2 gives 0.30000000000000004, and 5 == "5" is true while 5 === "5" is false. In Python, 7 / 2 gives 3.5 but 7 // 2 gives 3, and range(5) stops at 4. "Python"[6] is an error, because counting starts at 0.

What beginners get wrong

Each Python unit names the mistakes it expects. Reading = as "equals" rather than "gets", so score = score + 5 looks impossible. Writing if answer == "yes" or "y" and expecting it to catch both. Assuming b = a makes a backup of a list. Thinking a function that prints the answer has returned it, the confusion the teacher note calls the most common at this stage, because the screen looks the same. Fixing the line a traceback names when the real cause sits higher up.

Questions about this subject

What is the difference between let and const in JavaScript?

Both declare variables, but let permits a later assignment and const does not. A const declaration needs an initial value immediately, and attempting to assign another value raises a TypeError. Use const when the binding should stay unchanged and let when a later step must update it, rather than redeclaring the same variable every time. JavaScript

Why does adding a string and a number join them as text?

With the plus operator, a string on either side makes JavaScript convert the other value to text and concatenate the pair. That is why "5" + 3 produces "53" rather than 8. Convert digit text with Number before adding when you want arithmetic; multiplication has different conversion behaviour and does not concatenate strings. JavaScript

Why is 0.1 plus 0.2 not printed as exactly 0.3?

JavaScript stores numbers in a fixed binary format, and some decimal fractions cannot be represented exactly in that format. Small rounding errors can become visible, as in the result 0.30000000000000004. Formatting with toFixed(2) displays "0.30", but returns a string, so a displayed rounded value and a numeric value are not the same thing. JavaScript

What is the difference between double and triple equals?

Double equals attempts type conversion before comparing, so a number and digit string can compare equal. Triple equals uses strict equality and does not convert either value: 5 === "5" is false because their types differ. This differs from a single equals sign, which assigns a value rather than asking whether two values are equal. JavaScript

Why is the last string index smaller than its length?

Indexing begins at zero, so a ten-character string has positions zero through nine. The length of "JavaScript" is ten, while its first character is at index zero and its last at index nine. A slice also excludes its ending index, so slice(0, 4) selects the first four characters rather than five. JavaScript