JavaScript#1 · 2 Dec 2026
Can you add true and true?
console.log(true + true);
console.log(true + "1");
console.log(true * "3");
console.log(false - 1);What does this print?
JavaScript · Types and coercion
console.log(true + true);
console.log(true + "1");
console.log(true * "3");
console.log(false - 1);What does this print?
It prints: 2
true1
3
-1
In math, true becomes 1 and false becomes 0, so true + true is 2 and false - 1 is -1. But + with a string on one side joins text instead, so true + "1" is "true1". * always converts both sides to numbers, so true * "3" is 3.
Booleans act as 1 and 0 in math, except next to a string with +, where they become text.