fixed typos, improved readability, included location of coutries_data

pull/759/head
sapiensFactor 2 years ago
parent e302906562
commit b976bb4415

@ -42,7 +42,7 @@
## Scope
Variable is the fundamental part in programming. We declare variable to store different data types. To declare a variable we use the key word _var_, _let_ and _const_. A variable can be declared at different scope. In this section, we will see the scope variables, scope of variables when we use var or let.
Variable is the fundamental part in programming. We declare variable to store different data types. To declare a variable we use the keywords _var_, _let_ and _const_. A variable can be declared at different scope. In this section, we will see the scope of variables. Scope of variables when we use var or let.
Variables scopes can be:
- Global
@ -72,7 +72,7 @@ console.log(a, b) // accessible
### Global scope
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.
A globally declared variable can be accessed everywhere 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.
```js
//scope.js
@ -131,9 +131,8 @@ Now, you have an understanding of scope. A variable declared with *var* only sco
function letsLearnScope() {
var gravity = 9.81
console.log(gravity)
}
// console.log(gravity), Uncaught ReferenceError: gravity is not defined
console.log(gravity) // Uncaught ReferenceError: gravity is not defined
if (true){
var gravity = 9.81
@ -158,22 +157,22 @@ function letsLearnScope() {
console.log(gravity)
}
// console.log(gravity), Uncaught ReferenceError: gravity is not defined
console.log(gravity) // Uncaught ReferenceError: gravity is not defined
if (true){
const gravity = 9.81
console.log(gravity) // 9.81
}
// console.log(gravity), Uncaught ReferenceError: gravity is not defined
console.log(gravity) // Uncaught ReferenceError: gravity is not defined
for(let i = 0; i < 3; i++){
console.log(i) // 0, 1, 2
}
// console.log(i), Uncaught ReferenceError: i is not defined
console.log(i) // Uncaught ReferenceError: i is not defined
```
The scope *let* and *const* are the same. The difference is only reassigning. We can not change or reassign the value of the `const` variable. I would strongly suggest you to use *let* and *const*, by using *let* and *const* you will write 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 an array, object, arrow function and function expression.
The scope of *let* and *const* are the same. The difference is only reassigning. We can not change or reassign the value of the `const` variable. I would strongly suggest you to use *let* and *const*, by using *let* and *const* you will write 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 an array, object, arrow function and function expression.
## 📔 Object
@ -437,7 +436,7 @@ console.log(copyPerson.hasOwnProperty('score'))
### Exercises: Level 2
1. Find the person who has many skills in the users object.
1. Find the person who has the most skills in the users object.
1. Count logged in users, count users having greater than equal to 50 points from the following object.
````js
@ -491,20 +490,22 @@ console.log(copyPerson.hasOwnProperty('score'))
isLoggedIn: false,
points: 40
}
}```
}
````
1. Find people who are MERN stack developer from the users object
1. Set your name in the users object without modifying the original users object
1. Get all keys or properties of users object
1. Get all the values of users object
1. Use the countries object to print a country name, capital, populations and languages.
1. Use the [countries object](../08_Day_Objects/08_day_starter/data/countries_data.js) to print a country name, capital, populations and languages.
### Exercises: Level 3
1. Create an object literal called _personAccount_. It has _firstName, lastName, incomes, expenses_ properties and it has _totalIncome, totalExpense, accountInfo,addIncome, addExpense_ and _accountBalance_ methods. Incomes is a set of incomes and its description and expenses is a set of incomes and its description.
2. **** Questions:2, 3 and 4 are based on the following two arrays:users and products ()
```js
** Questions:2, 3 and 4 are based on the following two arrays: `users` and `products`
```js
const users = [
{
_id: 'ab12ex',
@ -579,7 +580,7 @@ console.log(copyPerson.hasOwnProperty('score'))
]
```
Imagine you are getting the above users collection from a MongoDB database.
2. Imagine you are getting the above users collection from a MongoDB database.
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.
b. Create a function called signIn which allows user to sign in to the application

Loading…
Cancel
Save