JavaScript in the Console!
The Console’s log method allows us to print JavaScript data, of any kind, to the Console. Before we dig into all of the cool tricks you can do with the log method, try the following examples to see what different types of data look like in the Console.
Strings
1 console.log("Hello, console!");
2 // Hello, console!
3
4 console.log("Hello, console!".toUpperCase());
5 // HELLO, CONSOLE!
Numbers
1 console.log(9001);
2 // 9001
3
4 console.log(10*10);
5 // 100
Booleans
1 console.log(true);
2 // true
3
4 console.log(1<0);
5 // false
Arrays
1 console.log([0, 1, 2]);
2 // [0, 1, 2]
3
4 console.log([0, 1, 2].reverse());
5 // [2, 1, 0]
6
7 console.log([0, 1, 2][0]);
8 // 0
Objects
1 console.log({key: "value"});
2 // Object {key: "value"}
3
4 var myObject = {key: "value"};
5 console.log(myObject["key"]);
6 // value
Functions
1 var myFunction = function() {
2 return "Hello, console!";
3 }
4
5 console.log(myFunction);
6 // function () {
7 // return "Hello, console!";
8 // }
9
10 console.log(myFunction());
11 // Hello, console!