Language features

Verze:

19. 06. 2025

Zodpovědná osoba:

Dominik Šlechta

Prefer Modern JavaScript Features

 

  • Rule: Prefer modern JavaScript features from the latest ECMAScript standards, such as:

    • let and const for variable declarations

    • Arrow functions for function expressions

    • Template strings for complex string concatenation

    • Destructuring for object or array manipulation

  • Reason: Using modern JavaScript features improves readability, reduces errors, and ensures that the code takes advantage of recent improvements in the language.

Example (Correct):

const user = { name: 'John', age: 30 };
const { name, age } = user;  // Destructuring
console.log(`Hello, ${name}. You are ${age} years old.`);  // Template string

Example (Incorrect):

var user = { name: 'John', age: 30 };
var name = user.name;
var age = user.age;
console.log('Hello, ' + name + '. You are ' + age + ' years old.');

Summary:

  • Modern JavaScript: Prefer the latest ECMAScript features such as let, const, arrow functions, template strings, and destructuring.