← #43 Log a value to the Console
#44

Use short-circuits conditionals

Topics: JavaScript

If you want to execute a function when a condition matches, then use short-circuit to shorten the code:

if (formValid) {
submitForm();
}

// Use short-circuit
formValid && submitForm();

The logical OR operator || is used in a simliar way:

!formValid || submitForm();

In the modern web frameworks, we can use the similar syntax to render a given component when a condition satisfies.
The following sample code gives you the idea of conditional rendering in React:

{
unreadMessages.length > 0 && (
<div>You have {unreadMessages.length} unread messages.</div>
)
}
Fix a typo or suggest an improvement
#45 Get the current timestamp