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.
Top comments (9)
Method two: Template literals (ES6+)
By wrapping a string in backticks you can append a variable to the string by putting it inside
${}
.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 argumentsKISS
🤘🏾
Method one: String concatenation
We can join strings using the + operator. As a result this allows us to append a variable to a string.
I just log it without any message and identify it with the filename and line number. 🙈
Sounds like work 😅