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 !!!
Top comments (0)