Understanding JavaScript Arrow Functions in Depth
Understanding JavaScript Arrow Functions in Depth
markdown
CopyEdit
# Understanding JavaScript Arrow Functions in Depth
// Arrow function
const add = (a, b) => a + b;
2. Implicit Return
If the function has only one expression, you can omit the return keyword and curly
braces:
javascript
CopyEdit
const multiply = (a, b) => a * b;
3. Returning Objects
Wrap object literals in parentheses to return them:
javascript
CopyEdit
const getUser = () => ({ name: 'Waleed', age: 21 });
4. No this Binding
Arrow functions do not bind their own this. They inherit it from the enclosing
context.
javascript
CopyEdit
function Timer() {
this.seconds = 0;
setInterval(() => {
this.seconds++;
console.log(this.seconds);
}, 1000);
}new Timer();
5. Limitations
No arguments object
Arrow functions make your code cleaner and less error-prone when dealing with
this. Learn when to use them for better productivity!
yaml
CopyEdit
---### 📝 **2. Title:** “Destructuring in ES6 — Arrays & Objects
Explained”
**Description:** Clear and practical examples of array and object
destructuring in ES6 JavaScript.
**Tags:** JavaScript, ES6, Destructuring, Web Dev, Learn JS
**Content:**```markdown# Destructuring in ES6 — Arrays &
Objects Explained
Destructuring helps unpack values from arrays or objects into
variables.
## 1. Array Destructuring
```javascriptconst numbers = [10, 20, 30];const [a, b, c] =
numbers;console.log(a, b, c); // 10 20 30