Marko Denic Profile picture
Software engineer.

Oct 29, 2021, 14 tweets

JavaScript tips you won't see in most tutorials.

🧵

1. Copy to clipboard

You can use the `Clipboard` API to create the “Copy to clipboard” functionality:

2. "Go back" button

Use the `history.back()` to create a “Go Back” button.

3. `console.table()`

You can use the `console.table()` method to display tabular data as a table:

4. You can wrap your console.log() arguments with curly brackets to see the variable names.

5. Capture right clicks (user attempts to open a context menu).

6. Get min/max value from an array

You can use `Math.min()` or `Math.max()` combined with the spread operator to find the minimum or maximum value in an array.

7. Run event listener only once

If you want to add an event listener but have it run only once, you can use the ` once` option:

8. Numbers separators

To improve readability for numbers, you can use underscores as separators:

9. Use the `window.print()` to create a "print page" functionality.

10. Use the `Fullscreen API` to open any element in full-screen mode.

11. Use the `dataset` property to access the element's custom data attributes (data-*):

12. You can use `Set` to remove duplicate elements from an array:

If you're learning HTML, CSS or JavaScript be sure to follow me and never miss tips like this.

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling