A faster way to write console.log ⚡

As developers we are always seeking innovative ways to boost our productivity 🚀. Today I bring you a clever hack to log stuff to the console faster 😎.

Let’s begin!

The 3 most used methods of the console object in JavaScript are log ✏️, warn ⚠️ and …


This content originally appeared on DEV Community and was authored by Carlos Dubón

As developers we are always seeking innovative ways to boost our productivity 🚀. Today I bring you a clever hack to log stuff to the console faster 😎.

To the moon

Let's begin!

The 3 most used methods of the console object in JavaScript are log ✏️, warn ⚠️ and error ❌:

console.log("Hello world 🌎"); // "Hello world 🌎"
console.warn("Hmm... 🤔"); // "Hmm... 🤔"
console.error("Oops! 🚨"); // "Oops! 🚨"

We can make use of object destructuring to extract ⛏️ these methods from the console object and bind them to constants:

const { log, error, warn } = console;

Now that we have extracted these methods from the console object we can call them from anywhere ✨:

const { log, error, warn } = console;

log("Hello world 🌎"); // "Hello world 🌎"
warn("Hmm... 🤔"); // "Hmm... 🤔"
error("Oops! 🚨"); // "Oops! 🚨"

If you plan to reuse this behavior across your entire app just add an export statement 📦:

// utils.js

export const { log, error, warn } = console;
// app.js

import { log } from "./utils.js";

log("Hello world 🌎"); // "Hello world 🌎"

And that's all folks. I hope you have found this post helpful and that I’ve made your development process a lil faster ⚡😉.

Dog over turtle


This content originally appeared on DEV Community and was authored by Carlos Dubón


Print Share Comment Cite Upload Translate Updates
APA

Carlos Dubón | Sciencx (2021-10-18T17:07:58+00:00) A faster way to write console.log ⚡. Retrieved from https://www.scien.cx/2021/10/18/a-faster-way-to-write-console-log-%e2%9a%a1/

MLA
" » A faster way to write console.log ⚡." Carlos Dubón | Sciencx - Monday October 18, 2021, https://www.scien.cx/2021/10/18/a-faster-way-to-write-console-log-%e2%9a%a1/
HARVARD
Carlos Dubón | Sciencx Monday October 18, 2021 » A faster way to write console.log ⚡., viewed ,<https://www.scien.cx/2021/10/18/a-faster-way-to-write-console-log-%e2%9a%a1/>
VANCOUVER
Carlos Dubón | Sciencx - » A faster way to write console.log ⚡. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/18/a-faster-way-to-write-console-log-%e2%9a%a1/
CHICAGO
" » A faster way to write console.log ⚡." Carlos Dubón | Sciencx - Accessed . https://www.scien.cx/2021/10/18/a-faster-way-to-write-console-log-%e2%9a%a1/
IEEE
" » A faster way to write console.log ⚡." Carlos Dubón | Sciencx [Online]. Available: https://www.scien.cx/2021/10/18/a-faster-way-to-write-console-log-%e2%9a%a1/. [Accessed: ]
rf:citation
» A faster way to write console.log ⚡ | Carlos Dubón | Sciencx | https://www.scien.cx/2021/10/18/a-faster-way-to-write-console-log-%e2%9a%a1/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.