Hi there! Have you ever gotten a new version of your favorite game? Suddenly there are cooler characters, better graphics, and new powers that make everything more fun.
JavaScript got an update like that too. It’s called ES6.
Think of JavaScript as the language that makes websites do fun things—like pop-up messages, moving pictures, and interactive forms. For a long time, it worked okay, but writing it could be a bit… clunky.
Then ES6 arrived. It’s like JavaScript got a super-powered upgrade. It added new, shorter, and smarter ways to write code. These new ways are called JavaScript ES6 features.
Learning them is like learning the cool new shortcuts in your game. They make coding faster, easier to read, and more fun.
In this guide, we’ll explore 20 of these game-changing updates. Don’t worry if you’re new—I’ll explain everything like we’re just chatting. No confusing talk, I promise!
Let’s dive into these awesome JavaScript ES6 features together.
Part 1: Variables & Constants – Giving Things Better Names
In coding, we store information in containers called variables. ES6 gave us two new, better containers.
1. let and const (The Better Boxes)
- The Old Way: We only had
var. It was a loose box. Things could fall out or get mixed up easily. - The ES6 Way: We got
letandconst.let: A box you can change later. “Let the score be 10. Now let the score be 15.”const: A sealed box you can’t change. “Const is for my birthday—it’s always July 20th.”
- Why it’s great: It helps prevent mistakes. Use
constby default, andletonly when you need to change the value.
// Old Way var oldName = "Sam"; oldName = "Alex"; // This is allowed. // ES6 Way let changeableName = "Sam"; changeableName = "Alex"; // Allowed! const foreverName = "Sam"; // foreverName = "Alex"; // ERROR! Can't change a constant.
Part 2: Functions – Writing Less, Doing More
Functions are like little machines that do a task. ES6 made building these machines much simpler.
2. Arrow Functions (=>) (The Shortcut Machine)
- What it is: A shorter, cleaner way to write small functions.
- It looks like a little arrow
=>! - Why it’s great: You write way less code. It’s perfect for quick tasks.
// Old Way - A full function function addOld(a, b) { return a + b; } // ES6 Arrow Function - So short! const addNew = (a, b) => a + b;
3. Default Parameters (The Backup Plan)
- What it is: Giving a function a default value, just in case.
- Why it’s great: If someone forgets to give your machine the right part, it has a backup ready to go.
// If no name is given, it will use "Guest" function sayHello(name = "Guest") { console.log(`Hello, ${name}!`); } sayHello("Maria"); // "Hello, Maria!" sayHello(); // "Hello, Guest!" (Uses the default!)
Part 3: Working with Text & Data
4. Template Literals (Backtick Magic `)
- The Old Way: Combining words and variables was messy with
+signs. - The ES6 Way: Use backticks
`and${}to put variables right inside your text. - Why it’s great: It’s so much cleaner and easier to read!
let pet = "dog"; let age = 5; // Old Messy Way let oldSentence = "My " + pet + " is " + age + " years old."; // ES6 Clean Way let newSentence = `My ${pet} is ${age} years old.`;
5. Destructuring (The Unpacking Trick)
- What it is: Taking a box of items and unpacking them into separate variables in one step.
- Why it’s great: It saves you from writing long, boring lines of code to pull data out of objects and arrays.
// UNPACKING AN OBJECT let person = { firstName: "Jamie", job: "Designer" }; // Old way: // let name = person.firstName; // let job = person.job; // ES6 Destructuring - One line! let { firstName, job } = person; console.log(firstName); // "Jamie" // UNPACKING AN ARRAY let colors = ["red", "green", "blue"]; // Old way: // let firstColor = colors[0]; // let secondColor = colors[1]; // ES6 Destructuring let [firstColor, secondColor] = colors; console.log(firstColor); // "red"
Part 4: Loops & Arrays – Supercharged Lists
6. The for...of Loop (The Simple Looper)
- What it is: A new, cleaner way to loop through items in an array.
- Why it’s great: You don’t have to mess with counter numbers (
i). It just gives you each item, one by one.
let fruits = ["apple", "banana", "orange"]; // Old 'for' loop was more complex. // ES6 'for...of' is simple: for (let fruit of fruits) { console.log(`I like ${fruit}s.`); }
7. Spread Operator (...) (The Copy & Combine Tool)
- What it is: Three dots
...that “spread” an array or object out into its pieces. - Why it’s great: It makes copying arrays, combining them, or adding items super easy.
let list1 = ["A", "B", "C"]; let list2 = ["D", "E"]; // Copying an array let copy = [...list1]; // copy is now ["A", "B", "C"] // Combining arrays let combined = [...list1, ...list2]; // ["A", "B", "C", "D", "E"] // Adding to an array let newList = ["Start", ...list1, "End"]; // ["Start", "A", "B", "C", "End"]
8. Array Methods: .map(), .filter(), .find() (The Smart Helpers)
.map(): Takes a list, changes each item, and gives you a new list. “Map these raw ingredients into cooked food.”.filter(): Takes a list and gives you a new list with only items that pass a test. “Filter this box of toys to show only the red ones.”.find(): Looks through a list and gives you the first item that passes a test.
let numbers = [1, 2, 3, 4, 5]; // .map() - Double each number let doubled = numbers.map(num => num * 2); // [2, 4, 6, 8, 10] // .filter() - Get only even numbers let evens = numbers.filter(num => num % 2 === 0); // [2, 4] // .find() - Find the first number greater than 3 let bigNumber = numbers.find(num => num > 3); // 4
Part 5: Objects & Classes – Organized Code
9. Shorthand Property Names (The Lazy Typist’s Friend)
- What it is: If your variable name and the property name are the same, you only have to write it once.
- Why it’s great: Less typing means less chance for typos!
let name = "Taylor"; let age = 30; // Old Way let oldPerson = { name: name, age: age }; // ES6 Way (so clean!) let newPerson = { name, age };
10. Classes (The Blueprint Maker)
- What it is: A much nicer and clearer way to create object blueprints (constructors).
- Why it’s great: It looks more like other programming languages and is easier to understand when building complex things.
// Old constructor function was less clear. // ES6 Class is neat: class Dog { constructor(name) { this.name = name; } bark() { console.log(`${this.name} says Woof!`); } } let myDog = new Dog("Rex"); myDog.bark(); // "Rex says Woof!"
Part 6: Promises & Modules – Handling Complexity
11. Promises (The “I Owe You” Note)
- What it is: A cleaner way to handle tasks that take time (like loading data from the internet).
- The Old Way: Used messy “callbacks” (functions inside functions).
- Why it’s great: Promises make async code look almost like regular code, which is easier to follow.
// Simulating loading data function getData() { return new Promise((resolve) => { setTimeout(() => resolve("Here is your data!"), 1000); }); } // Using the promise getData().then(data => console.log(data));
12. Modules: import / export (The Code Organizer)
- What it is: A way to split your code into different files and use pieces where you need them.
- Why it’s great: You can keep your code organized, like having different drawers for socks, shirts, and pants.
// In a file called 'mathHelpers.js' export const add = (a, b) => a + b; export const pi = 3.14159; // In your main file import { add, pi } from './mathHelpers.js'; console.log(add(5, 10)); // 15
Part 7: More Cool Features
Here are some more fantastic JavaScript ES6 features that make life easier:
13. Rest Parameters (... again!)
- What it is: The three dots
...used to collect many arguments into a single array inside a function. - Why it’s great: You can make functions that accept any number of arguments easily.
// '...numbers' collects ALL arguments into an array function sumAll(...numbers) { let total = 0; for (let num of numbers) total += num; return total; } console.log(sumAll(1, 2, 3)); // 6 console.log(sumAll(5, 10, 15, 20)); // 50
14. String Methods: .startsWith(), .endsWith(), .includes()
- What they are: New, easy ways to check parts of a string.
- Why it’s great: No more complicated older methods. The names tell you exactly what they do!
let sentence = "The quick brown fox"; console.log(sentence.startsWith("The")); // true console.log(sentence.includes("brown")); // true console.log(sentence.endsWith("dog")); // false
15. Sets
- What it is: A special kind of collection that only stores unique values (no duplicates allowed!).
- Why it’s great: If you need a list where every item is different, a Set does the work for you automatically.
let mySet = new Set(); mySet.add("apple"); mySet.add("banana"); mySet.add("apple"); // This won't be added again! console.log(mySet); // Set { 'apple', 'banana' } (Only two items!)
Quick Reference Table: ES6 vs The Old Way
| What You Want To Do | The Old JavaScript Way | The ES6 Way (Better!) | Why ES6 Wins |
|---|---|---|---|
| Make a variable | var x = 5; |
const x = 5; or let x = 5; |
Clearer rules, fewer bugs. |
| Write a short function | function(a,b){return a+b;} |
(a,b) => a + b |
Much shorter & cleaner. |
| Put variables in text | "Hello " + name + "!" |
`Hello ${name}!` |
Easy to read and write. |
| Get data from an object | var n = obj.name; |
let {name} = obj; |
Unpacks many things at once. |
| Copy an array | Harder loops. | let copy = [...original]; |
One simple line. |
| Handle async tasks | Callback functions. | Promises & async/await |
Code is easier to follow. |
Your 5-Step Plan to Learn These JavaScript ES6 Features
Learning 20 new things can feel big. Let’s break it down.
- Step 1: Master the Big Three. Start with
let/const, Arrow Functions=>, and Template Literals`... ${} `. These three alone will change how you write code. - Step 2: Practice Destructuring & Spread. Play with unpacking objects
{a, b}and arrays[a, b]. Use the spread operator...to copy and combine things. This feels like a magic trick. - Step 3: Adopt Array Helpers. Stop writing long
forloops for simple tasks. Use.map()to change lists,.filter()to find things, and.find()to get one item. - Step 4: Re-write Old Code. Take a small project you wrote before. Go through it and ask: “Can I use an arrow function here? Can I use
const? Can I simplify this string?” This is the best practice. - Step 5: Explore One New Thing a Week. Pick one more feature from the list—like Promises or Classes. Spend a week just reading about it and trying tiny examples. Go slow.
Common Mistakes When Learning ES6
- Using
varout of habit. Train yourself to always ask: “Will this change?let. Will it not change?const.” Avoidvar. - Overusing arrow functions. They are great, but they behave differently with the
thiskeyword. For now, use them for simple, one-line functions. - Forgetting the backticks
`. You still need quotes" "for regular strings. Only use backticks when you need to put a variable inside${ }or break lines. - Trying to change a
constvalue. Remember:constmeans the binding is constant, not that the thing inside can’t change (if it’s an array or object, you can modify its contents). - Ignoring browser support. Most modern browsers support ES6, but if you’re supporting very old ones, you might need a tool (like Babel) to convert your ES6 code to older JavaScript.
Bonus Tip: You Don’t Have to Learn It All at Once!
The best thing about these JavaScript ES6 features is that you can learn them one at a time. Start with the features that look most useful to you. Maybe it’s template literals because you hate string concatenation. Maybe it’s arrow functions because they look cool.
Each one you learn will make your code a little bit better, a little bit cleaner, and a little bit more fun to write. That’s a win every single time.
Conclusion
So, what are these JavaScript ES6 features really about? They’re about joy.
They’re about turning long, confusing code into short, clear sentences. They’re about having tools that help you express your ideas faster. They make JavaScript more powerful and more pleasant to use.
You don’t need to master all 20 today. Just start. Try using a const instead of a var. Try writing one arrow function. Use a template literal to build a string.
Each small step adds up. Before you know it, you’ll be writing cleaner, more modern JavaScript without even thinking about it. You’ve got this! Now go play with some new code