0%
ES6+ JavaScript Features Made Easy: A Friendly Guide

ES6+ JavaScript Features Made Easy: A Friendly Guide

Discover the coolest ES6+ tricks—let, arrow functions, templates, and more—explained with simple examples you can start using today!

Saransh Pachhai
Saransh Pachhai
5 min read5 viewsApril 5, 2026
javascriptes6webdevprogrammingtutorial
Share:

ES6+ JavaScript Features Made Easy

Welcome! If you’ve been writing JavaScript for a while, you’ve probably heard the term ES6 (or ES2015) tossed around. It’s a big update that added many useful features to the language. In this post we’ll walk through the most popular ones, show you clear examples, and give you handy tips you can apply right away.

1. Let and Const – Safer Variable Declarations

Before ES6 we used var for everything. It works, but it has quirks: hoisting (variables appear to be moved to the top) and function‑wide scope can cause bugs.

Enter let and const:

  • let creates a block‑scoped variable. It can be reassigned.
  • const also creates a block‑scoped variable, but you cannot reassign it.
// let example
let counter = 0;
if (true) {
  let counter = 10; // this counter lives only inside the block
  console.log(counter); // 10
}
console.log(counter); // 0 (outside block)

// const example
const API_URL = 'https://api.example.com';
// API_URL = 'https://evil.com'; // ❌ throws an error

Takeaway: Use const by default. Switch to let only when you really need to change the value.

2. Arrow Functions – Shorter, Cleaner Callbacks

Callbacks are everywhere in JavaScript (think map, filter, event listeners). Regular function syntax can be wordy. Arrow functions (=>) shrink them dramatically.

// Traditional function
const numbers = [1, 2, 3];
const doubled = numbers.map(function(n) {
  return n * 2;
});

// Arrow function – same result, less code
const doubled = numbers.map(n => n * 2);

Two extra perks:

  1. No own this. Arrow functions inherit this from the surrounding scope, which avoids many common bugs.
  2. If you have only one argument, you can drop the parentheses.

Takeaway: Convert simple callbacks to arrow syntax. It makes your code easier to read.

3. Template Literals – Easy String Interpolation

Creating strings with variables used to require messy concatenation:

const name = 'Alice';
const greeting = 'Hello, ' + name + '! Welcome back.';

Template literals, surrounded by backticks (`), let you embed expressions directly with ${...}. They also support multi‑line strings.

const name = 'Alice';
const greeting = `Hello, ${name}!\nWelcome back.`;
console.log(greeting);
// Output:
// Hello, Alice!
// Welcome back.

Great for building HTML snippets, URLs, or any dynamic text.

Takeaway: Switch to backticks when you need variable substitution or line breaks.

4. Destructuring & Spread – Pull Out What You Need

Destructuring lets you unpack values from arrays or objects into distinct variables. No more repetitive obj.prop calls.

// Object destructuring
const user = {id: 42, name: 'Bob', role: 'admin'};
const {id, name} = user;
console.log(id, name); // 42 Bob

// Array destructuring
const colors = ['red', 'green', 'blue'];
const [first, second] = colors;
console.log(first, second); // red green

The spread operator (...) copies elements or properties. It’s handy for merging objects, cloning arrays, or passing arguments.

// Clone an array
const original = [1, 2, 3];
const copy = [...original];
copy.push(4);
console.log(original); // [1,2,3] – untouched

// Merge objects
const defaults = {host: 'localhost', port: 80};
const options = {port: 8080, path: '/api'};
const config = {...defaults, ...options};
console.log(config); // {host:'localhost', port:8080, path:'/api'}

Takeaway: Use destructuring for clearer code, and spread for quick copies or merges.

5. Modules – Keep Your Code Organized

Old JavaScript relied on global variables or messy script tags. ES6 introduced modules with import and export. Each file becomes its own module, keeping the namespace clean.

// math.js – a module file
export function add(a, b) { return a + b; }
export const PI = 3.1415;

// main.js – another file that uses the module
import {add, PI} from './math.js';
console.log(add(2, 3)); // 5
console.log(PI); // 3.1415

Modules also support default exports (useful when a file only exports one thing).

// logger.js
export default function log(msg) { console.log('[LOG]', msg); }

// app.js
import log from './logger.js';
log('App started');

Remember to serve your files over a server (not the file system) so the browser can resolve module paths.

Takeaway: Split large codebases into small modules. It improves readability and reusability.

6. Async/Await – Write Asynchronous Code Like Synchronous Code

Promises already made async flows clearer, but they still need .then() chains. async functions paired with await let you pause execution until a Promise resolves, looking just like regular code.

// Simulated fetch function returning a promise
function fetchUser(id) {
  return new Promise(resolve => {
    setTimeout(() => resolve({id, name: 'Sam'}), 1000);
  });
}

// Using async/await
async function showUser(id) {
  console.log('Loading...');
  const user = await fetchUser(id); // wait here
  console.log('User:', user);
}

showUser(7);

Errors are caught with normal try / catch blocks, keeping error handling straightforward.

async function safeFetch() {
  try {
    const data = await fetch('/api/data');
    return await data.json();
  } catch (err) {
    console.error('Fetch failed', err);
  }
}

Takeaway: Replace complex promise chains with async/await for cleaner, more maintainable code.

Actionable Takeaways

  • Start every new file with const or let. Reserve var for legacy code only.
  • Convert simple callbacks to arrow functions. Watch out for the this binding.
  • Use backticks for any string that needs a variable or a line break.
  • Destructure objects and arrays whenever you need only a few pieces of data.
  • Adopt the spread operator for quick copies, merges, or argument forwarding.
  • Break your project into modules. Export only what you need.
  • Prefer async/await over .then() chains for readability.

Try applying one of these tips today. In a few minutes you’ll see your code become shorter, clearer, and less error‑prone.

Happy coding!

Loading comments...

Designed & developed with❤️bySaransh Pachhai

©2026. All rights reserved.

ES6+ JavaScript Features Made Easy: A Friendly Guide | Saransh Pachhai Blog