DEV Community

Cover image for It's 2022, don't use the console.log(😎)
Dhairya Shah
Dhairya Shah

Posted on β€’ Originally published at codewithsnowbit.hashnode.dev

6

It's 2022, don't use the console.log(😎)

We as Javascript developers usually console.log() stuffs to test the output or just for fun. Even, I can bet that our (include me ✌️) first code was "Hello world" logged in the console.

console.log("Hello World!")
Enter fullscreen mode Exit fullscreen mode

This piece of code has been nostalgic for all fellow JS developers. But now it's 2022, let's 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.

Let's get started

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

console.log("I love js") // I love js

console.log(4 + 4) // 8

console.log(!true)  // false
Enter fullscreen mode Exit fullscreen mode

Let's work a little smarter and more efficient 😎

const log = (arg) => console.log(arg)
Enter fullscreen mode Exit fullscreen mode

Here, we have created a function with a shorter name - log relative to console.log(), you can even use a shorter name, Ummm πŸ€” something like this...

const l = (arg) => console.log(arg)
Enter fullscreen mode Exit fullscreen mode

So, you might be wondering what's the benefit of writing code like this? Let's discuss the benefits.

Benefits

  • Keeps your code clean and slick
  • Improves readability
  • Relief to your fingers, don't have to write a long thing

comment more benefits if you can...

Let's test πŸš—

log("Hello world") // Hello world
log(4 + 4) // 8
log(!false) // true
log(Math.PI) // 3.141592653589793
Enter fullscreen mode Exit fullscreen mode

Try yourself - fiddle

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 console. info(), console.warn(), console.error()


Feel free to reach me out via Twitter - @codewithsnowbit

🌏 Let's connect

Stay tuned for the next article. Stay safe and Happy Coding!

If you enjoyed and find my content helpful, then you can check this out
Buy me a coffee

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
tzwel profile image
tzwel β€’
const l = console.log
Enter fullscreen mode Exit fullscreen mode

should work too

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay