console.log()

So console.log() comes with some additional behavior that may surprise some of you.

Let's start with the well-known ones, you can use console.log() to log an object like this:

const person = {firstName:"john",lastName:"doe",age:24} console.log(person)

console.log(person)

you can also use it to attach a message (string) to the object in the following way:

console.log("Person Object Details:",person)

Now let’s assume that you want to mark a specific log in order to find him easily, you can do so by attaching to your log the %c operator that tells the browser to get the CSS from the second argument and implement it on the text that comes after that %c

console.log("%c Hi I'm Green ",'color:green')

console.dir()

console.dir() behave nearly the same as console.log(object) the main difference between the two is shown when you try to print a DOM Element

when you run console.log(document) the output will be:

console.log(document)

but when you run console.dir(document) the output will be present in a more objective view