Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 12, 2022 03:04 pm GMT

Shorten The Console.log

Tired of writing console.log() again and again ??? the the following JS tip is for you .

You can shorten the log() function with the help of Function.prototype.bind .

Since ES5, all functions have a bind method that allows one to create a new function specifying the context.

Use bind method to pre-define the context execution to always point to console. This way, no matter how the function is invoked, we are instructing the JavaScript engine to always set the context execution to console.

const C = console.log.bind(console);C("Downloaded Successfully !!!");// Downloaded Successfully !!!C("Code Executed Successfully !!!");// Code Executed Successfully !!!

Original Link: https://dev.to/shamgurav96/shorten-the-consolelog-25h8

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