|
5 | 5 | # Table of Contents
|
6 | 6 |
|
7 | 7 | 1. [Introduction](#introduction)
|
8 |
| -2. [Setup](#setup) |
9 |
| -3. [Variables](#variables) |
10 |
| -4. [Data Types](#data-types) |
11 |
| -5. [Operators](#operators) |
12 |
| -6. [Conditionals](#conditionals) |
13 |
| -7. [Arrays](#arrays) |
14 |
| -8. [Loops](#loops) |
15 |
| -9. [Functions](#functions) |
16 |
| -10. [Scope](#scope) |
17 |
| -11. [Hoisting](#Hoisting) |
18 |
| -12. [Object](#object) |
19 |
| -13. [Document Object Model](#document-object-model) |
20 |
| -14. [Class](#class) |
21 |
| -15. [Call Back and Higher Order Functions](#call-back-and-higher-order-functions) |
22 |
| -16. [Functional Programming](#functional-programming) |
23 |
| -17. [Destructuring](#destructuring) |
24 |
| -18. [Rest and Spread](#rest-and-spread) |
25 |
| -19. [Regular Expressions](#regular-expressions) |
26 |
| -20. [Local Storage](#local-storage) |
27 |
| -21. [Cookies](#cookies) |
28 |
| -22. [JavaScript Tests](https://github.com/Asabeneh/JavaScript-for-Everyone/wiki/JavaScript-Tests): |
29 |
| -23. [JavaScript Interview Questions](#javascript-interview-questions) |
| 8 | +1. [Setup](#setup) |
| 9 | +1. [Variables](#variables) |
| 10 | +1. [Data Types](#data-types) |
| 11 | +1. [Operators](#operators) |
| 12 | +1. [Conditionals](#conditionals) |
| 13 | +1. [Arrays](#arrays) |
| 14 | +1. [Loops](#loops) |
| 15 | +1. [Functions](#functions) |
| 16 | +1. [Scope](#scope) |
| 17 | +1. [Hoisting](#Hoisting) |
| 18 | +1. [Object](#object) |
| 19 | +1. [Map and Set](#map-and-set) |
| 20 | +1. [Document Object Model](#document-object-model) |
| 21 | +1. [Class](#class) |
| 22 | +1. [Call Back and Higher Order Functions](#call-back-and-higher-order-functions) |
| 23 | +1. [Functional Programming](#functional-programming) |
| 24 | +1. [Destructuring](#destructuring) |
| 25 | +1. [Rest and Spread](#rest-and-spread) |
| 26 | +1. [Regular Expressions](#regular-expressions) |
| 27 | +1. [Local Storage](#local-storage) |
| 28 | +1. [Promises and Callback](#promises-and-callbacks) |
| 29 | +1. [Cookies](#cookies) |
| 30 | +1. [JavaScript Tests](https://github.com/Asabeneh/JavaScript-for-Everyone/wiki/JavaScript-Tests): |
| 31 | +1. [JavaScript Interview Questions](#javascript-interview-questions) |
30 | 32 |
|
31 | 33 |
|
32 | 34 | # Introduction
|
@@ -111,8 +113,6 @@ The external script link can be on the header or body but it is preferred to put
|
111 | 113 | <script src="introduction.js"></script>
|
112 | 114 | </head>
|
113 | 115 | <body>
|
114 |
| - //it could be in the header or in the body |
115 |
| - <script src="introduction.js"></script> |
116 | 116 | </body>
|
117 | 117 | </html
|
118 | 118 | ```
|
@@ -835,10 +835,10 @@ console.log(eightEmptyValues); // [empty x 8]
|
835 | 835 | const arr = Array(); // creates an an empty array
|
836 | 836 | console.log(arr);
|
837 | 837 | const eightXvalues = Array(8).fill('X'); // it creates eight element values
|
838 |
| -console.log(eightXvalue); // ['X', 'X','X','X','X','X','X','X'] |
| 838 | +console.log(eightXvalues); // ['X', 'X','X','X','X','X','X','X'] |
839 | 839 | ```
|
840 | 840 |
|
841 |
| - concat:To concatinate two arrays. |
| 841 | + concat:To concatenate two arrays. |
842 | 842 |
|
843 | 843 | ```js
|
844 | 844 | const firstList = [1, 2, 3];
|
@@ -899,21 +899,21 @@ toString:Converts array to string
|
899 | 899 | ```js
|
900 | 900 | const numbers = [1, 2, 3, 4, 5];
|
901 | 901 | console.log(numbers.toString()); // 1,2,3,4,5
|
902 |
| -const names = ['Asabeneh', 'Matias', 'Elias', 'Brook']; |
903 |
| -console.log(names.toString()); // Asabeneh,Matias,Elias,Brook |
| 902 | +const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']; |
| 903 | +console.log(names.toString()); // Asabeneh,Mathias,Elias,Brook |
904 | 904 | ```
|
905 | 905 |
|
906 | 906 | join:To join the elements of the array, the argument passed in the join method will be joined in the array and return as a string.
|
907 | 907 |
|
908 | 908 | ```js
|
909 | 909 | const numbers = [1, 2, 3, 4, 5];
|
910 | 910 | console.log(numbers.join()); // 1,2,3,4,5
|
911 |
| -const names = ['Asabeneh', 'Matias', 'Elias', 'Brook']; |
912 |
| -console.log(names.join()); // Asabeneh,Matias,Elias,Brook |
913 |
| -console.log(names.join('')); //AsabenehMatiasEliasBrook |
914 |
| -console.log(names.join(' ')); //Asabeneh Matias Elias Brook |
915 |
| -console.log(names.join(', ')); //Asabeneh, Matias, Elias, Brook |
916 |
| -console.log(names.join(' # ')); //Asabeneh # Matias # Elias # Brook |
| 911 | +const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']; |
| 912 | +console.log(names.join()); // Asabeneh,Mathias,Elias,Brook |
| 913 | +console.log(names.join('')); //AsabenehMathiasEliasBrook |
| 914 | +console.log(names.join(' ')); //Asabeneh Mathias Elias Brook |
| 915 | +console.log(names.join(', ')); //Asabeneh, Mathias, Elias, Brook |
| 916 | +console.log(names.join(' # ')); //Asabeneh # Mathias # Elias # Brook |
917 | 917 | ```
|
918 | 918 |
|
919 | 919 | Slice: To cut out a multiple items in range. It takes two parameters:starting and ending position. It doesn't include the ending position
|
@@ -2197,61 +2197,6 @@ console.log(result);
|
2197 | 2197 | #### Exercises:Regular Expressions
|
2198 | 2198 | - Calculate the total annual income of the person from the following text. ‘He earns 4000 euro from salary per month, 10000 euro annual bonus, 5500 euro online courses per month.’
|
2199 | 2199 |
|
2200 |
| -## localStorage |
2201 |
| -
|
2202 |
| -Local storage is the para of the web storage API which is used to store data on the browser with no expiration data. The data will be available on the browser even after the browser is closed. There are five methods to work on local storage: |
2203 |
| -_setItem(), getItem(), removeItem(), clear(), key()_ |
2204 |
| -
|
2205 |
| -##### Setting item to the localStorage |
2206 |
| -When we set data to be stored in a localStorage, it will be stored as a string. If we are storing an array or an object, we should stringify it first to keep the format unless otherwise we lose the array structure or the object structure of the original data |
2207 |
| -```js |
2208 |
| -localStorage.setItem('name', 'Asabeneh'); |
2209 |
| -console.log(localStorage) //Storage {name: 'Asabeneh', length: 1} |
2210 |
| -localStorage.setItem('age', 200); |
2211 |
| -console.log(localStorage) //Storage {age: '200', name: 'Asabeneh', length: 2} |
2212 |
| -const skills = ['HTML', 'CSS', 'JS', 'React']; |
2213 |
| -//Skills array has to be stringified first to keep the format. |
2214 |
| -const skillsJSON = JSON.stringify(skills,undefined, 4) |
2215 |
| -localStorage.setItem('skills', skillsJSON); |
2216 |
| -console.log(localStorage) //Storage {age: '200', name: 'Asabeneh', skills: 'HTML,CSS,JS,React', length: 3} |
2217 |
| -``` |
2218 |
| -If we are storing an array, an object or object array, we should stringify the object first. See the example below. |
2219 |
| -```js |
2220 |
| - |
2221 |
| -let skills = [ |
2222 |
| - { tech: 'HTML', level: 10 }, |
2223 |
| - { tech: 'CSS', level: 9 }, |
2224 |
| - { tech: 'JS', level: 8 }, |
2225 |
| - { tech: 'React', level: 9 }, |
2226 |
| - { tech: 'Redux', level: 10 }, |
2227 |
| - { tech: 'Node', level: 8 }, |
2228 |
| - { tech: 'MongoDB', level: 8 } |
2229 |
| -]; |
2230 |
| - |
2231 |
| -let skillJSON = JSON.stringify(skills); |
2232 |
| -localStorage.setItem('skills', skillJSON); |
2233 |
| -``` |
2234 |
| -##### Getting item from localStorage |
2235 |
| -```js |
2236 |
| -let name = localStorage.getItem('name'); |
2237 |
| -let age = localStorage.getItem('age'); |
2238 |
| -let skills = localStorage.getItem('skills'); |
2239 |
| -console.log(name, age, skills) // 'Asabeneh', '200', '['HTML','CSS','JS','React']' |
2240 |
| - |
2241 |
| - |
2242 |
| -let skillsObj = JSON.parse(localStorage.getItem('skills'), undefined, 4); |
2243 |
| -console.log(skillsObj); |
2244 |
| - |
2245 |
| -``` |
2246 |
| -##### Clearing the localStorage |
2247 |
| -The clear method, will clear everything stored in the local storage |
2248 |
| -```js |
2249 |
| -localStorage.clear(); |
2250 |
| -``` |
2251 |
| -
|
2252 |
| -## Exercises:Local Storage |
2253 |
| -
|
2254 |
| -## Cookies |
2255 | 2200 | ## Promises and Callbacks
|
2256 | 2201 | From the following code blocks you will notice, the difference between callback and promises:
|
2257 | 2202 |
|
@@ -2355,12 +2300,64 @@ console.log(square(10))
|
2355 | 2300 | fetchData()
|
2356 | 2301 | ```
|
2357 | 2302 |
|
| 2303 | +## localStorage |
2358 | 2304 |
|
| 2305 | +Local storage is the para of the web storage API which is used to store data on the browser with no expiration data. The data will be available on the browser even after the browser is closed. There are five methods to work on local storage: |
| 2306 | +_setItem(), getItem(), removeItem(), clear(), key()_ |
| 2307 | +
|
| 2308 | +##### Setting item to the localStorage |
| 2309 | +When we set data to be stored in a localStorage, it will be stored as a string. If we are storing an array or an object, we should stringify it first to keep the format unless otherwise we lose the array structure or the object structure of the original data |
| 2310 | +```js |
| 2311 | +localStorage.setItem('name', 'Asabeneh'); |
| 2312 | +console.log(localStorage) //Storage {name: 'Asabeneh', length: 1} |
| 2313 | +localStorage.setItem('age', 200); |
| 2314 | +console.log(localStorage) //Storage {age: '200', name: 'Asabeneh', length: 2} |
| 2315 | +const skills = ['HTML', 'CSS', 'JS', 'React']; |
| 2316 | +//Skills array has to be stringified first to keep the format. |
| 2317 | +const skillsJSON = JSON.stringify(skills,undefined, 4) |
| 2318 | +localStorage.setItem('skills', skillsJSON); |
| 2319 | +console.log(localStorage) //Storage {age: '200', name: 'Asabeneh', skills: 'HTML,CSS,JS,React', length: 3} |
| 2320 | +``` |
| 2321 | +If we are storing an array, an object or object array, we should stringify the object first. See the example below. |
| 2322 | +```js |
| 2323 | + |
| 2324 | +let skills = [ |
| 2325 | + { tech: 'HTML', level: 10 }, |
| 2326 | + { tech: 'CSS', level: 9 }, |
| 2327 | + { tech: 'JS', level: 8 }, |
| 2328 | + { tech: 'React', level: 9 }, |
| 2329 | + { tech: 'Redux', level: 10 }, |
| 2330 | + { tech: 'Node', level: 8 }, |
| 2331 | + { tech: 'MongoDB', level: 8 } |
| 2332 | +]; |
| 2333 | + |
| 2334 | +let skillJSON = JSON.stringify(skills); |
| 2335 | +localStorage.setItem('skills', skillJSON); |
| 2336 | +``` |
| 2337 | +##### Getting item from localStorage |
| 2338 | +```js |
| 2339 | +let name = localStorage.getItem('name'); |
| 2340 | +let age = localStorage.getItem('age'); |
| 2341 | +let skills = localStorage.getItem('skills'); |
| 2342 | +console.log(name, age, skills) // 'Asabeneh', '200', '['HTML','CSS','JS','React']' |
| 2343 | + |
| 2344 | + |
| 2345 | +let skillsObj = JSON.parse(localStorage.getItem('skills'), undefined, 4); |
| 2346 | +console.log(skillsObj); |
| 2347 | + |
| 2348 | +``` |
| 2349 | +##### Clearing the localStorage |
| 2350 | +The clear method, will clear everything stored in the local storage |
| 2351 | +```js |
| 2352 | +localStorage.clear(); |
| 2353 | +``` |
| 2354 | +
|
| 2355 | +## Exercises:Local Storage |
| 2356 | +
|
| 2357 | +## Cookies |
2359 | 2358 | ## [JavaScript Tests](https://github.com/Asabeneh/JavaScript-for-Everyone/wiki/JavaScript-Tests)
|
2360 | 2359 | ## JavaScript Interview Questions
|
2361 |
| -
|
2362 | 2360 | #### Exercises:Cookies
|
2363 |
| -
|
2364 | 2361 | ### [JavaScipt Tests](https://github.com/Asabeneh/JavaScript-for-Everyone/wiki/JavaScript-Test-1)
|
2365 | 2362 | ##### [JavaScript Test 1](https://github.com/Asabeneh/JavaScript-for-Everyone/wiki/JavaScript-Test-1)
|
2366 | 2363 | ##### [JavaScript Test 2](https://github.com/Asabeneh/JavaScript-for-Everyone/wiki/JavaScript-Test-2)
|
@@ -2485,14 +2482,14 @@ ___
|
2485 | 2482 | - [Creating a pattern with flags: global flag (g), case insensitive flag(i)](#creating-a-pattern-with-flags-global-flag-g-case-insensitive-flagi)
|
2486 | 2483 | - [RegExp Object Methods](#regexp-object-methods)
|
2487 | 2484 | - [Exercises:Regular Expressions](#exercisesregular-expressions)
|
| 2485 | + - [Promises and Callbacks](#promises-and-callbacks) |
| 2486 | + - [Async and Await](#async-and-await) |
2488 | 2487 | - [localStorage](#localstorage)
|
2489 | 2488 | - [Setting item to the localStorage](#setting-item-to-the-localstorage)
|
2490 | 2489 | - [Getting item from localStorage](#getting-item-from-localstorage)
|
2491 | 2490 | - [Clearing the localStorage](#clearing-the-localstorage)
|
2492 | 2491 | - [Exercises:Local Storage](#exerciseslocal-storage)
|
2493 | 2492 | - [Cookies](#cookies)
|
2494 |
| - - [Promises and Callbacks](#promises-and-callbacks) |
2495 |
| - - [Async and Await](#async-and-await) |
2496 | 2493 | - [JavaScript Tests](#javascript-tests)
|
2497 | 2494 | - [JavaScript Interview Questions](#javascript-interview-questions)
|
2498 | 2495 | - [Exercises:Cookies](#exercisescookies)
|
|
0 commit comments