LOCK.IN Intermediate: make the page do something

Build things20 pages

You finish with an interactive page wired to real data.

Rp 99.000Buy E-Book
LOCK.IN Intermediate: make the page do something cover

What is inside

All 6 chapters

  1. 1Values and types

    Tell what kind of thing a value is before the code runs.

  2. 2Control flow and functions

    Give a piece of logic one name, one input and one job.

  3. 3Arrays and objects

    Keep many values in order, and a record in named fields.

  4. 4The DOM

    Find a node in the page and change it from code.

  5. 5Events and state

    Keep one value as the truth and redraw from it.

  6. 6Fetching and shipping

    Read data from somewhere that can fail, and say so on screen.

Quests and Challenges

  • quiz
    Read a record without guessing+15 XP
  • repo
    Ship a small stateful page+10 XP
  • bank soal
    Requests and their failures+10 XP

Chapter 1: Values and types

Read the first chapter

Twelve and "twelve" are different things

A value is a piece of data and a type is what kind it is. 12 is a number you can add to. "12" is a string of two characters that happen to be digits: and + will join it to another string instead of adding it.

js · RunnableRun in playground
console.log(12 + 5);console.log("12" + "5");console.log("12" + 5);console.log(typeof 12, typeof "12");
Run it and read the output line by line.

The fourth line prints number string. typeof answers the question the whole chapter is about, and it costs less than a guess.

What `+` does to a mix

When one side of + is a string, JavaScript turns the other side into a string and joins them. Other arithmetic operators go the other way: they try to make a number.

js · RunnableRun in playground
console.log("3" * 4);console.log("3" + 4);console.log(3 + 4 + "!");console.log("Items: " + 3 + 4);console.log(Number("3") + 4);
Four lines, four different results.
trapThe classic string-concatenation bug

"Items: " + 3 + 4 prints Items: 34, not Items: 7, because the join happens left to right. Group the sum in brackets or convert with Number() before you join.

The other 5 chapters

Every interactive code checkpoint, the PDF edition, Quests and Socratic AI.