Member-only story
5 Must-Know JavaScript Features That You Might Not Know
Let’s learn some cool JavaScript tricks to make your code look and work better
Have you ever been amazed by a developer using some cool JavaScript feature you had never seen before? Well, this happens to me all the time. And since programming is all about constant learning, I’m sure you’ve felt the same way at some point in time.
In this article, I’m going to share five JavaScript features that I always use that help my code look cleaner. Let’s get started.
1. Nullish Coalescing Operator (??)
Here’s the official definition from MDN Web Docs:
“The nullish coalescing operator (
??
) is a logical operator that returns its right-hand side operand when its left-hand side operand isnull
orundefined
, and otherwise returns its left-hand side operand.”
To understand this operator, let’s take an example.
Let’s say we have a simple JavaScript function that accepts three parameters (price
, taxes
, and description
) and simply prints the total price of an item with taxes in the console. Something like this:
function calculatePrice(price, taxes, description) { const total = price * (1 +…