@ -313,13 +313,13 @@ const PI = 3.14 // Not allowed to reassign PI to a new value
### 2. Data types
If you do not feel comfortable with data types check the following [link](https://github.com/Asabeneh/30-Days-Of-JavaScript/blob/master/02_Day_Data_types/02_day_data_types.md)
If you do not feel comfortable with data types check the following [link](https://github.com/Asabeneh/30-Days-Of-JavaScript/blob/master/02_Day_Data_types/02_day_data_types.md).
### 3. Arrays
In contrast to variables, an array can store _multiple values_. Each value in an array has an _index_, and each index has _a reference in a memory address_. Each value can be accessed by using their _indexes_. The index of an array starts from _zero_, and the index of the last element is less by one from the length of the array.
An array is a collection of different data types which are ordered and changeable(modifiable). An array allows storing duplicate elements and different data types. An array can be empty, or it may have different data type values.
An array is a collection of different data types which are ordered and changeable(mutable). An array allows storing duplicate elements and different data types. An array can be empty, or it may have different data type values.
Most of the time the size of an array is big and we use a loop to iterate through each item of the arrays. Sometimes, we may have short arrays. If the array size is very short it is ok to access the items manually as shown above but today we will see a better way to access the array item which is destructuring.
Most of the time the size of an array is big and we use a loop to iterate through each item of the arrays. Sometimes, we may have short arrays. If the array size is very short it is ok to access the items manually as shown above but today we will see a better way to access the array items which is destructuring.
During destructuring each variable should match with the index of the desired item in the array. For instance, the variable fin matches to index 0 and the variable nor matches to index 2. What would be the value of den if you have a variable den next nor?
During destructuring each variable should match with the index of the desired item in the array. For instance, the variable `fin` matches to index 0 and the variable `nor` matches to index 2. What would be the value of `den` if you have a variable `den` next `nor`?
```js
const [fin, swe, nor, den] = countries
@ -3004,7 +3003,7 @@ const fullStack = [
]
for (const [first, second, third, fourth] of fullStack) {
console.log(first, second, third, fourt)
console.log(first, second, third, fourth)
}
```
@ -3044,12 +3043,10 @@ const rectangle = {
}
let width = rectangle.width
let height = recangle.height
let height = rectangle.height
// or
let width = rectangle[width]
let height = recangle[height]
let height = rectangle[height]
```
But today, we will see how to access the value of an object using destructuring.
@ -3082,7 +3079,7 @@ console.log(
) // 20, 10, undefined
```
The value of the perimeter in the above example is undefined.
The value of the perimeter in the above example is `undefined`.
Default value during object destructuring
@ -3186,7 +3183,7 @@ Destructuring function parameter
In this article, I will try to help you to have a very good understanding of the most common feature of JavaScript, _functional programming_.
In this article, I will try to help you to have a very good understanding of the most common feature of JavaScript, _Functional programming_.
_Functional programming_ allows you to write shorter code, clean code, and also to solve complicated problems which might be difficult to solve in a traditional way.
@ -3391,7 +3387,6 @@ We use forEach when we like to iterate through an array of items. The forEach is
```js
// syntax in a normal or a function declaration
function callback(item, index, arr) {}
array.forEach(callback)
@ -3453,7 +3448,6 @@ We use the map method whenever we like to modify an array. We use the map method
```js
// syntax in a normal or a function declaration
function callback(item, i) {
return // code goes here
}
@ -3461,7 +3455,6 @@ function callback(item, i) {
const modifiedArray = array.map(callback)
// or syntax in an arrow function
const callback = (item, i) => {
return // code goes here
}
@ -3472,20 +3465,16 @@ Now, let us modify the countries array using the map method. The index is an opt
```js
// Using function declaration
const countries = ['Finland', 'Estonia', 'Sweden', 'Norway']
const allAreEvens = numbers.every((n) => n % 2 === 0)
const allAreOdds= numbers.every((n) => n % 2 !== 0)
const allAreOdds= numbers.every((n) => n % 2 !== 0)
console.log(allAreEven) // false
console.log(allAreOdd) // false
console.log(allAreEvens) // false
console.log(allAreOdds) // false
const evens = [0, 2, 4, 6, 8, 10]
const someAreEvens = evens.some((n) => n % 2 === 0)
const someAreOdds = evens.some((n) => n % 2 !== 0)
const allAreEvens = evens.every((n) => n % 2 === 0)
const allAreOdds = evens.every((n) => n % 2 !== 0)
console.log(someAreEvens) // true
console.log(someAreOdds) // false
console.log(allAreEvens) // true
console.log(allAreOdds) // false
```
#### Exercises
@ -4512,7 +4490,7 @@ So do not directly manipulate the DOM if you are using react. The only place we
</html>
```
Check out there result on [codepen](https://codepen.io/Asabeneh/full/vYGqQxP)
Check out there result on [codepen](https://codepen.io/Asabeneh/full/vYGqQxP).
🌕 You are amazing! You have just completed day 1 challenge and you are on your way to greatness. Now you are a JavaScript Ninja and ready to dive into React.