Destructuring the console object
JavaScriptAll snippets in this category →
Posted on console
is an object like any other. That means we can destructure from it like we do with other objects as well. The saved keystrokes might harm readability, so use this at your own discretion.
// Tired of writing “console.” all the time?
console.log("This sure is tiresome.")
console.warn("That’s a lotta keystrokes.")
// Destructure the functions from the console object.
const { log, warn } = console
log("Look ma, no console!")
warn("I’m going to let you do whatever.")
// Tired of writing “console.” all the time?
console.log("This sure is tiresome.")
console.warn("That’s a lotta keystrokes.")
// Destructure the functions from the console object.
const { log, warn } = console
log("Look ma, no console!")
warn("I’m going to let you do whatever.")
// Tired of writing “console.” all the time?
console.log("This sure is tiresome.")
console.warn("That’s a lotta keystrokes.")
// Destructure the functions from the console object.
const { log, warn } = console
log("Look ma, no console!")
warn("I’m going to let you do whatever.")
// Tired of writing “console.” all the time?
console.log("This sure is tiresome.")
console.warn("That’s a lotta keystrokes.")
// Destructure the functions from the console object.
const { log, warn } = console
log("Look ma, no console!")
warn("I’m going to let you do whatever.")