1. Modules πŸ“¦

What are Modules?

In JavaScript, modules allow you to split your code into smaller chunks. You can export pieces of your code (like functions, variables) from one file and import them in other files. This makes your code cleaner and easier to maintain. πŸš€

Example:

module.js:

export const greeting = "Hello, World!";
export function greet(name) {
  return `Hello, ${name}! 🌍`;
}

main.js:

import { greeting, greet } from './module.js';
console.log(greeting); // "Hello, World!"
console.log(greet('Alice')); // "Hello, Alice! 🌍"


2. Optional Chaining (?.) πŸ€”

What is Optional Chaining?

Optional chaining is like knocking on a door to check if someone is home. If the door doesn’t exist, you don’t crash into it, you simply move on. 😎

With ?., if a property doesn’t exist, it won’t throw an error; it’ll return undefined instead.

Example:

const user = { name: "Alice", address: { city: "Wonderland" } };

console.log(user.address?.city); // "Wonderland" πŸ™οΈ
console.log(user.profile?.bio); // undefined ❌