Sobes.tech
Junior — Middle

What distinguishes ECMAScript 5 syntax and features from ECMAScript 6?

sobes.tech AI

Answer from AI

ECMAScript 6 (ES6) significantly expanded the capabilities of the language compared to ECMAScript 5 (ES5). Main differences:

  • Variable declarations: ES5 uses var, ES6 added let and const for block scope.
  • Arrow functions: concise syntax for functions.
  • Classes: syntactic sugar for prototypal inheritance.
  • Modules: import and export for organizing code.
  • Template strings: convenient string interpolation with backticks.
  • Destructuring: easy way to extract data from arrays and objects.
  • Promises: for working with asynchronous code.

Example of an arrow function and a template string in ES6:

const greet = name => `Hello, ${name}!`;
console.log(greet('World'));

ES6 improved code readability and ease of writing, as well as expanded language capabilities.