DEV Community

CodeWithDhanian
CodeWithDhanian

Posted on

40 JavaScript Shortcuts Every Developer Should Know in 2025

Created by Dhanian (@e_opore on X)

JavaScript is evolving rapidly, and mastering the right shortcuts can make you a faster, smarter, and more efficient developer. Whether you're building full-stack apps or working on frontend UI systems, these time-saving tricks will help you write cleaner code and improve productivity.

Here are 40 JavaScript shortcuts you should absolutely know in 2025 — organized into four categories for quick learning:


1–10: Syntax Shortcuts and Essentials

// 1. Ternary Operator
const isAdult = age >= 18 ? "Yes" : "No";

// 2. Default Parameters
function greet(name = "Guest") {
  return `Hello, ${name}`;
}

// 3. Arrow Functions
const add = (a, b) => a + b;

// 4. Destructuring Objects
const { name, age } = person;

// 5. Destructuring Arrays
const [first, second] = colors;

// 6. Template Literals
const message = `Hi, ${user.name}!`;

// 7. Spread Operator
const newArray = [...oldArray, 4];

// 8. Rest Parameters
function sum(...numbers) {
  return numbers.reduce((a, b) => a + b);
}

// 9. Optional Chaining
const street = user?.address?.street;

// 10. Nullish Coalescing
const username = inputName ?? "Anonymous";
Enter fullscreen mode Exit fullscreen mode

11–20: Logic, Loops, and Arrays

// 11. Short-circuit Evaluation
const status = isLoggedIn && "Welcome!";

// 12. Logical OR Assignment
user.name ||= "Guest";

// 13. Logical AND Assignment
settings.debug &&= false;

// 14. Object Property Shorthand
const age = 30;
const person = { name, age };

// 15. Computed Property Names
const key = "level";
const player = { [key]: 42 };

// 16. For-of Loop
for (const item of items) {
  console.log(item);
}

// 17. forEach Loop
items.forEach(item => console.log(item));

// 18. Map Function
const squared = nums.map(n => n * n);

// 19. Filter Function
const evens = nums.filter(n => n % 2 === 0);

// 20. Reduce Function
const total = nums.reduce((a, b) => a + b, 0);
Enter fullscreen mode Exit fullscreen mode

21–30: Object & Array Utilities

// 21. Includes Check
const found = list.includes("apple");

// 22. Set for Unique Values
const unique = [...new Set(array)];

// 23. Object.entries
Object.entries(obj).forEach(([key, value]) => {
  console.log(key, value);
});

// 24. Object.values
const vals = Object.values(obj);

// 25. Object.keys
const keys = Object.keys(obj);

// 26. Chaining Array Methods
const result = data.filter(a => a.active).map(a => a.name);

// 27. Flatten Array
const flat = arr.flat();

// 28. Trim String
const cleaned = str.trim();

// 29. Pad String
const padded = "5".padStart(2, "0");

// 30. Intl.NumberFormat
const price = new Intl.NumberFormat().format(1234567);
Enter fullscreen mode Exit fullscreen mode

31–40: Modern Tricks & Utilities

// 31. Dynamic Import
const module = await import('./module.js');

// 32. Promise.all
await Promise.all([fetchData(), loadUI()]);

// 33. Async/Await
const fetchData = async () => {
  const res = await fetch(url);
  return res.json();
};

// 34. Optional Parameters in Functions
function log(message, level = "info") {
  console[level](message);
}

// 35. Number Conversion with Unary +
const num = +"42";

// 36. Boolean Conversion with !!
const isTrue = !!value;

// 37. Short Array Swap
[a, b] = [b, a];

// 38. Quick String to Array
const chars = [..."hello"];

// 39. Quick Object Clone
const copy = { ...original };

// 40. Debounce Function (Utility)
const debounce = (fn, delay) => {
  let timeout;
  return (...args) => {
    clearTimeout(timeout);
    timeout = setTimeout(() => fn(...args), delay);
  };
};
Enter fullscreen mode Exit fullscreen mode

Supercharge Your JavaScript Skills

If you found these shortcuts useful, you’ll love my complete JavaScript guidebook. It’s packed with in-depth explanations, real-world projects, and smart coding patterns to take you from beginner to advanced.

Get your copy today and join hundreds of devs leveling up their JavaScript skills!

Buy now:

https://codewithdhanian.gumroad.com/l/jjpifd

Let’s build smarter in 2025.

— Dhanian (@e_opore on X)

Top comments (16)

Collapse
 
yaireo profile image
Yair Even Or •
  1. missing output result for the examples
  2. missing any sort of explanation for some things which aren't self-explained
  3. number 39 "Object Clone" should mention this is a shallow cloning only
Collapse
 
hamza7681 profile image
Hamza Siddique •

function greet(name = "Guest") {
return
Hello, ${name};
}

It is good practice to pass parameters in object rather than this old way, this will save the sequence issue and undefined issue

function greet({name = "Guest"}) {
return
Hello, ${name};
}

Collapse
 
nibelune profile image
Benoît Schiex •

No...It's not always a good practice. And here, it's a bad one.

It's usefull when you have a function with 3+ parameters, cause it improve usability/readability
it's a bad practice on simple functions especially when you use Javascript :

  • poor autocompletion
  • poor readability
  • risk of silent undefined issues (when JS evaluate an objet property that doesn't exist, it won't throw an error but just returns undefined)
Collapse
 
code_2 profile image
CodeWithDhanian •

Thanks for checking out

Collapse
 
biru_basfore profile image
Biru Basfore •

Thanks for sharing this valuable information 🥰

Collapse
 
code_2 profile image
CodeWithDhanian •

Thanks for checking out

Collapse
 
biru_basfore profile image
Biru Basfore •

You're welcome.

Collapse
 
minionarmytothemoon profile image
Minion Army •

How are people still putting these moronic articles out for things that have been here for almost a decade now.

Collapse
 
code_2 profile image
CodeWithDhanian •

To make JavaScript easier

Collapse
 
eudeferraz profile image
eudeferraz •

Learned new things from your post, thank you for sharing with us!!

Collapse
 
palsang_ghising_15dbe1d8e profile image
Palsang Ghising •

As a beginner so much useful information, just in one page. Thanks bro.

Collapse
 
code_2 profile image
CodeWithDhanian •

Thanks for checking out

Collapse
 
collinzo2022 profile image
Efuetanu Collins •

Nice one, l had to go through to check if l was a really js developer😁

Collapse
 
clint_hiles_2ca3cc9412167 profile image
Clint Hiles •

StucturedClone is good to

Collapse
 
theme_selection profile image
ThemeSelection •

Great collection..!!
Thanks for sharing.

Collapse
 
raldjie profile image
Jeirald Lepaopao •

Thank you for sharing