No Need To Use console.log() Anymore In 2022

I have a question to ask as a JavaScript developer. Should I ask?

Do you often use console.log() to check the output in the console for fun purposes? I can bet everyone that, when you were a fresher, may have used the console to write the first “Hello World”. 

Do you remember? 

Let me share an example. 

console.log (“Hello World!”)

Isn’t this giving you a nostalgic feeling? But coming back to the recent year, and it’s 2022. Let’s make it more friendly and tiny for our fingers. 

Why I am telling you this? Because in this article, I am going to disclose a unique method that has been hardly used by us (developers). 

Let’s go ahead.

We used to log the information to the console something like this,

console.log("Radixweb is my home") // Radixweb is my home
console.log(5 + 5) // 10
console.log(!false)  // true

We have become too smart now. Right? So, let’s apply some brain power here.

const log = (arg) => console.log(arg)

Didn’t get it yet?

Actually, I have made a new function with a shorter name – log relative to console.log(). And we also can use a shorter name, something like shown in the given command:

const 1 = (arg) => console.log(arg)

Now you must have a question. Why will I use it? What kind of benefits will I get from writing code like this?

Let’s discuss some advantages here.

  • Used for better readability
  • Gives relief from writing a long code.
  • Keeps the code neat and clean.

Allow me to give a real-time example here,

onsole.log("Radixweb is my home") // Radixweb is my home
console.log(5 + 5) // 10
console.log(!false)  // true
log(Math.PI) // 3.141592653589793

Conclusion

Isn’t this interesting? This definitely saves you time and makes your code cleaner.

Moreover, you can follow the same practice for console.info()concolse.warn(), and console.error().

Ebook Download
View all
Learn
View all