JavaScript

ES6+ Modern Features

Master modern JavaScript! Learn template literals, optional chaining, nullish coalescing, and more ES6+ features.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Master modern JavaScript! Learn template literals, optional chaining, nullish coalescing, and more ES6+ features. This hands-on tutorial focuses on practical implementation of es6+ modern features concepts.

ES6+ Modern Features

Modern JavaScript (ES6 and later versions) introduced powerful features that make code cleaner, more readable, and more expressive. In this chapter, we'll explore these essential tools.

1. Template Literals πŸ“

What are they? Template literals are a new way to create strings using backticks (`) instead of single or double quotes.

Why use them? They allow for:

  • String Interpolation: Embedding variables directly into strings.
  • Multi-line Strings: Creating strings that span multiple lines without special characters.

How it works: Use ${variable} to insert values.

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

2. Optional Chaining (?.) πŸ”—

What is it? Optional chaining allows you to safely access nested properties of an object without worrying if an intermediate property exists.

Why use it? It prevents the dreaded TypeError: Cannot read properties of undefined error. If a property doesn't exist, it simply returns undefined instead of crashing your app.

How it works: Place ?. before the property you want to access.

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

3. Nullish Coalescing (??) 🎯

What is it? A logical operator that returns the right-hand side operand only when the left-hand side is null or undefined.

Why use it? The standard OR operator (||) falls back for any falsy value (like 0, "", or false). Sometimes you want to keep 0 or "" as valid values and only fall back if the value is truly missing (null or undefined).

How it works: left ?? right

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

4. Default Parameters 🎁

What are they? Default parameters allow you to initialize named parameters with default values if no value or undefined is passed.

Why use them? To make your functions more robust and handle missing arguments gracefully without writing extra check logic inside the function.

How it works: Assign a value in the function definition: function(a = 1).

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

5. Enhanced Object Literals 🎨

What are they? Shorthand syntax for defining properties and methods in objects.

Why use them? They reduce boilerplate code when creating objects, making your code cleaner.

How it works:

  • Property Shorthand: { name } instead of { name: name }
  • Method Shorthand: sayHi() {} instead of sayHi: function() {}
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

6. Modern Array & Object Methods πŸ› οΈ

ES6+ also added useful utility methods.

  • Object.entries(): Returns an array of [key, value] pairs.
  • Object.values(): Returns an array of values.
  • Array.from(): Creates an array from an array-like object (like a String or NodeList).
JAVASCRIPT PLAYGROUND
⏳ Loading editor…

Practical Examples πŸ’‘

Let's combine these features into a real-world scenario.

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "ES6+ features, template literals, optional chaining, nullish coalescing, default parameters, and object enhancements"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 4

What is the main benefit of Optional Chaining (?.)?

It makes code run faster
It safely accesses nested properties without errors
It creates new properties automatically
It validates data types

Key Takeaways

βœ… Template Literals ( ): Easy string interpolation and multi-line strings.
βœ… Optional Chaining (?.): Safe access to nested properties.
βœ… Nullish Coalescing (??): Smarter default values (handles 0 and "" correctly).
βœ… Default Parameters: Set default values for function arguments.
βœ… Object Shorthands: Cleaner syntax for creating objects.

What's Next?

These features are used everywhere in modern frameworks like React. Next, let's look at Modules to see how to organize your code!

Keep coding! πŸš€