Calculating the sum of an array of numbers
We can reduce an array of numbers into a single value that represents the sum of its values, without needing a traditional for-loop.
Read full articleIf the name of your variable is the exact same as the property you would extract from an object, you can use destructuring instead. That way, you don’t have to type the same word twice.
We can also rename the variable we’re destructuring into at the same time.
const person = {
name: "Bob",
age: 35,
email_address: "bob@example.com",
}
// without destructuring
const age = person.age
const emailAddress = person.email_address
// with destructuring
const {
age,
email_address: emailAddress,
} = person
const person = {
name: "Bob",
age: 35,
email_address: "bob@example.com",
}
// without destructuring
const age = person.age
const emailAddress = person.email_address
// with destructuring
const {
age,
email_address: emailAddress,
} = person
const person = {
name: "Bob",
age: 35,
email_address: "bob@example.com",
}
// without destructuring
const age = person.age
const emailAddress = person.email_address
// with destructuring
const {
age,
email_address: emailAddress,
} = person
const person = {
name: "Bob",
age: 35,
email_address: "bob@example.com",
}
// without destructuring
const age = person.age
const emailAddress = person.email_address
// with destructuring
const {
age,
email_address: emailAddress,
} = person
We can reduce an array of numbers into a single value that represents the sum of its values, without needing a traditional for-loop.
Read full articleWhen naming variables that hold Boolean values, using a prefix that indicates as much helps with readability.
Read full articleWe can build a dictionary of a string’s letters to count how many times each letter appears.
Read full articleWe can turn arrays of key-value-pairs into objects with a function that is available on Object.
Read full articleIf you keep seeing stars in JavaScript, it’s probably someone trying to raise a number to the power of another number.
Read full articleRegular JavaScript has no concept of required parameters. We can use default parameter values to emulate this feature.
Read full article