Ehsanullah Haidary (@successbyte) 's Twitter Profile
Ehsanullah Haidary

@successbyte

Frontend Developer | React | Vue | Tailwind | JavaScript

ID: 1574054826278805504

linkhttps://ehsanullah.vercel.app/ calendar_today25-09-2022 15:17:09

2,2K Tweet

123 Followers

214 Following

Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

🚨 Stop using for…in for arrays! ❌ for…in loops over all properties (including custom ones). ✅ for…of loops over values only—it’s the right choice! Example: for (let fruit of arr) console.log(fruit); // ✅ Works correctly Use for…in for objects, not arrays! #WebDev

🚨 Stop using for…in for arrays!

❌ for…in loops over all properties (including custom ones).
✅ for…of loops over values only—it’s the right choice!

Example:

for (let fruit of arr) console.log(fruit); // ✅ Works correctly

Use for…in for objects, not arrays! 
#WebDev
Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

📌 Objects vs. Arrays in JavaScript ✔ Use objects when you need key-value pairs (user.name). ✔ Use arrays when you need an ordered list (["Apple", "Banana"]). Arrays are faster for handling large collections! #CodingTips

📌 Objects vs. Arrays in JavaScript

✔ Use objects when you need key-value pairs (user.name).
✔ Use arrays when you need an ordered list (["Apple", "Banana"]).

Arrays are faster for handling large collections! #CodingTips
Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

💡 Symbols make object properties "invisible"! let id = Symbol("id"); let user = { name: "John", [id]: 123 }; console.log(Object.keys(user)); // ["name"] console.log(user[id]); // 123 ✅ ✔ Hidden in loops ✔ Prevents property conflicts ✔ Safe for third-party code #Javascript

💡 Symbols make object properties "invisible"!

let id = Symbol("id");
let user = { name: "John", [id]: 123 };

console.log(Object.keys(user)); // ["name"]
console.log(user[id]); // 123 ✅

✔ Hidden in loops
✔ Prevents property conflicts
✔ Safe for third-party code
#Javascript
Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

Why Use Optional Chaining (?.)? 🚀 Stop your JavaScript from crashing! ❌ Without ?. console.log(user.address.street); // TypeError 😱 ✅ With optional chaining console.log(user?.address?.street); // ✅ undefined (no crash!) Use ?. to safely access nested properties! #WebDev

Why Use Optional Chaining (?.)?

🚀 Stop your JavaScript from crashing!

❌ Without ?.
console.log(user.address.street); // TypeError 😱

✅ With optional chaining
console.log(user?.address?.street); // ✅ undefined (no crash!)

Use ?. to safely access nested properties! #WebDev
Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

⚡ Accessing the DOM safely with ?. ❌ Without ?. (throws an error if .elem doesn’t exist): let html = document.querySelector('.elem').innerHTML; ✅ With ?. (safe!): let html = document.querySelector('.elem')?.innerHTML; Optional chaining for safer DOM access! #JavaScript

⚡ Accessing the DOM safely with ?.

❌ Without ?. (throws an error if .elem doesn’t exist):

let html = document.querySelector('.elem').innerHTML;

✅ With ?. (safe!):

let html = document.querySelector('.elem')?.innerHTML;

Optional chaining for safer DOM access! #JavaScript
Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

🔥 Why write this? let street = user && user.address && user.address.street; 💡 When you can write this? let street = user?.address?.street; ✔ Less code ✔ More readable ✔ No crashes JavaScript keeps getting better! #WebDevelopment

🔥 Why write this?

let street = user && user.address && user.address.street;

💡 When you can write this?

let street = user?.address?.street;

✔ Less code
✔ More readable
✔ No crashes

JavaScript keeps getting better! #WebDevelopment
Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

🚨 Don’t use ?. everywhere! ❌ Bad: let name = user?.name?.firstName?.toUpperCase(); If user should always exist, this hides errors! ✅ Good let name = user.name/?.firstName?.t…(); ✅ Use it only when a value might be missing! #JavaScriptTips

🚨 Don’t use ?. everywhere!

❌ Bad:

let name = user?.name?.firstName?.toUpperCase();

If user should always exist, this hides errors!

✅ Good 

let name = user.name/?.firstName?.t…();

✅ Use it only when a value might be missing! #JavaScriptTips
Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

💡 Ever tried calling a function… that doesn’t exist? ❌ Without ?.(): user.sayHi(); // ❌ TypeError: user.sayHi is not a function ✅ With ?.(): user.sayHi?.(); // ✅ No error, nothing happens ?.() is a lifesaver for dynamic objects! #WebDev

💡 Ever tried calling a function… that doesn’t exist?

❌ Without ?.():

user.sayHi(); // ❌ TypeError: user.sayHi is not a function

✅ With ?.():

user.sayHi?.(); // ✅ No error, nothing happens

?.() is a lifesaver for dynamic objects! 
#WebDev
Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

We lost a $3K deal because the CEO pushed untested code to main. 😬🤦‍♂️ Lesson learned: Always test before merging!

Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

JavaScript was made to make web pages alive. Now, it's running on servers, mobile apps, and even robots. Not bad for a language created in 10 days! 🚀"

Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

JavaScript can do a lot in the browser: But it can’t: ❌ Read/write files without permission ❌ Access other browser tabs ❌ Control your system Security is built-in. That’s why JavaScript is both powerful and safe. 💡

Ehsanullah Haidary (@successbyte) 's Twitter Profile Photo

In 2018 & 2019 two Boeing 737 Max crushes resulted in 346 deaths. The cause? A software system called MCAS and lacking of training pilots about the system It blows my mind