JavaScript: Printing

Printing Single Values

1console.log(5)      // Prints: 5
2
3console.log(4.3)    // Prints: 4.3
4
5console.log("John") // Prints: John
6
7console.log(true)   // Prints: true
8
9console.log(false)  // Prints: false

Printing Expression Results

1// Arithmetic Operations
2
3console.log(5 + 3)     // Prints: 8
4
5console.log(4.3 + 1.2) // Prints: 5.5
6
7console.log(4.3 + 1)   // Prints: 5.3
8
9// ---
10
11console.log(5 - 3)  // Prints: 2
12
13console.log(5 * 3)  // Prints: 15
14
15console.log(10 / 2) // Prints: 5
1// Working with "Text" (Strings)
2
3console.log("JohnDoe")      // Prints: JohnDoe
4
5console.log("John" + "Doe") // Prints: JohnDoe
6
7// ---
8
9console.log("John Doe")           // Prints: John Doe
10
11console.log("John " + "Doe")      // Prints: John Doe
12
13console.log("John" + " Doe")      // Prints: John Doe
14
15console.log("John" + " " + "Doe") // Prints: John Doe

We're always writing code that solves problems and produces results, and we frequently need to see what those results are

A common way to see those results is just printing them using console.log, as we have done in the examples above