Skip to content

Commit 2a4eedb

Browse files
committed
day 8 : scopes and object - reviewed
1 parent 382a2ae commit 2a4eedb

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

08_Day/08_day_objects.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
![Thirty Days Of JavaScript](../images/banners/day_1_8.png)
1919

20-
- [📔 Day 8](#%f0%9f%93%94-day-8)
20+
- [📔 Day 8](#-day-8)
2121
- [Scope](#scope)
2222
- [Window Scope](#window-scope)
2323
- [Global scope](#global-scope)
2424
- [Local scope](#local-scope)
25-
- [📔 Object](#%f0%9f%93%94-object)
25+
- [📔 Object](#-object)
2626
- [Creating an empty object](#creating-an-empty-object)
2727
- [Creating an objecting with values](#creating-an-objecting-with-values)
2828
- [Getting values from an object](#getting-values-from-an-object)
@@ -33,9 +33,10 @@
3333
- [Getting object values using Object.values()](#getting-object-values-using-objectvalues)
3434
- [Getting object keys and values using Object.entries()](#getting-object-keys-and-values-using-objectentries)
3535
- [Checking properties using hasOwnProperty()](#checking-properties-using-hasownproperty)
36-
- [💻 Exercises](#%f0%9f%92%bb-exercises)
36+
- [💻 Exercises](#-exercises)
3737
- [Exercises: Level 1](#exercises-level-1)
3838
- [Exercises: Level 2](#exercises-level-2)
39+
- [Exercises: Level 3](#exercises-level-3)
3940

4041
# 📔 Day 8
4142

@@ -72,7 +73,7 @@ console.log(a, b) // accessible
7273

7374
### Global scope
7475

75-
A globally declared variable can be access every where in the same file. But the term global is relative. It can be global to the file or it can be global relative to some block of codes.
76+
A globally declared variable can be accessed every where in the same file. But the term global is relative. It can be global to the file or it can be global relative to some block of codes.
7677

7778
```js
7879
//scope.js
@@ -93,7 +94,7 @@ console.log(a, b) // JavaScript 10, accessible
9394

9495
### Local scope
9596

96-
A local declared variable can be access only certain block code.
97+
A variable declared as local can be accessed only in certain block code.
9798

9899
```js
99100
//scope.js
@@ -117,7 +118,7 @@ letsLearnScope()
117118
console.log(a, b) // JavaScript 10, accessible
118119
```
119120

120-
Now, you have an understanding of scope. A variable declared with *var* only scoped to function but variable declared with *let* or *const* is block scope(function block, if block, loop etc)
121+
Now, you have an understanding of scope. A variable declared with *var* only scoped to function but variable declared with *let* or *const* is block scope(function block, if block, loop etc). Block in JavaScript is a code in between two curly brackets ({}).
121122

122123
```js
123124
//scope.js
@@ -141,7 +142,7 @@ console.log(i)
141142

142143
```
143144

144-
In ES6 and above there is *let* and *const*, so you will suffer from the sneakiness of *var*. When we use *let* our variable is block scope and it will not infect other parts of our code.
145+
In ES6 and above there is *let* and *const*, so you will not suffer from the sneakiness of *var*. When we use *let* our variable is block scoped and it will not infect other parts of our code.
145146

146147
```js
147148
//scope.js
@@ -166,12 +167,12 @@ for(let i = 0; i < 3; i++){
166167

167168
```
168169

169-
The scope *let* and *const* is the same. The difference is only reassigning. We can not change or reassign the value of const variable. I would strongly suggest you to use *let* and *const*, by using *let* and *const* you will writ clean code and avoid hard to debug mistakes. As a rule of thumb, you can use *let* for any value which change, *const* for any constant value, array, object, arrow function and function expression.
170+
The scope *let* and *const* is the same. The difference is only reassigning. We can not change or reassign the value of const variable. I would strongly suggest you to use *let* and *const*, by using *let* and *const* you will writ clean code and avoid hard to debug mistakes. As a rule of thumb, you can use *let* for any value which change, *const* for any constant value, and for array, object, arrow function and function expression.
170171

171172
## 📔 Object
172173

173-
Everything can be an object and objects do have properties and properties have values, so an object is key value pair. The order of the key is not reserved, or there is no order.
174-
Creating an object literal. To create an object literal, we use two curly brackets.
174+
Everything can be an object and objects do have properties and properties have values, so an object is a key value pair. The order of the key is not reserved, or there is no order.
175+
To create an object literal, we use two curly brackets.
175176

176177
### Creating an empty object
177178

@@ -185,7 +186,7 @@ const person = {}
185186

186187
Now, the person object has firstName, lastName, age, location, skills and isMarried properties. The value of properties or keys could be a string, number, boolean, an object, null, undefined or a function.
187188

188-
Let us see some examples of object. Each key has a value in object.
189+
Let us see some examples of object. Each key has a value in the object.
189190

190191
```js
191192
const rectangle = {
@@ -573,11 +574,12 @@ console.log(copyPerson.hasOwnProperty('score'))
573574
```
574575

575576
Imagine you are getting the above users collection from a MongoDB database.
576-
a. Create a function called signUp which allows user to add to the collection. If user exists, inform the user that he has already an account.
577-
b. Create a function called signIn which allows user to sign in to the application
577+
a. Create a function called signUp which allows user to add to the collection. If user exists, inform the user that he has already an account.
578+
b. Create a function called signIn which allows user to sign in to the application
579+
578580
3. The products array has three elements and each of them has six properties.
579581
a. Create a function called rateProduct which rates the product
580-
b. Create a function called averageRating which calculate the average rating of a product
582+
b. Create a function called averageRating which calculate the average rating of a product
581583

582584
4. Create a function called likeProduct. This function will helps to like to the product if it is not liked and remove like if it was liked.
583585

0 commit comments

Comments
 (0)