Top 10 JavaScript ES12 Features That Make Everyday Coding Easier | Syncfusion Blogs
Loader
Top 10 JavaScript ES12 Features That Make Everyday Coding Easier

Summarize this blog post with:

TL;DR: JavaScript ES12 brings practical improvements that make code cleaner, safer, and easier to maintain. Explore ten essential features that help write efficient code, avoid bugs, and simplify development without changing how you think about JavaScript.

Why does JavaScript keep evolving?

JavaScript isn’t changing to keep up with trends; it’s changing to keep up with developers.

Every year, the ECMAScript (ES) specification incorporates lessons learned from real‑world usage: common mistakes, repeated patterns, and long‑standing pain points. The goal isn’t to reinvent the language, but to make everyday JavaScript feel more natural and less error‑prone.

What makes ES12 different?

ES12 introduces practical, small improvements to make code clearer and more efficient, with no flashy syntax changes.

If you’ve ever written extra checks to avoid runtime errors, duplicated logic to handle defaults, or struggled to keep code readable as it grows, ES12 addresses those exact problems.

Who should care about these features?

This guide is for developers who already uses JavaScript and want to:

  • Write cleaner, more predictable code.
  • Reduce bugs caused by edge cases.
  • Adopt modern, stable features without added complexity.

Below, we’ll explore 10 JavaScript ES12 features and show how they make everyday development easier.

Syncfusion JavaScript UI controls are the developers’ choice to build user-friendly web applications. You deserve them too.

1. Let & const

let creates variables that are only available inside the block where they are defined (like inside { … }). This helps avoid mistakes where variables accidentally affect code outside that block. You can change the value of a let variable later, but you cannot use it before you declare it; this is called the Temporal Dead Zone (TDZ).

Use let when the value changes, especially inside loops or if statements.

{
 // console.log(count); // Reference error due to TDZ
 let count = 0;
 count += 2;
 console.log(count);
}
// output: 2

const creates a variable you set once and cannot change later. This clearly tells anyone reading your code, “this value should stay the same.” But keep in mind, const only stops you from replacing the variable; it doesn’t freeze the contents. If you use const with an object or array, you can still update its properties or items, just not reassign the object itself.

Use const by default. Switch to let only when reassignment is necessary.

Code example (no reassignment)

const apiVersion = "v1";
// apiVersion = "v2"; // TypeError in strict mode / reassignment not allowed
console.log(apiVersion);
// output: v1

Code example (object rebinding)

const config = { debug: false };
config.debug = true; // Allowed: mutating object property
console.log(config.debug);
// config = {}; // Not allowed: rebinding the identifier
//output: true

2. Arrow function

Arrow functions help us write functions in a shorter way, and automatically use them from the code around them. They don’t have their own this, arguments, or prototype, and cannot be used as constructors.

Use them for callbacks, array operations, and methods that depend on the outer this. Use regular functions if you need your own this or arguments.

const nums = [1, 2, 3];
const doubled = nums.map(n => n * 2);
console.log(doubled);
// output: [2, 4, 6]

3. Destructuring

Destructuring lets you unpack values from arrays or properties from objects into individual variables in a single, clean statement. Instead of writing multiple lines to access values, you can extract them directly in a structured way.

const colors = ["red", "green", "blue"];

// Extract first two values
const [firstColor, secondColor] = colors;

console.log(firstColor);
console.log(secondColor);

// output:
red
green

4. Template literals

