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!")
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
Let's work a little smarter and more efficient π
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, Ummm π€ something like this...
const l = (arg) => console.log(arg)
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
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
Top comments (1)
should work too