Counting months from zero
When is June the fifth month of the year? When JavaScript is involved, of course. In JavaScript, January is the zero-th month.
Read full articleSetting the length of an array in JavaScript removes all values beyond that length. Setting the length to zero removes all values from it.
// this array holds six values
const numbers = [4, 8, 15, 16, 23, 42]
// by setting the length to 4, any value past the fourth element is removed
numbers.length = 4
console.log(numbers) // ⇒ [4, 8, 15, 16]
// setting the length to 0 leads to the entire array being emptied
numbers.length = 0
console.log(numbers) // ⇒ []
// this array holds six values
const numbers = [4, 8, 15, 16, 23, 42]
// by setting the length to 4, any value past the fourth element is removed
numbers.length = 4
console.log(numbers) // ⇒ [4, 8, 15, 16]
// setting the length to 0 leads to the entire array being emptied
numbers.length = 0
console.log(numbers) // ⇒ []
// this array holds six values
const numbers = [4, 8, 15, 16, 23, 42]
// by setting the length to 4, any value past the fourth element is removed
numbers.length = 4
console.log(numbers) // ⇒ [4, 8, 15, 16]
// setting the length to 0 leads to the entire array being emptied
numbers.length = 0
console.log(numbers) // ⇒ []
// this array holds six values
const numbers = [4, 8, 15, 16, 23, 42]
// by setting the length to 4, any value past the fourth element is removed
numbers.length = 4
console.log(numbers) // ⇒ [4, 8, 15, 16]
// setting the length to 0 leads to the entire array being emptied
numbers.length = 0
console.log(numbers) // ⇒ []
When is June the fifth month of the year? When JavaScript is involved, of course. In JavaScript, January is the zero-th month.
Read full articleBy destructuring the return value of a function, we can take out only the values we need without having to assign the result to an object first.
Read full articleThere are several ways to concatenate in JavaScript. We can pick the one that is most readable in each situation.
Read full articleWant to create annoying memes but are too lazy to hit the shift key every other letter? Don’t worry, I got you.
Read full articleAccessing deeply nested values required us to check for undefined along the way. With optional chaining, we no longer need to do that.
Read full articleWe no longer need to install dependencies to pad a string with characters to the left or right of it.
Read full article