#tinyJStip Got some buttons and only one can be pressed? Here's a simple way to swap their values!

Same applies to swapping which tab is selected and other similar situations.

(doesn't seem to work for tabIndex through 😡)

#HTML #a11y #JS #JavaScript #code #web #coding #frontend #dev #webDev #webDevelopment

#tinyJStip Remember to always pad with '0' when converting rgb channels to hex 😼

#js #javascript #code #coding #frontend #webDev #webDevelopment

#tinyJStip Cycling stuff around in an array! Useful when generating polyhedron vertices starting from a vector for example.

Move last array item to the start:
`pop()` + `unshift()`

Move first array item to the end:
`shift()` + `push()`

#js #javascript #tinyCodingTip #code #coding #frontend #webDev #webDevelopment

#tinyJStip You can use the padStart() function to generate things like file names with leading zeros within a loop.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart

#js #javscript #coding #frontend #webDev #webDevelopment

String.prototype.padStart() - JavaScript | MDN

The padStart() method of String values pads this string with a given string (repeated and/or truncated, if needed) so that the resulting string has a given length. The padding is applied from the start of this string.

MDN Web Docs

#tinyJStip
Did you know that you can get the relative position of every letter of your #canvas text with:

context.measureText('hello there!').advances

#js #JavaScript #coding #frontend #webDev #webDevelopment #array

#tinyJStip

❌ DON'T
d[i] + ',' + d[i + 1] + ',' + d[i + 2] + ',' + d[i + 3]

βœ… DO
d.slice(i, i + 4).join()

Because I actually saw the first in a 2023-dated tutorial. Okay, people don't know CSS, don't know HTML, JS is important, right? But turns out people don't know JS either... Array functions are a thing, you know...

#js #JavaScript #coding #frontend #webDev #webDevelopment #array

#tinyJStip
Math.hypot() is a thing! So...

❌ DON'T
Math.sqrt(dx*dx + dy*dy)

βœ… DO
Math.hypot(dx, dy)

(part of the "Ana is checking 2023 dated tutorials and screaming at the code that seems to come from 10+ years ago" series)

#js #JavaScript #coding #frontend #webDev #webDevelopment #trigonometry