loading...

Three types of console.log users. Which one are you?

allanjeremy profile image Allan N Jeremy ・1 min read

Any js developer has definitely used console.log() before. Among these 3 main ways to print variables with text within console.log(), I am curious to see what kind of developers people are.

I have added comments for of the three methods mentioned feel free to vote for the method you use by liking the comment that corresponds to how you use `console.log(). I'd also love to hear why you use the method that you use.

Discussion

pic
Editor guide
 

Method two: Template literals (ES6+)

By wrapping a string in backticks you can append a variable to the string by putting it inside ${}.

console.log (`my variable : ${myVariable}`);
 

This is the way I should do it, 😜

 

😁 either this or the other one, the other option does have its advantages (e.g. printing an object or other non-primitives without having to JSON.stringify it)

 

Method three: separate arguments

console.log allows us to parse strings and variables as separate arguments

console.log ('my variable :', myVariable);
 
 

Method one: String concatenation

We can join strings using the + operator. As a result this allows us to append a variable to a string.

console.log ('my variable :'+ myVariable);
 

I just log it without any message and identify it with the filename and line number. πŸ™ˆ

 

Sounds like work πŸ˜…