r/javascript • • Jul 25 '21

Useful Javascript Tricks and Tips

https://kush01.hashnode.dev/useful-javascript-tricks-and-tips

[removed] — view removed post

0 Upvotes

5 comments sorted by

•

u/Ustice Jul 25 '21

While your question may be relevant to you, it's not particularly relevant to the rest of the subreddit and honestly belongs much better in /r/LearnJavascript.

8

u/redsandsfort Jul 25 '21

better title: "How to get your PR declined"

1

u/cutebabli9 Jul 25 '21

What's wrong with this trick?

  //longhand  
  if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') {  
     //logic  
  }  
  //shorthand  
  if (\['abc', 'def', 'ghi', 'jkl'\].includes(x)) {  
     //logic  
  }

1

u/backtickbot Jul 25 '21

Fixed formatting.

Hello, cutebabli9: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

1

u/960321203112293 Jul 25 '21 edited Jul 25 '21

myArray.length = 0; // myArray will be equal to [].

Ah yes, because simply setting the length to 0 is much more cost effective and readable vs myArray = [];

/s