Here’s a breakdown of the key ES6 features natively available in Node.js without the --harmony flag:
1. Block Scoping: let and const
let - Block-scoped variable declaration.
const - Block-scoped constant declaration.
let x = 10;
const y = 20;
2. Arrow Functions (=>)
Lexical this binding, shorter syntax for functions.
const add = (a, b) => a + b;
3. Template Literals
String interpolation and multiline strings.
const name = 'Ram';
console.log(`Hello, ${name}!`);
4. Classes
Class-based object-oriented programming.
class Person {
constructor(name) {
this.name = name;
}
greet() {
return `Hello, ${this.name}!`;
}
}
5. Default Parameters
Function parameters with default values.
function greet(name = 'User') {
return `Hello, ${name}!`;
}