Modern JavaScript
Modern JavaScript provides cleaner, shorter and more powerful ways to write JavaScript programs.
What is Modern JavaScript?
Modern JavaScript refers to the newer features introduced in JavaScript to make code easier to read, maintain and develop.
These features include let, const, template literals, arrow functions, spread and rest operators, destructuring and modules.
Simple Definition
Modern JavaScript means using newer JavaScript features and syntax to write clean, readable and maintainable code.
Modern JavaScript helps developers write cleaner and more efficient code.
Example 1: let and const
Modern JavaScript provides let and const for declaring variables.
let name = "Rahul";
const course = "JavaScript";
console.log("Name:", name);
console.log("Course:", course);
Course: JavaScript
Example 2: Template Literals
Template literals allow us to create strings using backticks and easily insert variables using ${}.
let name = "Rahul";
let course = "JavaScript";
let message = `Welcome ${name} to ${course}`;
console.log(message);
Example 3: Arrow Function
Arrow functions provide a shorter syntax for writing functions.
const add = (a, b) => {
return a + b;
};
console.log("Result:", add(10, 20));
Example 4: Spread Operator
The spread operator ... can be used to expand elements of an array.
let numbers1 = [10, 20];
let numbers2 = [30, 40];
let numbers = [...numbers1, ...numbers2];
console.log(numbers);
Example 5: Destructuring
Destructuring allows us to extract values from arrays or objects into separate variables.
const student = {
name: "Amit",
age: 22
};
const { name, age } = student;
console.log("Name:", name);
console.log("Age:", age);
Age: 22
Why Use Modern JavaScript?
✔ Cleaner code
✔ Shorter syntax
✔ Better readability
✔ Easier maintenance
✔ Useful for modern web applications
Summary
Modern JavaScript introduces powerful features that make JavaScript development easier and more efficient. Important features include let and const, template literals, arrow functions, spread operators and destructuring.