Template literals are one of the most useful modern JavaScript features. Instead of using regular quotes ‘ ‘ or ” “, we can use backticks `. This simple change makes strings more powerful and easier to work with.

With template literals, you can:

  • Write text on multiple lines without using \n or concatenation.
  • Insert variables directly inside the string using ${variable}.
  • Embed expressions like calculations, conditions, or even function calls inside ${}.
    const name = "Alice";
    const age = 25;
    
    const message = `Hello, ${name}!
    Next year, you will be ${age + 1} years old.`;
    
    console.log(message);
    
    // Output
    Hello, Alice!
    Next year, you will be 26.

Everything a developer needs to know to use JavaScript control in the web app is completely documented.

5. Optional chaining

Optional chaining is an easier way to safely access nested properties in JavaScript without causing errors. Instead of manually checking every level, we can use ?. to stop the lookup if something is null or undefined, and the whole expression returns undefined.

With optional chaining, we can:

  • Access deeply nested properties safely: obj?.a?.b?.c
  • Safely read array items: arr?.[0]?.name
  • Safely call functions only if they exist: fn?.()
    const user = {
      profile: { name: "Alice" },
      friends: [{ name: "Ravi" }],
      getGreeting: null
    };
    
    // Safely access nested properties, array items, and function calls
    const city = user.profile?.address?.city; // address is missing → undefined
    const firstFriend = user.friends?.[0]?.name; // "Ravi"
    const greeting = user.getGreeting?.(); // function is null → undefined (no error)
    
    console.log(city);
    console.log(firstFriend);
    console.log(greeting);
    
    // Output
    undefined
    Ravi
    undefined

6. Logical assignment operators

JavaScript already supports arithmetic and bitwise assignment operators. In ES12, it has extended support for logical assignment operators.

There are three new logical assignment operators:

  • Logical Nullish Assignment (??=)
  • Logical AND Assignment (&&=)
  • Logical OR Assignment (||=)

Even though the syntax looks like an arithmetic assignment operator (+=), the logical assignment operators will not always perform the assignment. Instead, the assignment would happen only if the condition defined by the logical operator is met.

6.1 Logical nullish assignment

The logical nullish assignment operator (??=) will assign the value of the right operand to the left operand only if the left operand is null or undefined (nullish).

At first glance, the ??= operator might look a bit confusing because the expanded form of this operator is equivalent to x ?? (x = y).

const person = { name: 'John' };

person.name ??= 'User 1';
console.log(person.name); // output: John

person.age ??= 18;
console.log(person.age);  // output: 18

If we were to use an older ES version, the above code would look like the following:

const person = { name: 'John' };

if (person.name === undefined || person.name === null) {
  person.name = 'User 1';
}
console.log(person.name);

if (person.age === undefined || person.age === null) {
  person.age = 18;
}
console.log(person.age);

6.2 Logical AND assignment

The logical AND assignment operator (&&=) will perform the assignment if the left operand is truthy. Since we just covered the nullish assignment, usage of the logical AND assignment operator is pretty much self-explanatory.

const product = { stocks: 10 };

product.stocks &&= 20;
console.log(product.stocks); // output: 20

product.exp &&= '12/31/2021';
console.log(product.exp); // output: undefined

6.3 Logical OR assignment

The logical OR assignment operator (||=) is similar to the nullish assignment, but the left operand should be false for the assignment to occur. A value is considered false if it is null, undefined, false, 0, or NaN.

const product = {
  stocks: 0,
  exp: '12/31/2021'
};

product.stocks ||= 10;
console.log(product.stocks); // output: 10

product.exp ||= '01/31/2022';
console.log(product.exp); // output: 12/31/2021

To make it easy for developers to include Syncfusion JavaScript controls in their projects, we have shared some working ones.

7. Private class fields

Private class fields in JavaScript let you create properties inside a class that cannot be accessed or modified from outside the class. This helps keep internal details hidden and prevents accidental changes, making your code more secure and maintainable.

To declare a private field, prefix its name with a # inside the class. These fields are only accessible within the class methods.

class User {
  #password; // private field

  constructor(name, password) {
    this.name = name;
    this.#password = password;
  }

  checkPassword(input) {
    return input === this.#password;
  }
}

const user = new User("Alice", "secret123");

console.log(user.name); // Alice
console.log(user.checkPassword("secret123")); // true
console.log(user.#password); // Error: Private field '#password' must be declared in an enclosing class

// Output
Alice
true
Error: Private field '#password' must be declared in an enclosing class

8. Iterator helpers

ES12 introduced iterator helpers such as map, filter, take, and drop, making working with iterators even easier. An iterator is like a tool that lets you go through a list of items one by one without having to load the entire list at once.

Before this, you had to convert iterators into arrays to transform them, which could use up a lot of memory for big lists or large data sets. With iterator helpers, you can process data step by step without creating additional arrays.

const users = [
  { name: 'Alice', age: 25, active: true },
  { name: 'Bob', age: 30, active: false },
  { name: 'Charlie', age: 35, active: true }
];

// Chain operations without creating intermediate arrays
const result = users.values()
  .filter(user => user.active)
  .map(user => user.name.toUpperCase())
  .take(2)
  .toArray();

console.log(result); // ['ALICE', 'CHARLIE']

9. New Set methods

Sets are great for storing unique values, and now they’re even better with built-in methods like union, intersection, and difference. These methods make combining and comparing sets easy without writing loops or extra logic.

const a = new Set([1, 2]);
const b = new Set([2, 3]);

console.log(a.union(b)); // Set {1, 2, 3}
console.log(a.intersection(b)); // Set {2}
console.log(a.difference(b)); // Set {1}

10. JSON module import

Working with JSON data requires extra steps like fetch or require, but now you can import JSON files directly as modules in modern JavaScript. This makes loading configuration or static data simple and efficient.

import config from './config.json' assert { type: 'json' };

console.log(config.apiUrl);

Frequently Asked Questions

What’s the difference between let and const in JavaScript?

Use const by default for identifiers that should not be reassigned; use let only when you need reassignment. Both are block-scoped and subject to the Temporal Dead Zone (TDZ). const prevents rebinding of the identifier but does not make objects immutable.

When should I use arrow functions vs regular functions?

Use arrow functions for concise callbacks and when you want to capture this from the surrounding scope. Use regular functions when you need your own this, arguments, or when creating constructors.

Why use template literals instead of string concatenation?

Template literals support multiline strings and let you interpolate variables and expressions using ${…}, which makes string building clearer and less error-prone.

What is optional chaining, and when should I use it?

Optional chaining (?.) safely accesses nested properties, array items, and callable members. If any link in the chain is nullish, the expression short-circuits to undefined instead of throwing an error.

What are logical assignment operators (??=, &&=, ||=)?

They combine logical checks with assignment. ??= assigns only if the left side is nullish; &&= assigns only if the left side is true; ||= assigns only if the left side is false. They reduce verbose guard code for default and update cases.

Can I import JSON files directly in JavaScript?

Yes, modern JavaScript supports importing JSON files as modules using:
import config from ‘./config.json’ assert { type: ‘json’ };

How do modern JavaScript features work with Syncfusion Essential JS2 components?

Syncfusion Essential JS2 components are built using modern JavaScript standards, so features like let/const, arrow functions, and destructuring fit perfectly. They make your code cleaner when configuring components or handling events.


Easily build real-time apps with Syncfusion’s high-performance, lightweight, modular, and responsive JavaScript UI components.

Conclusion

Thanks for reading! JavaScript ES12 doesn’t ask you to relearn the language. It builds on what developers already do, refining common patterns and turning best practices into first‑class features.

By adopting these changes, you:

  • Write clearer code with less effort.
  • Avoid entire categories of runtime errors.
  • Make your intent obvious to anyone reading your code.

Modern JavaScript isn’t about writing clever code! It’s about writing reliable, maintainable code that ages well. ES12 quietly helps you do exactly that.

Syncfusion Essential JS 2 is the only suite you will ever need to build an application. It contains over 145+ high-performance, lightweight, modular, and responsive UI components in a single package. Download the free trial to evaluate the controls today.

If you have any questions or comments, you can contact us through our support forumssupport portal, or feedback portal. We are always happy to assist you!

Be the first to get updates

Dulanka KarunasenaDulanka Karunasena profile icon

Meet the Author

Dulanka Karunasena

Software Engineer | Mobile Developer | Technical Writer

Leave a comment