Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 7, 2022 09:00 am GMT

Its 2022, Dont Use the console.log() Anymore

We as JavaScript developers usually use console.log() to test the output or just for fun. Even I can bet that our (including mine) first code was Hello world logged in the console.

console.log("Hello World!")

This piece of code has been nostalgic for all fellow JS developers. But now its 2022, lets make it a little handy and comfortable for our fingers.

In this article, I have discussed a simple and common method that has rarely been used by developers.

Lets get started

As we know, we all use to log the data to the console like this:

console.log("I love js") // I love jsconsole.log(4 + 4) // 8console.log(!true)  // false

Lets work smartly and efficiently as shown below:

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

Here, we have created a function with a shorter name log relative to console.log(), you can even use a shorter name, something like this:

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

So, you might be wondering whats the benefit of writing code like this? Lets discuss the benefits.

Benefits

Keeps your code clean and slick
Improve readability
Relief to your fingers, dont have to write a long thing
Comment more benefits if you can.

Lets test

log("Hello world") // Hello worldlog(4 + 4) // 8log(!false) // truelog(Math.PI) // 3.141592653589793

Conclusion

So, this was a quick tip to save your time and make your code look cleaner. Let me know in the comments if you will use this tip.

You can try the same thing for the console.info(), console.warn(), console.error().

Lets connect

LinkedIn

Twitter

Read More

A Complete Guide to WEB 3.0

How to upload files to aws s3 using nodejs lambda and api gateway


Original Link: https://dev.to/braincuber_technologies/its-2022-dont-use-the-consolelog-anymore-51dn

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To