DEV Community

CodeWithDhanian
CodeWithDhanian

Posted on

9

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)

Tiugo image

Fast, Lean, and Fully Extensible

CKEditor 5 is built for developers who value flexibility and speed. Pick the features that matter, drop the ones that don’t and enjoy a high-performance WYSIWYG that fits into your workflow

Start now

Top comments (1)

Collapse
 
collinzo2022 profile image
Efuetanu Collins

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

Neon image

Next.js applications: Set up a Neon project in seconds

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Please show some love ❤️ or share a kind word in the comments if you found this useful!

Got it!