7 JavaScript Quick Coding Tips ✨

random_ti

Random

Posted on November 28, 2023

7 JavaScript Quick Coding Tips ✨

Hey Developer,

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

Today post i will tell you some "Javascript Quick TipsπŸ’Ž" that every javascript developers should know.

Follow me in Githubβœ…

Let start


1. Combine Objects πŸ‘¨β€πŸ‘¨β€πŸ‘¦β€πŸ‘¦

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

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

// Result: { id: '@Taquiimam14', url: 'www.twitter.com' }
Enter fullscreen mode Exit fullscreen mode

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]
Enter fullscreen mode Exit fullscreen mode

3. Short-circuit conditional πŸ› 

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

// New 

isSubscribed && sendThankyouEmail() ;
Enter fullscreen mode Exit fullscreen mode

4. Dynamic Property Names ✨

const dynamic = 'websites' ;

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

// Result: { userId: "@Taquiimam14", website: "www.twitter.com" }
Enter fullscreen mode Exit fullscreen mode

5. Flattern an array πŸ‘“

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

// Result: [1, 2, 2, 3, 4, 8]
Enter fullscreen mode Exit fullscreen mode

6. Return shorthand βœ”

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

// New
function myFunc() {
return foo(), bar(), 1;
}
Enter fullscreen mode Exit fullscreen mode

7. Resize An Array βš™

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

// Result: [1, 2]
Enter fullscreen mode Exit fullscreen mode

πŸ’­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 πŸ‘‹

πŸ’– πŸ’ͺ πŸ™… 🚩
random_ti
Random

Posted on November 28, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related