We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies. Learn More
contact@techquestworld.com
+919547614783
Premium Article
Published 4 months ago

Top 5 ES6 Tricks Most Developers Don't Know

5 min read
90 views
Top 5 ES6 Tricks Most Developers Don't Know
Photo by Techquestworld

Write modern and cleaner JavaScript with these 5 lesser-known but powerful ES6 tricks that can drastically improve your coding skills.

🔹 Destructuring Assignment

Think of destructuring as unpacking a backpack—you only pull out what you need from arrays or objects. It's a cleaner, faster way to grab values.

const user = { name: 'Imran', age: 28 };
const { name, age } = user;
console.log(name); // 'Imran'

🔹 Default Function Parameters

No more messy if undefined checks! Just set a default value inside the function's parameter list—it's simple, readable and saves time.

function greet(name = 'Guest') {
console.log(`Hello, ${name}`);
}
greet(); // Hello, Guest

🔹 Spread and Rest Operators

• Spread (...) expands arrays/objects

• Rest (...) collects arguments into an array

// Spread
const nums = [1, 2, 3];
const allNums = [...nums, 4, 5];

// Rest
function sum(...args) {
return args.reduce((a, b) => a + b, 0);
}
console.log(sum(1, 2, 3)); // 6

🔹 Template Literals

Say goodbye to string concatenation mess.

const name = 'TechQuest';
const message = `Welcome to ${name} Blog!`;
console.log(message);

🔹 Async / Await

Modern way to handle asynchronous code. No more .then() hell.

const fetchData = async () => {
try {
const res = await fetch('https://jsonplaceholder.typicode.com/posts/1');
const data = await res.json();
console.log(data);
} catch (err) {
console.error(err);
}
};

fetchData();


Trick No. ES6 Feature Use Case
1 Destructuring Cleaner variable access
2 Default Parameters Handle missing arguments
3 Spread / Rest Expand or collect values
4 Template Literals Easier string formatting
5 Async / Await Cleaner async code
Author
TAPAS SAHOO

Developer by Profession, Techie by Heart

A curious mind with a love for writing and technology, dedicated to simplifying web development and programming topics while keeping up with the ever-changing tech landscape.

Discussion (0)

Replying to
Previous Article
Node.js Async vs Await Explained with Real Ex...

Master async and await in Node.js with this easy guide. Includes real code examples, pros/cons and p...

Next Article
ExpressJS vs NestJS: Which Node.js Framework...

Discover the core differences between ExpressJS and NestJS. Whether you build APIs or full-scale app...

Related Articles