Comments on: console.delight https://frontendmasters.com/blog/console-delight/ Helping Your Journey to Senior Developer Mon, 26 Feb 2024 10:55:56 +0000 hourly 1 https://wordpress.org/?v=6.5.2 By: Andy Fuchs https://frontendmasters.com/blog/console-delight/#comment-1073 Mon, 26 Feb 2024 10:55:56 +0000 https://frontendmasters.com/blog/?p=362#comment-1073 In reply to John.

You can get JS to work, but you must make sure it is evaluated at runtime like this (otherwise it is static):

const timestamp = () => {};
timestamp.toString = function() {
    const date = new Date();
    const hours = date.getHours().toString().padStart(2, '0');
    const minutes = date.getMinutes().toString().padStart(2, '0');
    const seconds = date.getSeconds().toString().padStart(2, '0');
    const milliseconds = date.getMilliseconds().toString().padStart(3, '0');
    return `${hours}:${minutes}:${seconds}:${milliseconds}`;
};

// log with a mark, color, and timestamp
// e.g.: 
// 08:35:01:232 [LOG]  This log message shows a red tag and timestamp
log = console.log.bind(console, `%s %c[LOG] `, timestamp, `color:#FC0`);

// then:
log('Hello World');

I use it everywhere in my code to better identify classes/modules, etc… in the console.
You can also use it in node to show timestamps in files.

]]>
By: Speed https://frontendmasters.com/blog/console-delight/#comment-1042 Mon, 26 Feb 2024 02:30:20 +0000 https://frontendmasters.com/blog/?p=362#comment-1042 In reply to Roger.

Go to Facebook and open up the browser console. They use it for something useful.

]]>
By: Chris Coyier https://frontendmasters.com/blog/console-delight/#comment-736 Mon, 12 Feb 2024 16:39:32 +0000 https://frontendmasters.com/blog/?p=362#comment-736 In reply to Roger.

Use case: fun.

]]>
By: Roger https://frontendmasters.com/blog/console-delight/#comment-728 Sun, 11 Feb 2024 10:13:04 +0000 https://frontendmasters.com/blog/?p=362#comment-728 Well well well…

It is not because you CAN that you SHOULD…

I cannot think of a use case where this feature would be useful.

Prove me wrong.

]]>
By: John https://frontendmasters.com/blog/console-delight/#comment-357 Fri, 19 Jan 2024 09:20:29 +0000 https://frontendmasters.com/blog/?p=362#comment-357 Interesting, ty
ps: I couldn’t get any JS to work, (including your date example, it just displays the hardcoded date and not one set with JS)

]]>
By: pp https://frontendmasters.com/blog/console-delight/#comment-352 Thu, 18 Jan 2024 23:06:30 +0000 https://frontendmasters.com/blog/?p=362#comment-352 Usefull console.table than more that.

]]>