DEV Community

Discussion on: Javascript Tips for Beginners

Collapse
 
aminnairi profile image
Amin

Hi Henry and thanks for your article full of interesting advices!

When it comes to printing to the console by a predicate, I like to use one console and use the ternary operator inside the method call.

const value = 10;

console.log(value !== 0 ? `Value is ${value}` : "No value");
Enter fullscreen mode Exit fullscreen mode

This shorten the code a little bit more, while still keeping the conditional rendering of those strings.

Collapse
 
hb profile image
Henry Boisdequin

Great point! This way definitely is more concise and readable.