Skip to main content

Command Palette

Search for a command to run...

7 JavaScript Quick Code Tips ✨ Part - 1

Published
2 min read
7 JavaScript Quick Code Tips ✨ Part - 1
M

🎮Gaming is my ex and coding is my wife👩 |🌐 Full Stack Web Developer & Programmer 🚀 | Tech Enthusiast 👋 | Blog 📚 writter | Prompt enginner 💡 | Follow Now!

Hey Developer,

Welcome to my Javascript blog, My name is Md Taqui Imam i am a Full Stack developer And in,

Today's post i will tell you some "Javascript Quick Tips💎" that every javascript developers should know.

Follow me in Github✅

1. Combine Objects 👨‍👨‍👦‍👦

const username = { id: '@Taquiimam14' };
const website = { url: 'www.twitter.com' };

const social = { ...username, ...url };

// Result: { id: '@Taquiimam14', url: 'www.twitter.com' }

2. Shuffle an array 🥓

function shuffleArr(array) {
return array.sort( () => Math.random( ) - 0.5) ;
}

let myArr = [1, 2, 3, 4, 5];

shuffleArr(myArr);

// Result: [3, 1, 5, 4, 2]

3. Short-circuit conditional 🛠

// Old  
 if ( isSubscribed ) {
      sendThankyouEmail();
}

// New 

isSubscribed && sendThankyouEmail() ;

4. Dynamic Property Names ✨

const dynamic = 'websites' ;

var social = {
      userId: '@Taquiimam14',
      [dynamic]: 'www.twitter.com'
};

// Result: { userId: "@Taquiimam14", website: "www.twitter.com" }

5. Flattern an array 👓

const oldArr = [1, 2, [2, 3, 4], 8];
const newArr = oldArr.flat();

// Result: [1, 2, 2, 3, 4, 8]

6. Return shorthand ✔

// Old
fumction myfunc() {
    foo();
    bar();
    return 1;
}

// New
function myFunc() {
return foo(), bar(), 1;
}

7. Resize An Array ⚙

var array = [1, 2, 3, 4, 5];
array.length = 2 ;

// Result: [1, 2]

💭Conclusion

Thankyou for reading this blog post i hope you find it helpful. Even beginning programmers can understand these concepts to get the most out of JavaScript. Keep practicing and have fun with code!

And don't forget to Drop "🔥💖🦄"

Happy coding 👋

More from this blog

M

Md Taqui Imam Blogs

60 posts

💡 Mastering Web Dev & Software Craftsmanship | Turning Ideas into Interactive Reality | Web Architect | Code Poet ✏ | Open for Work 💼