├── A11Y.md
├── Bootstrap
└── Bootstrap.md
├── CSS
├── General-Notes-CSS.md
├── Resilient CSS Playlist.md
└── Responsive-Images.md
├── Compiler vs Transpiler.md
├── Git & GitHub
└── WRITING READMEs.md
├── HTML
├── HTML elements
├── HTML5 Sectioning Elements.md
├── HTML5 canvas.md
└── meme-maker.html
├── JS
├── Closure.md
├── Default Function Parameters.md
├── ES6 Built-ins.md
├── ES6 Functions.md
├── ES6 Syntax.md
├── Good Commenting Practices.md
├── IIFE.md
├── JS OOP.md
├── JS Promises.md
├── Memory management.md
├── Object Iteration.md
├── polyfills.md
├── symbols.md
└── this.md
├── JavaScript DOM.md
├── Plagiarism .md
├── Projects road map
└── P4: Classic Arcade Game.md
├── README.md
├── React
└── intro.md
├── ServiceWorker
├── notes.md
└── steps.md
├── Time
├── angular js
├── cheat sheet.md
└── directives.md
└── gulp
├── gulp tutorial.md
└── gulpfile.js
/A11Y.md:
--------------------------------------------------------------------------------
1 | # Accessibility
2 |
3 | _Source: Udacity Accessibility part of the Front end nanodegree_
4 |
5 | ### Table Of Contents:
6 | * [A11y Overview](#1-a11y-overview)
7 | * [FOCUS](#2-focus)
8 | * [Semantics Basics](#3-semantics-basics)
9 | * [Navigating Content](#4-navigating-content)
10 | * [ARIA](#5-aria)
11 | * [Style](#6-style)
12 |
13 |
14 | ## 1. A11y Overview
15 |
16 | - **Definition**: A11y means that site _**content**_ should be available to everyone and _**functionality**_ is operable to everyone.
17 | - It affects every user of your website, having _disabilities_, or others with _no disabilities_ but can not access your website due to unresponsive design, colors, etc...
18 |
19 |
20 | ### a. Screen Readers
21 |
22 | - [Chromevox extension](https://chrome.google.com/webstore/detail/chromevox/kgejglhpjiefppelpmljglcjbhoiplfn?hl=en)
23 | [Chromevox extension shortcuts](http://www.chromevox.com/keyboard_shortcuts.html)
24 |
25 |
26 | ### b. WCAG , Web Aim, and POUR
27 |
28 | - **[WCAG](https://www.w3.org/TR/WCAG20/)**: Web Content Accessibility Guidelines.
29 | It is about making your site POUR.
30 |
31 | - **POUR**: Percievable, Operable, Understandable, and Robust.
32 | - **[Web Aim Checklist](https://webaim.org/standards/wcag/checklist)**: a checklist for ensuring that the website meets WCAG guidelines.
33 |
34 |
35 |
36 | ## 2. FOCUS
37 |
38 | - [Web Aim](https://webaim.org/standards/wcag/checklist#sc2.1.1)
39 | - Implicity focusable elements (automatic tab order + built-in keyboard event handling) ex.:
40 | - input elements.
41 | - buttons.
42 | - _No need_ to focus something if the user can NOT interact with it, or provide some sort of input from the user.
43 | - [Focus Management](https://www.w3.org/TR/html5/editing.html#focus-management)- tab order is the same as DOM order even if the _visual_ order ( by CSS ) is changed.
44 | - Changing the order _visually_ can cause confusion to users depend on keyboard navigation. [Web Aim](https://webaim.org/standards/wcag/checklist#sc1.3.2).
45 |
46 |
47 | ### a. tabindex attribute
48 |
49 | - tabindex = "-1"
50 |
51 | [.] Not in tab order.
52 |
53 | [.] can be programmatically focused by focus()
54 |
55 | [.] For Off screen content (appears in response to user event) like modals.
56 | ```
57 |
58 | ```
59 |
60 | - tabindex = "0"
61 |
62 | [.] Insert natively Unfocusable element in tab order.
63 |
64 | [.] can also be programmatically focused by focus()
65 |
66 | [.] And then keyboard events get directed to it.
67 | ```
68 |
69 | ```
70 |
71 | - tabindex > 0
72 |
73 | [.] In front of tab order.
74 |
75 | [.] If multiple elements the lowest value is the first in tab order.
76 |
77 | [.] **ANTI - PATTERN**
78 |
79 | [.] Confuse screen readers and also keyboard users.
80 |
81 | [.] Instead change elements DOM order.
82 |
83 |
84 | #### :alien: JS
85 | To get tabindex value of an element:
86 | `element.tabIndex;`
87 |
88 |
89 | ```
90 | Don't add focus to any content user will Not interact with.
91 | ```
92 |
93 | #### :exclamation: Exception:
94 |
95 | This video shows an exception to this rule:
96 | https://www.youtube.com/watch?time_continue=155&v=ifW_oy9hajU
97 |
98 |
99 | ### b. Skip links
100 |
101 | - Allows screen reader users and keyboard, or switch devices users to directly navigate towards main content of the page bypassing navigation items and other things before main content.
102 | - Visually hidden until it comes into focus.
103 | ```
104 |
105 | Skip to main content
106 |
107 | .
108 | .
109 | .
110 |
111 |
112 | .
113 | .
114 | .
115 |
116 | ```
117 | ```
118 | /*CSS code*/
119 | .skip-link {
120 | position: absolute;
121 | top: -40px;
122 | left: 0;
123 | background: red;
124 | color: white;
125 | padding: 8px;
126 | z-index: 100;
127 | }
128 | .skip-link:focus {
129 | top: 0;
130 | }
131 | ```
132 |
133 | :alien: **[Alternate way to skip to main content.](https://webaim.org/techniques/skipnav/#headings)**
134 |
135 | ### c. Managing Focus at the component level
136 |
137 | - Like in case of drop down menu, tree view component. The keyboard interaction after getting focused is what we are talking about.
138 | - [WAI-Aria guidelines](https://www.w3.org/TR/wai-aria-practices-1.1/) provide guidance in selcting which keyboard interaction is appropriate for such action.
139 |
140 |
141 | ### d. Roving Focus
142 |
143 | - To implement focus inside of a component.
144 | - For example: Radio group:
145 | - first radio button: 1. tabindex="0" / 2. checked / 3. focus()
146 | - when moving to the next element => first element: 1. tabindex="-1" / 2. remove checked / 3. unfocus :: next element: 1. tabindex="0" / 2. checked / 3. focus()
147 | - If it is the last element `tab` move us to the first element.
148 | - If it is the first element `shift` + `tab` move us to the last element.
149 |
150 | - [Example](https://www.w3.org/TR/wai-aria-practices-1.1/examples/radio/radio-1/radio-1.html)
151 | - [Video](https://www.youtube.com/watch?v=uCIC2LNt0bk)
152 |
153 |
154 |
155 | ### e. Off-screen Content
156 |
157 | - Like drawer panel.
158 | - This can lead focus to visually disappear.
159 | - You can track the focus (active element) by `document.activeElement;`
160 | - Overcome it by setting `display: none;` or `visibility: hidden;`
161 |
162 | ### f. Keyboard Trap
163 |
164 | - [WebAim](https://webaim.org/standards/wcag/checklist#sc2.1.2)
165 | - It is desirable in modals when you want to trap keyboard focus inside the modal until you close it => return focus to the last focused element before modal open.
166 | - [Example](https://github.com/udacity/ud891/tree/gh-pages/lesson2-focus/07-modals-and-keyboard-traps)
167 |
168 |
169 |
170 | ## 3. Semantics Basics
171 |
172 | ### a. Affordances
173 |
174 | - Definition: the qualities or properties of an object that define its possible uses or make clear how it can or should be used.
175 | - [WebAim](https://www.w3.org/TR/UNDERSTANDING-WCAG20/ensure-compat-rsv.html)
176 | - Screen reader can provide info for elements' **Name(label) Role State Value.**
177 | - Browser takes DOM tree (natively semantic elements or othered with ARIA) ==modify it to==> Accessibility tree( containing all information for screen reader Name Role State Value).
178 |
179 | ### b. Labeling, Naming, and Alternative text
180 |
181 | - [WebAim](https://webaim.org/standards/wcag/checklist#g1.1)
182 | - Element could have a visual label (name) like for radio button or text alternative like in case of images.
183 | - There are 2 ways of labeling form inputs.
184 | ```
185 |
186 |
187 | Check me
188 |
189 | ```
190 | ```
191 |
192 | Check me
193 | ```
194 | - Using these labeling allow user to toggle the input element by also clicking the label.
195 | - alt text: 1. An alternative to the image if not loaded.
196 | 2. describe what the image about for screen reader.
197 | 3. For logos you can assign the company name for alt attribute.
198 | 4. For search icon you can leave alt with no value. This will skip it from accessibility tree.
199 | 5. Any image that is meant for decoration should have an empty alt.
200 |
201 |
202 | ## 4. Navigating Content
203 |
204 | - Screen Reader can make you navigate through headings, links, form controls, and landmarks.
205 | - It is important to use meaningful headings and links names.
206 | - Also use a good heading structure from h1 to h6 (for long complex content).
207 | - descriptive link text example:
208 | instead of using "learn more" links text use :learn more about bla bla".
209 | - [link Anti-patterns video](https://youtu.be/SiblO4dfYBg)
210 | - Landmarks: you can navigate by landmarks
211 | ``
212 | ``
213 | ``
214 | ``
215 | ``
216 | ``
217 | ``
218 |
219 |
220 |
221 | ## 5. ARIA
222 |
223 | - **WAI-ARIA**: Web Accessibility Initiative - Accessible Rich Internet Application.
224 | - ARIA attributes need to have explicit values (can't be empty values).
225 |
226 | - What ARIA can do and what can not do:
227 | - Can:
228 |
229 | :white_check_mark: modify Accessibility tree.
230 |
231 | - Can Not:
232 |
233 | :x: modify element behaviour.
234 |
235 | :x: modify element appearance.
236 |
237 | :x: add focus.
238 |
239 | :x: add event handling.
240 |
241 | - ARIA give a semantic meaning to non semantic elements.
242 | - ARIA can also give a new semantic meaning to a native semantic element.
243 | - Example:
244 | ```
245 |
246 | Enable
247 |
248 | ```
249 | - ARIA can express UI patterns which doesn't exist in HTML.
250 | - Example: `tree widget`
251 |
252 | - ARIA can add labels which is only accessible to assestive technology.
253 |
254 | - ARIA can provide semantic Relationship.
255 |
256 | - ARIA can provide live updates (aria-live).
257 |
258 | - the [video](https://youtu.be/7vz1aakYHtw?t=50s) explains that.
259 |
260 | ### a. Role
261 |
262 | - Definition: Short hand for a particular UI pattern.
263 |
264 | - make sure that the role attribute is in the same element as tabindex attribute.
265 |
266 | ```
267 | check me
268 | ```
269 |
270 | ### b. ARIA labelling
271 |
272 | - **aria-label** _attribute_
273 | - Can be used for element that has only a visual appearance.
274 | - override any other labelling such as ``, or text content (like that for a button) except **aria-labelledby** _attribute_.
275 | - have the label clicking behaviour like ``
276 |
277 | - **aria-labelledby** _attribute_
278 | - Overcome all other labelling methods.
279 | - refers to another element (which label it) by using a value corresponds to the id of the labelling element.
280 | - can take more than one element id (multiple labels) .
281 | - can refer to elements that are hidden for assestive technologies ( hidden for example).
282 | - Don't have the label clicking behaviour like `` and `aria-label`.
283 |
284 |
285 | ### c. Landmarks and ARIA roles
286 | - Landmarks may not have support in browsers' old versions. So we need to use role attribute with them.
287 | -Examples:
288 | ```
289 |
290 |
291 |
292 |
293 |
294 |
295 | ```
296 |
297 | ### d. ARIA realtionships
298 |
299 | - **ARIA relationship attributes**
300 | - They take a reference to one or more elements on the page to make a link between them.
301 | - The difference is: 1. _What link means_.
302 | 2. _How represented to users_.
303 |
304 | - Attributes:
305 | - `aria-labelledby`
306 | - `aria-describedby`
307 | - `aria-owns`
308 | - `aria-activedescendant`
309 | - `aria-posinset`
310 | - `aria-setsize`
311 |
312 | - [Video](https://youtu.be/e1ZmfmnB6v8?t=40s) explains it.
313 |
314 | - [Collection of relationship attr](https://www.w3.org/TR/wai-aria-1.1/#attrs_relationships)
315 |
316 |
317 | ### e. Visible and Hidden content
318 |
319 | - For the seek of fine tuning the experience of users using assistive tech.
320 | - To ensure that certain parts of the DOM is either:
321 | - hidden to assistive tech.
322 | Or
323 | - Only visible to assistive tech.
324 | - Hidden:
325 |
326 | 1.
327 | ```
328 |
329 |
330 |
331 | ```
332 | 2. `aria-hidden="true"`
333 |
334 | - Only visible to assistive tech:
335 | 1. element positioned absolute far off the screen. `position: absolute; left: -1000;`
336 | 2. `aria-label`
337 | 3. `aria-labelledby` or `aria-describedby` reference a hidden element.
338 |
339 |
340 | ### f. ARIA live
341 |
342 | - for in time alerts to user.
343 | - `aria-live="polite"` : important but not urgent alert.
344 | - `aria-live="assertive"` : important and urgent alert.
345 |
346 | ### g. ARIA relevant
347 |
348 | - attributes work with `aria-live`.
349 | - They are:
350 |
351 | - `aria-atomic` : when true assistive tech will present the entire region as a whole.
352 |
353 | - `aria-relevant` :indicates which type of changes should be presented to the user.
354 |
355 | `aria-relevant="additions"` ==> means any element added to live region is presented.
356 |
357 | `aria-relevant="text"` ==> means that any text content added to any descendant element is presented.
358 |
359 | `aria-relevant="removals"` ==> means that removal of any text or element within the live region is presented.
360 |
361 | `aria-relevant="all"` ==> means that additions or removals of text is presented.
362 |
363 | `aria-relevant="additions text"` (default).
364 |
365 | - `aria-busy`
366 |
367 |
368 |
369 | ## 6. Style
370 |
371 | ### a. Focus style
372 |
373 | - [WebAim](https://webaim.org/standards/wcag/checklist#sc2.4.7).
374 | - [video shows different styling for focus using :focus pseudo selector](https://youtu.be/ZooEnrj8aMc).
375 | - [video shows different styling reaction between native and non native buttons](https://youtu.be/bfPGicTGBTI).
376 | - Styling with ARIA ==> using ARIA attribute as an attribute selector. This made a good verification that I set the aria state properly.
377 | - Responsive website:
378 | - [WebAim](https://webaim.org/standards/wcag/checklist#sc1.4.4).
379 | - meta viewport tag: ` `
380 | - In meta viewport tag: don't use `user-scalable=no` ==> prevent user from zooming the screen.
381 | - Use relative CSS units.
382 | - Use appropriate size touch targets.Minimum touch target size is 48 px.
383 | - If the touch target(like icons) is smaller, add padding to it.
384 | - To avoid overlapping make sure to leave margin around touch target with minimum 32px.
385 | - Color Contrast:
386 | - [WebAim Minimum](https://webaim.org/standards/wcag/checklist#sc1.4.3).
387 | -It states that: Body text (less than 18.66px) ==> Contrast ratio minimum `4.5:1`
388 | Large Text (more than 18.66px) or (24px) ==> Contrast ratio minimum `3:1`
389 |
390 | - [WebAim Enhanced](https://webaim.org/standards/wcag/checklist#sc1.4.6).
391 | -It states that: Body text (less than 18.66px) ==> Contrast ratio minimum `7:1`
392 | Large Text (more than 18.66px) or (24px) ==> Contrast ratio minimum `4.5:1`
393 | - You can use {Chrome Accessibility Extension}(https://chrome.google.com/webstore/detail/accessibility-developer-t/fpkknkljclfencbdbgkenhalefipecmb?hl=en) to make Accessibility Audit to check contrast ratios and see recommendations and try them live at Dev tools.
394 | - 1 of 20 men and 1 in 200 women suffer from some sort of color blindness.
395 | - Don't convey info with color alone.
396 | - You can use color together with text, underline, audio, and aria-live.
397 | - [WebAim](https://webaim.org/standards/wcag/checklist#sc1.4.1).
398 | - You can use [Nocoffee chrome extension](https://chrome.google.com/webstore/detail/nocoffee/jjeeggmbnhckmgdhmgdckeigabjfbddl?hl=en-US) to experience color blindness vision and enhance use of color to convey info.
399 | - You can use [High Contrast chrome extension](https://chrome.google.com/webstore/detail/high-contrast/djcfdncoelnlbldjfhinnjlhdjlikmph?hl=en) and check how your UI appear for high contrast users.
400 |
401 |
--------------------------------------------------------------------------------
/Bootstrap/Bootstrap.md:
--------------------------------------------------------------------------------
1 | # **Bootstrap**
2 | --------------------------------------------------------
3 |
4 | ## :point_right: **div classes**
5 |
6 | 1. `container-fluid`
7 | 2. `row`
8 | 3. `col-xs-*`
9 | 4. `col-sm-*`
10 | 5. `col-md-*`
11 | 6. `col-lg-*`
12 | 7. `container`
13 |
14 | :musical_note: The Bootstrap grid system has four classes:
15 | - xs (for phones - screens < 768px wide)
16 | - sm (for tablets - screens => 768px wide)
17 | - md (for small laptops - screens => 992px wide)
18 | - lg (for laptops and desktops - screens=> 1200px wide)
19 |
20 | 8. `well`
21 | -------------------------------------------------------
22 | ## :point_right: **img classes**
23 |
24 |
25 | 1. `img-responsive`
26 | ------------------------------------------------------
27 | ## :point_right: **text classes**
28 |
29 | 1. `text-center`
30 | 2. `text-danger`
31 | 3. `h1` to `h6`
32 | 4. `text-muted`
33 | 5. `display-1` to `display-4`
34 | 6. `lead`
35 | 7. `blockquote`
36 | 8. `blockquote-reverse`
37 | 9. `blockquote-footer`
38 | -----------------------------------------------------
39 | ## :point_right: **button classes**
40 |
41 | 1. `btn`
42 | 2. `btn-block`
43 | 3. `btn-primary`
44 | 4. `btn-info`
45 | 5. `btn-danger`
46 | 6. `btn-default`
47 | ---------------------------------------------------
48 | ## :point_right: **input type: text**
49 |
50 | 1. `form-control`
51 | `
52 |
--------------------------------------------------------------------------------
/CSS/General-Notes-CSS.md:
--------------------------------------------------------------------------------
1 | # **CSS GENERAL NOTES**
2 |
3 | ## **Overriding in CSS** :hand:
4 |
5 | - **Overriding in a _descending_ order**
6 | **!important** (_override all_) > **Inline Style** > **id** > **Subsequent Selector**
7 |
8 | - :star: **Basically, the closer the style rule is to an element, the more specific it is. **
9 |
--------------------------------------------------------------------------------
/CSS/Resilient CSS Playlist.md:
--------------------------------------------------------------------------------
1 | # Description
2 |
3 | A video series ( 7 episodes) on how resilient CSS is and how to use new properties on every browser on the earth to make most of our users have similar or even the same experience with your websites.
4 | It is presented by [Jen Simmons](https://twitter.com/jensimmons?lang=en).
5 |
6 | Initial notes:
7 |
8 | 1. Can I use
9 | 2. It is ok for some property being ignored by some unspported browsers.
10 | 3. override
11 | 4. feature query
12 | 5. feature query support / "not"
13 | 6. working another way out. / doesn't deserve any of the above and there are another way out.
14 |
--------------------------------------------------------------------------------
/CSS/Responsive-Images.md:
--------------------------------------------------------------------------------
1 | # **Responsive Images**
2 |
3 | A course by [Udacity](https://classroom.udacity.com/courses/ud882).
4 |
5 | ----------------------------------------------------------------------------------------------
6 |
7 | ## **Introduction**
8 |
9 | - More than 60% of Bytes per page is images.
10 |
11 |
12 |
13 |
14 | Average Bytes Per Page Per Content Type. A diagram from http://httparchive.org .
15 |
16 |
17 |
18 |
19 | ## **Bits & Pixels**
20 |
21 | #### bits = pixels * bits per pixel (bpp)
22 |
23 |
24 | ## **Relative Sizing**
25 |
26 | - **Fixed image size in for example pixels would create Unresposive image that will not resize.**
27 | - **If you make `width : 100%;` It will resize as broswer resize but it will lead to pixelation of the image when it resizes to larger of its natural width.**
28 | - **But if you make `max-width: 100%` It will resize to a maximum width of its natural width only and will not pixelate.**
29 | - **If you want 2 images to fit side by side you can change to `max-width: 50%;`.**
30 |
31 | ## **Quiz: calc()**
32 |
33 | - **Using `Calc` is very important when we want the size (width for example) to take the remaining area after a fixed area is taken (for a maring for example).**
34 |
35 | **_This is a [quiz](https://classroom.udacity.com/courses/ud882/lessons/3520939843/concepts/37391188270923)._**
36 |
37 | ## **vh vw vmin vmax CSS Units**
38 |
39 | - **vh: viewport height vw: viewport width. vmin: viewport minimum vmax: viewport maximum.**
40 |
41 | - **You can set the height of an image to 100% but this only works if the html and body elements are set to 100%.**
42 |
43 | - **Alternatively, you can set **
44 | ```
45 | width: 100vw;
46 | height: 100vh;
47 | ```
48 | **
49 |
50 | - **Take care of the aspect ratio in this case if you want to keep it.**
51 |
52 | - **It is better to view vmin and vmax with examples to understand.**
53 |
54 | ## **Raster vs Vector**
55 |
56 | ### **Raster images**
57 |
58 | - **is a grid of individual dots of color.**
59 |
60 | - **Source:**
61 |
62 | - Camera.
63 | - Scanner.
64 | - HTML canvas.
65 |
66 | - **Example:** photographs.
67 |
68 |
69 |
70 | ### **Vector images**
71 |
72 | - **is a set of curves, lines, shapes, fill colors, and gradients.**
73 |
74 | - **Source:**
75 | - Adobe Illustrator.
76 | - Inkscape.
77 | - Using a vector format such as SVG.
78 | - **Examples:** Logos, Line art.
79 |
80 | - **Browser can render vector images at any size.**
81 |
82 | ## **General Rules:**
83 |
84 | 1. Use JPEG for Photographs.
85 | 2. Use WebP for Photographs(better than JPEG) (supported by chrome).
86 | 3. Use SVG for vector images, solid color graphics, logos, line art.
87 | 4. Use PNG for the same as above if you can't use SVG.
88 |
89 | ### Some useful links:
90 | - [Image Optimization](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/image-optimization).
91 |
92 | - [About WebP](https://developers.google.com/speed/webp/?csw=1).
93 |
94 | #### **IMPORTANT :heavy_exclamation_mark: [Page Speed Insights](https://developers.google.com/speed/pagespeed/insights/)**
95 |
96 |
97 | ## **Performance**
98 |
99 | ### **Latency:** is the delay between request & response.
100 |
101 | - **The latency affects Page loading times more than bandwidth.**
102 |
103 | - **So to increase performance you need to _compress images_ and _decrease the no of requests_.**
104 |
105 | - **It is better to use text overlaying an image than to use a text as an image.**
106 |
107 |
108 | ## **Background images**
109 |
110 | - **background-size: _cover_ or _contain_**
111 | - **Background images are responsive.**
112 |
113 | ## **Symbol characters**
114 |
115 | - **You can write symbols instead of images by using unicode.**
116 | - **They are more than 110000 characters.**
117 | - **They are responsive.**
118 |
119 |
120 | ## **Icon Fonts**
121 |
122 | - **They are treated as text.**
123 | - **Scalable (responsive) as it is a vector without a decrease in quality with minimum downloads (less requests). Indeed only one request**
124 |
125 | - **You can style it easily using CSS like shadow, size, color, etc. And you also add it by CSS clases.**
126 |
127 | - **They are lots of them.**
128 |
129 | - **Examples:
130 |
131 | - **[Font Awesome](https://fontawesome.com/).**
132 | - **[Zocial](http://zocial.smcllns.com/).**
133 |
134 |
135 | ## **SVG & Data Uri**
136 |
137 | - **Maximum scalability.**
138 |
139 | - **Very low size.**
140 |
141 | - **Can be implemented using HTML, OR CSS.**
142 |
143 |
144 | ## **Accessibility**
145 |
146 | - **Some advices for using alt attribute with img element:**
147 |
148 | - `alt` attributes should be set on every image.
149 | - `alt` attributes should be descriptive for important images.
150 | - `alt` attributes should be empty for images that are just decorations.\
151 |
152 | - **ChromeVox is a free screen reader.**
153 |
154 |
155 | **_The End_**
156 |
157 | _Last advice: The subject needs more and more reading and practice._
158 |
--------------------------------------------------------------------------------
/Compiler vs Transpiler.md:
--------------------------------------------------------------------------------
1 | # Compiler vs Transpiler
2 |
3 | - ## Compiler:
4 | - Source Code (Human readable code) ===> **_Compiler_** ===> target code (machine runnable code) (lower level code language).
5 |
6 | - Compiler changes the code language level of "**abstraction**".
7 |
8 |
9 | - ## Transpiler:
10 | - Source Code ===> **Transpiler** ===> target code (same level code lnguage).
11 |
12 | - Transpiler does NOT change code language level of "**abstraction**"
13 |
14 | - Avery good example:
15 | Transpilers ( like [Babel](https://babeljs.io/)) we use to convert ES6 code to ES5 code to run on older browsers that don't support ES6.
16 |
--------------------------------------------------------------------------------
/Git & GitHub/WRITING READMEs.md:
--------------------------------------------------------------------------------
1 | # **WRITING READMEs**
2 |
3 | ### Description:
4 | ##### It is a part of the _Udacity Front End Nanodegree program_.
5 |
6 | ---------------------------------------------------------------------------------------------------------------------
7 |
8 |
9 |
10 | ## **Who Is Your Documentation For?**
11 |
12 | #### Documentation is for:
13 | - **Future YOU.**
14 | - **Your Co-workers, or Contributers.**
15 | - **Your End User.**
16 |
17 | _And that's why Documentations should be **clear, descriptive and easy to follow**._
18 |
19 |
20 | ## **Anatomy Of A README**
21 |
22 | 1. **Title & Description.**
23 | - a sentece or two may be enough but be sure to provide clear explanation.
24 |
25 | 2. **Information for undersanding your code/project.**
26 | This may include:
27 | - _Installation instructions._
28 | - _Dependencies on other libraries, frameworks._
29 | - _Usage._
30 | - _Known bugs._
31 | - _Issues._
32 | - _Examples._
33 |
34 | 3. **License.**
35 |
36 |
37 | ## **Markdown**
38 |
39 | a light markup language often used for READMEs (though you'll find other use cases for it, too!).
40 |
41 | Here is [Markdown documentaion](https://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/).
42 |
43 | ## **HTML**
44 |
45 | You can still use HTML in markdown when you could not accomplish something using markdown.
46 |
47 | ## **Dillinger**
48 |
49 | - Markdown files use **.md** extension. It needs to be opened by specific software like [**Dillinger**](https://dillinger.io/).
50 | - You can also open it in your text editors using some plugin or extension.
51 | - For VS Code you can install [Markdown All In One extension](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one).
52 |
53 |
54 |
55 | _The End_
56 |
--------------------------------------------------------------------------------
/HTML/HTML elements:
--------------------------------------------------------------------------------
1 | # HTML elements
2 |
3 | 1. `` => highlight text.
4 | 2. `` => for blockquote. Can have the cite attribute.
5 | 3. `` => inline quote. Most browser will add quotation marks around text inside tags. Can have the cite attribute.
6 | 4. `` => inside a blockquote element at the end of it will add the blockquote footer preceded by a wide hyphen.
7 | 5. ``
8 |
--------------------------------------------------------------------------------
/HTML/HTML5 Sectioning Elements.md:
--------------------------------------------------------------------------------
1 | # **HTML5 Sectioning Elements**
2 |
3 | :exclamation: **Importance:**
4 |
5 | - gives more semantic meaning to your pages, allowing computer programs to better understand your content, enhance accessibility, and SEO friendly.
6 |
7 | ```
8 |
9 | ```
10 |
11 | - **contain the main content for your web page.**
12 | - **content should be unique to the individual page.**
13 | - **content should NOT appear elsewhere on the site.**
14 | - **should NOT have any content that is repeated on multiple pages (logos, search boxes, footer links, etc.)**
15 | - **should NOT be placed within ``, ``, ``, ``, or `` elements.**
16 | - **Only ONE `` element for each page.**
17 |
18 |
19 | ```
20 |
21 | ```
22 |
23 | - **contain a piece of self-contained content that could be distributed outside the context of the page.**
24 | - **like news articles, blog posts, or user comments.**
25 | - **could be _Nested_ inside each other. And this means that the nested one relate to the outer one.**
26 |
27 |
28 | ```
29 |
30 | ```
31 |
32 | - **contain a group of related content. **
33 | - **content doesn’t necessarily need to make sense out of the context of the page.(the main diff from ``).**
34 | - **It’s advisable to use a heading element `` to `` to define the topic of the section.**
35 | - **If you just need to group content together for styling purposes you should use `` instead.**
36 |
37 |
38 | ```
39 |
40 | ```
41 |
42 | - **used to:**
43 | - **contain a collection of links to external pages or sections within the current page.**
44 | - **table of contents.**
45 | - **blogroll.**
46 | - **It is better to mark up the links within list elment but this is not necessary with ``.**
47 |
48 | ```
49 |
50 |
55 |
56 | ```
57 |
58 |
59 | ```
60 |
61 | ```
62 |
63 | - **for content that is not directly related to the content surronding it and could be considered separate.
64 | - **like sidebars, `` elements.
65 |
66 | ```
67 |
68 |
72 | ...
73 | ...
74 |
75 |
79 |
80 | ```
81 |
82 | ```
83 |
84 | ```
85 |
86 | - **represent the introductory content to an article or web page. **
87 | - **contains:**
88 | - **a heading element like ``.**
89 | - **some metadata that’s relevant to the content, such as the post date.**
90 | - **table of contents (within ``).**
91 | - **associated with the nearest sectioning element.**
92 |
93 |
94 | ```
95 |
96 | ```
97 |
98 | - **represent information about a section such as _author, copyright information, or links to related web pages._**
99 | - **associated with the nearest sectioning element.**
100 |
101 |
102 | ```
103 |
104 | ```
105 |
106 | - **NOT for marking up postal address.**
107 | - **represent contact information for an article or web page.**
108 | - **like author’s website or their email address.**
109 | - **often used within ``.
110 |
111 | ```
112 |
113 |
117 | ...
118 | ...
119 |
120 |
121 | By Matt West
122 |
123 | Copyright Matt West 2014
124 |
125 |
126 | ```
127 |
128 |
129 | :blue_book: Source: [How to Use The HTML5 Sectioning Elements](http://blog.teamtreehouse.com/use-html5-sectioning-elements).
130 |
--------------------------------------------------------------------------------
/HTML/HTML5 canvas.md:
--------------------------------------------------------------------------------
1 | # HTML5 canvas
2 |
3 | - Contents:
4 | 1. [Description](#description).
5 | 2. [Create a canvas](#create-a-canvas).
6 | 3. [Loading Images Code](#loading-images-code).
7 | 4. [Drawing Rectangle](#drawing-rectangle).
8 | 5. [Clear Rectangle](#clear-rectangle).
9 | 6. [Paths](#paths).
10 | 7. [save() & restore()](#save--restore).
11 | 8. [Moving Objects in a Canvas](#moving-objects-in-a-canvas).
12 | 9. [Color Objects](#color-objects).
13 | 10. [Draw Text](#draw-text).
14 | 11. [Grayscale Conversion Algorithms](#grayscale-aconversion-algorithms).
15 | 12. [Resources](#resouces).
16 |
17 | ## Description:
18 | - A Udacity HTML5 canvas course. [Here is its link](https://classroom.udacity.com/courses/ud292).
19 | - I will try to make notes on the important things of the course.
20 | - The `` is just a container for drawing withthe use of JavaScript.
21 |
22 |
23 |
24 | ## Create a canvas:
25 |
26 | - HTML Syntax: ` `
27 | - Attributes: `width` ==> Width of the canvas in CSS pixels (Default 150).
28 | `height` ==> Height of the canvas in CSS pixels (Default 150).
29 |
30 |
31 | - JavaScript Syntax:
32 | ```javascript
33 | const canvas = document.getElementById('canvas');//to select the canvas element
34 | const ctx = canvas.getContext('2d');//to get the context of the 2d canvas. It can also be 3d but this course is about 2d.
35 | ```
36 |
37 | - In case we want an obaque canvas you can write:
38 |
39 | ```javascript
40 | const ctx = canvas.getContext('2d', {alpha: false});
41 | ```
42 |
43 | - After setting the context and assign it a variable `ctx`. We will use it to draw on the canvas like in the following examples.
44 |
45 |
46 | ## Loading Images Code
47 |
48 | - Using method drawImage()
49 | - It is called on the CanvasRenderingContext2D interface.
50 | - Syntax:
51 |
52 | It can contain either 3, 5, or 7 parameters:
53 |
54 | `ctx.drawImage(image, dx, dy);`
55 |
56 | `ctx.drawImage(image, dx, dy, dWidth, dHeight);`
57 |
58 | `ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);`
59 |
60 | Parameters:
61 |
62 | `image`: the image url.
63 |
64 | `dx`: the x coordinate of image.
65 |
66 | `dy`: the y coordinate of image.
67 |
68 | `sx`: The x coordinate where to start clipping.
69 |
70 | `sy`: The y coordinate where to start clipping.
71 |
72 | `dWidth`: The width to draw the image in the destination canvas. This allows _scaling_ of the drawn image. If not specified, the image is NOT scaled in width when drawn.
73 |
74 | `dHeight`: The height to draw the image in the destination canvas. This allows _scaling_ of the drawn image. If not specified, the image is not scaled in height when drawn.
75 |
76 | `sWidth`: The width of the clipped image.
77 |
78 | `sHeight`: The height of the clipped image.
79 |
80 |
81 | - Example:
82 | ```html
83 |
84 |
93 | ```
94 |
95 | ## Drawing Rectangle:
96 |
97 | - Syntax:
98 | ```javascript
99 | ctx.fillRect(x,y,width,height);//draws a colored rectangular.
100 | ```
101 | ```javascript
102 | ctx.strokeRect(x,y,width,height);//draws an empty rectangular.
103 | ```
104 |
105 |
106 | ## Clear Rectangle:
107 |
108 | - Synatx:
109 | ```javascript
110 | ctx.clearRect(x, y, width, height);
111 | ```
112 |
113 |
114 |
115 | ## Paths:
116 |
117 | - This [link](http://www.w3.org/TR/2dcontext/#building-paths) explains it in details.
118 |
119 |
120 |
121 | ## save() & restore():
122 |
123 | - `save()`:
124 | [o] saves the most current state to be called after with `restore()`
125 | [o] If called in the before a current state it saves the default on. An example from MDN(https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save#Examples).
126 | [o] Syntax:
127 | ```javascript
128 | ctx.save();//called after the state was declared.
129 | ```
130 |
131 | - `restore()`:
132 | [o] restores the most recently saved canvas state.
133 | [o] Syntax:
134 | ```javascript
135 | ctx.restore();//called before drawing the object we want to restore the state on.
136 | ```
137 |
138 |
139 | ## Moving Objects in a Canvas:
140 |
141 | `ctx.scale(x, y);`
142 |
143 | `ctx.translate(x, y);`
144 |
145 | `ctx.rotate(angleRadians);`: anglaeRadian = degrees * (Math.PI/180)
146 |
147 | - Order of operations: 1. scale
148 | 2. rotate
149 | 3. translate
150 |
151 |
152 | ## Color Objects:
153 |
154 | `ctx.strokeStyle = "someColor";//color can be a named color (140 named color in HTML), or a hexadecimal color.`
155 |
156 | `ctx.fillStyle = "someColor";`
157 |
158 | `ctx.fill();
159 | //can be used for example if we draw a rectangle by rect() instead of fillRect(), or to color path with the fillStyle color specified.`
160 |
161 |
162 | ## Draw Text:
163 |
164 | `ctx.strokeText(x, y, [optional max-width]);`
165 |
166 | `ctx.fillText(x, y, [optional max-width]);`
167 |
168 | - You can combine both `strokeText` and `fillText`
169 |
170 | - Here is the [meme-maker](https://github.com/Islam888/Study-Notes/blob/master/HTML/meme-maker.html) exercise app by udacity.
171 |
172 |
173 |
174 | ## Grayscale Conversion Algorithms:
175 |
176 | - [Here is the link to the article](http://www.tannerhelland.com/3643/grayscale-image-algorithm-vb6/).
177 |
178 |
179 | ## Resources:
180 |
181 | - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas
182 | - https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API
183 | - https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage
184 | - https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API
185 | - https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL
186 | - https://www.w3schools.com/tags/canvas_drawimage.asp
187 | - http://diveintohtml5.info/canvas.html#text
188 | - http://html5gamedevelopment.com/2013-12-developing-html5-games-1hr-video-presentation/
189 | - https://www.udemy.com/how-to-program-games/
190 | - https://www.udemy.com/courses/search/?q=html%20canvas&src=ukw&sort=most-reviewed
191 | - [A good youtube course](https://www.youtube.com/watch?v=EO6OkltgudE&list=PLpPnRKq7eNW3We9VdCfx9fprhqXHwTPXL).
192 |
193 |
194 |
195 |
--------------------------------------------------------------------------------
/HTML/meme-maker.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | MemeMaker-Simple
6 |
7 |
8 |
9 |
10 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
32 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/JS/Closure.md:
--------------------------------------------------------------------------------
1 | # Closure
2 |
3 | ### Table of Contents:
4 | - [Definition](https://github.com/Islam888/Study-Notes/blob/master/JS/Closure.md#definition).
5 | - [Example 1](https://github.com/Islam888/Study-Notes/blob/master/JS/Closure.md#example-1).
6 | - [Example 2](https://github.com/Islam888/Study-Notes/blob/master/JS/Closure.md#example-2).
7 | - [Example 3](https://github.com/Islam888/Study-Notes/blob/master/JS/Closure.md#example-3).
8 |
9 |
10 |
11 | ### Definition:
12 | - Simply is a function that has a reference ( can access ) a private variable.
13 |
14 |
15 | ### Example 1:
16 |
17 | ```
18 | function Person(pName) {
19 | this.name = pName;
20 | }
21 | const me = new Person('Islam');
22 | me.name;//'Islam'
23 | ```
24 | Now let's do it another way
25 | ```
26 | function Person(pName) {
27 | var name = pName;
28 | }
29 | const me = new Person('Islam');
30 | me.name;//undefined
31 | ```
32 | Instead we could use a closure to have a reference to this private name variable.
33 | ```
34 | function Person(pName) {
35 | var name = pName;
36 | return function() {
37 | return this.name = pName;
38 | }
39 | }
40 | const obj = Person('Islam');
41 | const me = new obj();
42 | me.name;//'Islam'
43 | ```
44 |
45 | ### Example 2
46 |
47 | ```
48 | function counterFunction() {
49 | var counter = 0;
50 | return function () {return counter += 1;}
51 | }
52 | const add = counterFunction();
53 | add();//1
54 | add();//2
55 | add();//3
56 | ```
57 | The add() refer to the returned anonymous function which has reference to the private counter variable and increment it by 1 each time the add() invoked.
58 | If you wrote `add;` in console it will return the returned anonymous function.
59 | ```
60 | add;//ƒ () {return counter += 1;}
61 | ```
62 |
63 |
64 | ### Example 3
65 |
66 | ```
67 | function invokeTwice(callback) {
68 | callback();
69 | callback();
70 | }
71 |
72 | const dog = {
73 | age: 5,
74 | growOneYear: function () {
75 | this.age += 1;
76 | }
77 | };
78 | ```
79 | Invoking the function `invokeTwice(dog.growOneYear);//undefined` will not increment age property of the dog object. This is because _this_ inside a regular function is scoped to the global object `window` when the function is invoked.
80 | A solution to that is using a closure function to have a refernce to age property inside the dog object and then the method can increment its value.
81 | ```
82 | invokeTwice(function() {
83 | dog.growOneYear()});
84 | dog.age;//7
85 | ```
86 |
--------------------------------------------------------------------------------
/JS/Default Function Parameters.md:
--------------------------------------------------------------------------------
1 | # Default Function Parameters
2 |
3 | In case of:
4 | ```
5 | function sayHi (name, greeting) {
6 | return `${greeting} ${name}`;}
7 |
8 | sayHi('Islam', 'Hi');//Hi Islam
9 | sayHu();//Uncaught ReferenceError: sayHu is not defined at ...
10 | ```
11 |
12 | You can write
13 | ```
14 | function sayHi (name, greeting) {
15 | name = (name !== undefined)? name : 'Islam';
16 | greeting = (greeting !== undefined)? greeting : 'Hi'
17 | return `${greeting} ${name}`;}
18 |
19 | sayHi();// Hi Islam
20 | sayHi('Hazem', 'Hello');//Hello Hazem
21 | ```
22 |
23 | How verbose this is!
24 | So you can instead write
25 | ```
26 | function sayHi (name = 'Islam', greeting = 'Hi') {
27 | return `${greeting} ${name}`;}
28 |
29 | sayHi();// Hi Islam
30 | sayHi('Hazem', 'Hello');//Hello Hazem
31 | ```
32 |
33 | This is what is meant by default function parameters. Assigning a default values for function parameters in case no values are assigned when invoking the function.
34 |
35 |
36 |
--------------------------------------------------------------------------------
/JS/ES6 Built-ins.md:
--------------------------------------------------------------------------------
1 | # ES6 Built-ins
2 |
3 | Description: _This is an index for the files notes of Built-ins lesson of Udacity Front End Nanodegree course._
4 |
5 | ### Table of Contents:
6 |
7 | 1. [symbols](https://github.com/Islam888/Study-Notes/blob/master/JS/symbols.md).
8 | 2. [Object Iteration](https://github.com/Islam888/Study-Notes/blob/master/JS/Object%20Iteration.md).
9 |
--------------------------------------------------------------------------------
/JS/ES6 Functions.md:
--------------------------------------------------------------------------------
1 | # ES6 Functions
2 |
3 | ## Table of contents:
4 | - [Introduction](#introduction).
5 | - [Arrow Functions](#arrow-functions).
6 | - [Arrow Functions and this key word](#arrow-functions-and-this-key-word).
7 | - [Default Function Parameter](#default-function-parameters).
8 | - [Destructuring with Default Function Parameters](#destructuring-with-default-function-parameters).
9 | - [JS Classes](#js-classes).
10 | - [Subclasses with extends, and super](#subclasses-with-extends-and-super).
11 |
12 | ## Introduction:
13 |
14 | ES6 has changed how we write _**functions**_, adding _**default parameters**_ and introduced a new way of presenting _**classes and subclasses**_. All for being more easier syntax.
15 |
16 |
17 | ## Arrow Functions`=>`:
18 |
19 | 1. They are similar to regular functions in behavior, but are quite different _**syntactically**_.
20 | 2. Its full name is "**_Arrow Function Expressions_**". So they can be ONLY :heavy_check_mark: a **function expression** NOT :x: function declaration.
21 | 3. This includes being:
22 | - variable stored.
23 | - passed as an argument to a function.
24 | - stored in an object's property.
25 | 4. **Syntax:**
26 | - One parameter.
27 | ```
28 | //Regular Function
29 | const greet = function(name) { return `Hello ${name}!`};
30 |
31 | //Arrow Function
32 | const greet = name => `Hello ${name}!`;
33 | ```
34 | - No parameter.
35 | ```
36 | //Regular Function
37 | const greet = function() { return `Hello student!`};
38 |
39 | //Arrow Function
40 | const greet = () => `Hello student!`;
41 | //Or
42 | const greet = _ => `Hello student!`;
43 | ```
44 | - More Than one parameter.
45 | ```
46 | //Regular Function
47 | const greet = function(name1, name2) { return `Hello ${name1} and ${name2}!`};
48 |
49 | //Arrow Function
50 | const greet = (name1, name2) => `Hello ${name1} and ${name2}!`;
51 | ```
52 | 5. **Concise body syntax:**
53 | - The function body contain one line of code ( which is a returned value).
54 | - No need to add `return` key word.
55 | - No :x: curly braces `{}` needed.
56 | ```
57 | const greet = () => `Hello student!`;
58 | ```
59 | 6. **Block body syntax:**
60 | - The function body contain more than one line of code.
61 | - If you want to return a specific value you would have to add `return` key word by yourself.
62 | - Need curly braces `{}`.
63 | ```
64 | const func1 = (x, y) => {x++; return x + y;};
65 |
66 | //don't want to return a specific value
67 | const func2 = (x, y) => {x++; console.log(x + y);};
68 |
69 | //this last one return undefined when invoking function.
70 | const func3 = (x, y) => {x++; x + y;};
71 | ```
72 |
73 |
74 | ## Arrow Functions and `this` key word:
75 |
76 | 1. In regular function value of `this` depends on how the function is called. [More on this here](https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch1.md), and [even more on `this` here](https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch2.md).
77 | 2. In Arrow function value of `this` depends on the function's surrounding context. In more simple words, "**Value of _this_ inside an arrow function is the same like value of _this_ outside this function.**"
78 | 3. Example:
79 | ```
80 | // constructor
81 | function IceCream() {
82 | this.scoops = 0;
83 | }
84 |
85 | // adds scoop to ice cream
86 | IceCream.prototype.addScoop = function() {
87 | setTimeout(function() {
88 | this.scoops++;
89 | }, 500);
90 | };
91 |
92 | const dessert = new IceCream();
93 | dessert.addScoop();
94 | dessert.scoops; //0
95 | dessert.scoops; //0
96 | ```
97 | Value of `this` inside the regular function of setTimeout is the global object. This is because this function has not invoked using new, call, or apply.
98 | To solve this issue we could add _**closure**_ to `this` to close over the `this` value outside the setTimeout function to the outer addScoop method. So when invoking the constructor function with new in `const dessert = new IceCream();` the value of `this` would be the new `dessert` object.
99 | ```
100 | // constructor
101 | function IceCream() {
102 | this.scoops = 0;
103 | }
104 |
105 | // adds scoop to ice cream
106 | IceCream.prototype.addScoop = function() {
107 | const cone = this; // sets `this` to the `cone` variable
108 | setTimeout(function() {
109 | cone.scoops++; // references the `cone` variable
110 | }, 0.5);
111 | };
112 |
113 | const dessert = new IceCream();
114 | dessert.addScoop();
115 | dessert.scoops; //0
116 | dessert.scoops; //1
117 | ```
118 | What happened is the same to what `this` value would be in an arrow function without needing this closure variable.
119 |
120 | ```
121 | // constructor
122 | function IceCream() {
123 | this.scoops = 0;
124 | }
125 |
126 | // adds scoop to ice cream
127 | IceCream.prototype.addScoop = function() {
128 | setTimeout(() => { // an arrow function is passed to setTimeout
129 | this.scoops++;
130 | }, 0.5);
131 | };
132 |
133 | const dessert = new IceCream();
134 | dessert.addScoop();
135 | dessert.scoops; //0
136 | dessert.scoops; //1
137 | ```
138 |
139 | Note: If we change the addScoope function to an arrow one the value of this will be the global object again.
140 |
141 |
142 | ## Default Function Parameters:
143 |
144 | 1. Definition: Assigning a default values for function parameters in case no values are assigned when invoking the function.
145 | 2. Examples:
146 |
147 | In case of:
148 | ```
149 | function sayHi (name, greeting) {
150 | return `${greeting} ${name}`;}
151 |
152 | sayHi('Islam', 'Hi');//Hi Islam
153 | sayHi();//Uncaught ReferenceError: sayHi is not defined at ...
154 | ```
155 | You can write
156 | ```
157 | function sayHi (name, greeting) {
158 | name = (name !== undefined)? name : 'Islam';
159 | greeting = (greeting !== undefined)? greeting : 'Hi'
160 | return `${greeting} ${name}`;}
161 |
162 | sayHi();// Hi Islam
163 | sayHi('Hazem', 'Hello');//Hello Hazem
164 | ```
165 | How verbose this is! So you can instead write
166 | ```
167 | function sayHi (name = 'Islam', greeting = 'Hi') {
168 | return `${greeting} ${name}`;}
169 |
170 | sayHi();// Hi Islam
171 | sayHi('Hazem', 'Hello');//Hello Hazem
172 | sayHi('Hazem');//Hi Hazem
173 | sayHi(undefined, 'Hello');//Hello Islam
174 | ```
175 |
176 |
177 | ## Destructuring with Default Function Parameters:
178 |
179 | 1. **Destructuring Arrays with Default Function Parameters**
180 |
181 | - Example
182 | ```
183 | function createGrid([width = 5, height = 5] = []) {
184 | return `Generates a ${width} x ${height} grid`;
185 | }
186 | createGrid(); // Generates a 5 x 5 grid
187 | createGrid([]); // Generates a 5 x 5 grid
188 | createGrid([2]); // Generates a 2 x 5 grid
189 | createGrid([2, 3]); // Generates a 2 x 3 grid
190 | createGrid([undefined, 3]); // Generates a 5 x 3 grid
191 | ```
192 |
193 | 2. **Destructuring Objects with Default Function Parameters**
194 |
195 | - Example:
196 | ```
197 | function createSundae({scoops = 1, toppings = ['Hot Fudge']} = {}) {
198 | const scoopText = scoops === 1 ? 'scoop' : 'scoops';
199 | return `Your sundae has ${scoops} ${scoopText} with ${toppings.join(' and ')} toppings.`;
200 | }
201 |
202 | createSundae(); // Your sundae has 1 scoop with Hot Fudge toppings.
203 | createSundae({}); // Your sundae has 1 scoop with Hot Fudge toppings.
204 | createSundae({scoops: 2}); // Your sundae has 2 scoops with Hot Fudge toppings.
205 | createSundae({scoops: 2, toppings: ['Sprinkles']}); // Your sundae has 2 scoops with Sprinkles toppings.
206 | createSundae({toppings: ['Cookie Dough']}); // Your sundae has 1 scoop with Cookie Dough toppings.
207 | ```
208 |
209 | 3. **Array defaults vs. object defaults**
210 | - Always use Objects defaults over array ones whenever possible because object defaults handle skipped parameter in a better way.
211 | - While you will have to set the skipped parameters to `undefined` value in arrays arguments( except the last element in the array) you don't have to do the same for object. This is because arrays are order (position based) while objects are not.
212 |
213 |
214 |
215 | ## JS Classes:
216 |
217 | 1. Introduction:
218 | - JavaScript is not :x: a _class-based language_.
219 | - JavaScript uses _functions_ to create objects.
220 | - JavaScript links object together by prototypal _inheritance_.
221 | - JavaScript Classes are just a way to write a cleaner easier to read code.
222 |
223 | 2. ES5 Class -to-> ES6 Class conversion
224 |
225 | ES5
226 | ```
227 | //ES5
228 | function Plane(numEngines) {
229 | this.numEngines = numEngines;
230 | this.enginesActive = false;
231 | }
232 |
233 | // methods "inherited" by all instances
234 | Plane.prototype.startEngines = function () {
235 | console.log('starting engines...');
236 | this.enginesActive = true;
237 | };
238 |
239 | const richardsPlane = new Plane(1);
240 |
241 | const jamesPlane = new Plane(4);
242 | ```
243 | ES6
244 | ```
245 | //ES6
246 | class Plane {
247 | constructor(numEngines) {
248 | this.numEngines = numEngines;
249 | this.enginesActive = false;
250 | }
251 |
252 | startEngines() {
253 | console.log('starting engines…');
254 | this.enginesActive = true;
255 | }
256 | }
257 |
258 | const richardsPlane = new Plane(1);
259 |
260 | const jamesPlane = new Plane(4);
261 | ```
262 |
263 | 3. `static` method
264 |
265 | - written by adding key word `static` before method.
266 | - Can be used for "utility classes". When you want an object to be a bag of methods. And for performance reasons when you don't want to reference every object itself.
267 | - A real life example is `Math.floor()`, `Math.random()`, `Math.ceil()` where `floor()`, `random()`, and `ceil()` are all static methods on Math constructor function.
268 | - accessed on constructor function directly
269 | - Example:
270 | ```
271 | class Plane {
272 | constructor(numEngines) {
273 | this.numEngines = numEngines;
274 | this.enginesActive = false;
275 | }
276 | static badWeather(planes) {
277 | for (plane of planes) {
278 | plane.enginesActive = false;
279 | }
280 | }
281 | startEngines() {
282 | console.log('starting engines…');
283 | this.enginesActive = true;
284 | }
285 | }
286 | ```
287 |
288 |
289 | ## Subclasses with extends, and super:
290 |
291 | 1. `extends`
292 | - Definition: used in class declarations or class expressions to create a class which is a child (subclass) of another class (parent class).
293 |
294 | 2. `super`
295 | - Definition: used to access and call functions on an object's parent.
296 |
--------------------------------------------------------------------------------
/JS/ES6 Syntax.md:
--------------------------------------------------------------------------------
1 | # **ES6 COURSE**
2 |
3 | ## **Names :**
4 | - **ES6**
5 | - **ES2015**
6 | - **Harmony**
7 |
8 | -----------------------------------------------------------------------------------------
9 |
10 | ## **let and const :**
11 | - **Variables declared with let and const eliminate this specific issue of hoisting because they’re scoped to the block, not to the function.**
12 | - **Variables declared with var are either scoped globally or locally the function scope.**
13 | - **Rules for using let and const :**
14 | - Variables declared with **_let_**:
15 |
16 | - [ ] can be reassigned.
17 | - [ ] can't be redeclared in the same scope.
18 | - Variables declared with **_const_**:
19 |
20 | - [ ] must be assigned an initial value.
21 | - [ ] can't be reassigned.
22 | - [ ] can't be redeclared in the same scope.
23 |
24 | - **Use Cases (when to use what) :**
25 | - **_let_** when you plan to `reassign` new values to a variable.
26 | - **_const_** when you _don’t_ plan on reassigning new values to a variable.
27 |
28 | **As a general rule _always_ declare your variables using `const` except if you plan to reassign new values to variable.**
29 |
30 | **It is a _GOOD PRACTICE_ to not using `var` any more.**
31 |
32 | ----------------------------------------------------------------------------------------
33 |
34 | ## **Template Literals :**
35 |
36 | **string literals that include embedded expressions.**
37 |
38 | ### Syntax:
39 |
40 | - Single line string (with embeded expressions or _expression interpolation_)
41 | ```
42 | const student = {
43 | name: 'Richard Kalehoff',
44 | guardian: 'Mr. Kalehoff'
45 | };
46 |
47 | const teacher = {
48 | name: 'Mrs. Wilson',
49 | room: 'N231'
50 | }
51 |
52 | let message = `${student.name} please see ${teacher.name} in ${teacher.room} to pick up your report card.`; //Richard Kalehoff please //see Mrs. Wilson in N231 to pick up your report card.
53 | ```
54 | ```
55 | var a = 5;
56 | var b = 10;
57 | console.log(`Fifteen is ${a + b} and not ${2 * a + b}.`);
58 | // "Fifteen is 15 and not 20."
59 | ```
60 | - Multi-line string.
61 |
62 | instead of:
63 | ```
64 | console.log('string text line 1\n' +
65 | 'string text line 2');
66 | // "string text line 1
67 | // string text line 2"
68 | ```
69 | you can write this:
70 | ```
71 | console.log(`string text line 1
72 | string text line 2`);
73 | // "string text line 1
74 | // string text line 2"
75 | ```
76 |
77 |
78 | -----------------------------------------------------------------------------
79 |
80 | ## **Destructuring**
81 |
82 | **Extract data from arrays and objects into different variables.**
83 | **allow you to specify the elements you want to extract from an array or object on the left side of an assignment.**
84 |
85 | ### **Arrays**
86 |
87 | - **Instead of :**
88 |
89 | ```
90 | const point = [10, 25, -34];
91 |
92 | const x = point[0];
93 | const y = point[1];
94 | const z = point[2];
95 |
96 | console.log(x, y, z); //10 25 -34
97 | ```
98 |
99 | - **You can do this:**
100 |
101 | ```
102 | const point = [10, 25, -34];
103 | const [x, y, z] = point;
104 |
105 | console.log(x, y, z); //10 25 -34
106 | ```
107 |
108 | ### **Objects**
109 |
110 | - **Instead of:**
111 |
112 | ```
113 | const gemstone = {
114 | type: 'quartz',
115 | color: 'rose',
116 | carat: 21.29
117 | };
118 |
119 | const type = gemstone.type;
120 | const color = gemstone.color;
121 | const carat = gemstone.carat;
122 |
123 | console.log(type, color, carat); ////quartz rose 21.29
124 | ```
125 |
126 | - **You can do this:**
127 |
128 | ```
129 | const gemstone = {
130 | type: 'quartz',
131 | color: 'rose',
132 | carat: 21.29
133 | };
134 | const {type, color, carat} = gemstone;
135 | console.log(type, color, carat); //quartz rose 21.29
136 | ```
137 | **achieve the same result as before, but with much _less code_; and it's still easy to _understand_.**
138 |
139 |
140 | --------------------------------
141 |
142 | ## **Object literal shorthand**
143 |
144 | ### **initializing objects**
145 |
146 | If the properties names are the same like values names assigned to them, then ni=o need to re-write the same name as the value of property.
147 |
148 | - **Instead of that:**
149 |
150 | ```
151 | let type = 'quartz';
152 | let color = 'rose';
153 | let carat = 21.29;
154 |
155 | const gemstone = {
156 | type: type,
157 | color: color,
158 | carat: carat
159 | };
160 |
161 | console.log(gemstone);
162 | ```
163 |
164 | - **You can write that:**
165 |
166 | ```
167 | let type = 'quartz';
168 | let color = 'rose';
169 | let carat = 21.29;
170 |
171 | const gemstone = {
172 | type,
173 | color,
174 | carat
175 | };
176 |
177 | console.log(gemstone);
178 | ```
179 |
180 | ### **methods names shorthand**
181 |
182 | **Since _anonymous function_ is being assigned to a property.**
183 |
184 | - **Instead of that:**
185 |
186 |
187 | ```
188 | let type = 'quartz';
189 | let color = 'rose';
190 | let carat = 21.29;
191 |
192 | const gemstone = {
193 | type,
194 | color,
195 | carat,
196 | calculateWorth: function() {
197 | //code here
198 | }
199 | };
200 | ```
201 |
202 | - **You can write that:**
203 |
204 |
205 | ```
206 | let gemstone = {
207 | type,
208 | color,
209 | carat,
210 | calculateWorth() { //code here }
211 | };
212 | ```
213 |
214 |
215 | --------------------------------------------------------------------
216 |
217 | ## :point_right: **for Loops**
218 |
219 | - **for loop**
220 | - **for in loop**
221 | - **for of loop**
222 |
223 | ### **for loop**
224 | - _**Weakness**_:
225 | Having to keep track of: **Counter** , and **Exit Condition**.
226 |
227 | ### **for in loop**
228 |
229 | ```
230 | const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
231 |
232 | for (const index in digits) {
233 | console.log(digits[index]);
234 | }
235 | ```
236 | - _**Adv**_:
237 | Eliminates **Counter** , and **Exit Condition**.
238 |
239 | - _**Weakness**_:
240 | Use of index to access values of the array.
241 | If you add any properties or methods to the array prototype they will appear in the loop.
242 |
243 | ```
244 | Array.prototype.decimalfy = function() {
245 | for (let i = 0; i < this.length; i++) {
246 | this[i] = this[i].toFixed(2);
247 | }
248 | };
249 |
250 | const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
251 |
252 | for (const index in digits) {
253 | console.log(digits[index]);
254 | }
255 | ```
256 | ```
257 | Prints:
258 | 0
259 | 1
260 | 2
261 | 3
262 | 4
263 | 5
264 | 6
265 | 7
266 | 8
267 | 9
268 | function() {
269 | for (let i = 0; i < this.length; i++) {
270 | this[i] = this[i].toFixed(2);
271 | }
272 | }
273 | ```
274 |
275 | ### **for of loop**
276 |
277 | - _**Adv**_:
278 | Eliminates **Counter** , and **Exit Condition**.
279 | _Don't_ use **index** but it loops over each value without use of index.
280 | _only_ loop over the **values** in the object. So you don't worry about any new properties like in for in loop.
281 | Can be **stopped** at any time.
282 |
283 | ```
284 | const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
285 |
286 | for (const digit of digits) {
287 | if (digit % 2 === 0) {
288 | continue;
289 | }
290 | console.log(digit);
291 | }
292 | ```
293 |
294 | ```
295 | prints:
296 | 1
297 | 3
298 | 5
299 | 7
300 | 9
301 | ```
302 |
303 | ```
304 | Array.prototype.decimalfy = function() {
305 | for (i = 0; i < this.length; i++) {
306 | this[i] = this[i].toFixed(2);
307 | }
308 | };
309 |
310 | const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
311 |
312 | for (const digit of digits) {
313 | console.log(digit);
314 | }
315 | ```
316 |
317 | ```
318 | Prints:
319 | 0
320 | 1
321 | 2
322 | 3
323 | 4
324 | 5
325 | 6
326 | 7
327 | 8
328 | 9
329 | ```
330 | :musical_note: **A good practice:** **_plural names_ for objects conatin values** and **_singular names_ for referencing individual values.**
331 |
332 | ```for (const button of buttons) {...}```
333 |
334 | ----------------------------------------------------------------------------
335 |
336 | ## :point_right: **Spread Operator**
337 |
338 | - **expand, or spread, iterable objects into multiple elements.**
339 |
340 | ```
341 | const primes = new Set([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]);
342 | console.log(...primes);\\ 2 3 5 7 11 13 17 19 23 29
343 | ```
344 |
345 | - **One of its uses is to concatenate 2 or more iterable objects.**
346 |
347 | - Example:
348 | - instead of using ```concat()``` an Array's method
349 |
350 | ```
351 | const fruits = ["apples", "bananas", "pears"];
352 | const vegetables = ["corn", "potatoes", "carrots"];
353 | const produce = fruits.concat(vegetables);
354 | console.log(produce);
355 | ```
356 |
357 | - You can use spread operator
358 |
359 |
360 | ```
361 | const fruits = ["apples", "bananas", "pears"];
362 | const vegetables = ["corn", "potatoes", "carrots"];
363 |
364 | const produce = [...fruits, ...vegetables];
365 |
366 | console.log(produce);
367 | ```
368 |
369 |
370 | -------------------------------------------------------
371 |
372 | ## :point_right: **Rest Parameter**
373 |
374 | - **represent an indefinite number of elements as an array.**
375 | - **Uses:**
376 |
377 | 1. **Assign certain values of an array to another array.**
378 |
379 | ```
380 | const order = [20.17, 18.67, 1.50, "cheese", "eggs", "milk", "bread"];
381 | const [total, subtotal, tax, ...items] = order;
382 | console.log(total, subtotal, tax, items);// 20.17 18.67 1.5 ["cheese", "eggs", "milk", "bread"]
383 | ```
384 | 2. **In Variadic Functions**
385 |
386 | - **Variadic functions: functions that take an indefinite number of arguments.**
387 | - **You can use argument object for that but it is misleading anf confusing.**
388 | - **Instead use Rest parameter.**
389 |
390 | ```
391 | \\Using argument object
392 | function sum() {
393 | let total = 0;
394 | for(const argument of arguments) {
395 | total += argument;
396 | }
397 | return total;
398 | }
399 | ```
400 |
401 | ```
402 | //Using rest parameter
403 | function sum(...nums) {
404 | let total = 0;
405 | for(const num of nums) {
406 | total += num;
407 | }
408 | return total;
409 | }
410 | ```
411 |
412 | :musical_note: **_argument object_**: Array-like object corresponding to the arguments passed to a function.
413 | available as a local variable inside all functions.
414 | contains a value for each argument being passed to the function starting at 0 for the first argument, 1 for the second argument, and so on.
415 |
416 | Example:
417 |
418 | ```
419 | function func1(a, b, c) {
420 | console.log(arguments[0]);
421 | // expected output: 2
422 |
423 | console.log(arguments[1]);
424 | // expected output: 5
425 |
426 | console.log(arguments[2]);
427 | // expected output: 0
428 | }
429 |
430 | func1(2, 5, 0);
431 | ```
432 |
433 |
434 |
435 |
--------------------------------------------------------------------------------
/JS/Good Commenting Practices.md:
--------------------------------------------------------------------------------
1 | # Good Commenting Practices
2 |
3 | ### Contents:
4 |
5 | - [Source](#source).
6 | - [The 5 tips](#the-5-tips).
7 | 1. [Comments are not subtitles](#1-comments-are-not-subtitles).
8 | 2. [Comments are not an art project](#2-comments-are-not-an-art-project).
9 | 3. [Header Blocks](#3-header-blocks).
10 | 4. [Comments are not source control](#4-comments-are-not-source-control).
11 | 5. [Comments are a code smell](#5-comments-are-a-code-smell).
12 |
13 |
14 | ## Source:
15 |
16 | - https://improvingsoftware.com/2011/06/27/5-best-practices-for-commenting-your-code/
17 |
18 |
19 | ## The 5 tips:
20 |
21 | ### 1. Comments are not subtitles
22 |
23 | - You are writting comments for both the future you, and others programmers who would be building over your code or maintain it.
24 | - So no need to write every simple detail. As not far from now you will read code as your native language.
25 | - Example:
26 | ```javascript
27 | // Loop through all bananas in the bunch
28 | foreach(banana b in bunch) {
29 | monkey.eat(b); //make the monkey eat one banana
30 | }
31 | ```
32 | - For people who are used to write pseudo code first before the real code, don't forget to replace pseudo with real code and not just add it to the former.
33 | - Exceptions:
34 | 1. Code examples used to teach a concept or new programming language.
35 | 2. Programming languages that aren’t human readable (Assembly, Perl).
36 |
37 |
38 | ### 2. Comments are not an art project
39 | ```
40 | /*
41 | _ _ _ _ _ _ _ _ _ _ _ _
42 | (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c)
43 | / ._. \ / ._. \ / ._. \ / ._. \ / ._. \ / ._. \
44 | __\( Y )/__ __\( Y )/__ __\( Y )/__ __\( Y )/__ __\( Y )/__ __\( Y )/__
45 | (_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)(_.-/'-'\-._)
46 | || M || || O || || N || || K || || E || || Y ||
47 | _.' `-' '._ _.' `-' '._ _.' `-' '._ _.' `-' '._ _.' `-' '._ _.' `-' '._
48 | (.-./`-'\.-.)(.-./`-'\.-.)(.-./`-'\.-.)(.-./`-'\.-.)(.-./`-'\.-.)(.-./`-'\.-.)
49 | `-' `-' `-' `-' `-' `-' `-' `-' `-' `-' `-' `-'
50 |
51 | -It's Monkey Business Time! (Version 1.5)
52 | */
53 | ```
54 | ```
55 | +------------------------------------------------------------+
56 | | Module Name: classMonkey |
57 | | Module Purpose: emulate a monkey |
58 | | Inputs: Bananas |
59 | | Outputs: Grunts |
60 | | Throws: Poop |
61 | +------------------------------------------------------------+
62 | ```
63 |
64 | - The first example is very silly to do in your comments and you are not do silly things, are you?
65 | - The second example will get developers tired while they are maintaing your code just to try to fix the unsymmetric border. Because they like consistency and every other method in the project has one.
66 |
67 |
68 | ### 3. Header Blocks
69 |
70 | - They are enablers for badly named objects/methods. Just to think that he reader will understand what the object/method do after reading the header, excuse you not to put extra work to find a good descriptive names.
71 |
72 | - They never get updated. And also rarely get read. So why wasting your time with something won't help.
73 |
74 |
75 | ### 4. Comments are not source control
76 |
77 | _I am trying to understand this part. If anyone could contribute, it is welcomed._
78 |
79 |
80 | ### 5. Comments are a code smell
81 |
82 | - "Things generally need signs because their affordances have failed." This means that "**when you add a comment you are admitting that you have written code that doesn’t communicate its purpose well.**".
83 | - Whenever you think, “This code needs a comment” follow that thought with, “How could I modify the code so its purpose is obvious?”
84 | Talk with your code, not your comments.
85 | - One of the ways to do so is to Use meaningful identifiers (even if they are single use).
86 | ```
87 | // Before
88 | // Calculate monkey's arm length
89 | // using its height and the magic monkey arm ratio
90 | double length = h * 1.845; //magic numbers are EVIL!
91 |
92 | // After - No comment required
93 | double armLength = height * MONKEY_ARM_HEIGHT_RATIO;
94 | ```
95 |
--------------------------------------------------------------------------------
/JS/IIFE.md:
--------------------------------------------------------------------------------
1 | # Immediately Invoked Function Expression
2 |
3 | - A good [article to introduce IIFE](http://adripofjavascript.com/blog/drips/an-introduction-to-iffes-immediately-invoked-function-expressions.html).
4 |
--------------------------------------------------------------------------------
/JS/JS OOP.md:
--------------------------------------------------------------------------------
1 | # JS OOP
2 |
3 | JS Object-Oriented Programing at Udacity. A part of Udacity Front end Nanodegree courses.
4 |
5 | Course lessons:
6 |
7 | 1. [Objects In Depth](#objects-in-depth).
8 | 2. [Functions at runtime](#functions-at-runtime).
9 | 3. [Classes and Objects](#classes-and-objects).
10 |
11 | ## 1. Objects in Depth
12 |
13 | ### Introduction
14 |
15 | - Object Definition: a collection of associated unordered (opposite to arrays) key/value pairs. It is defined with curly brackets `{}`. Key/value pairs are called properties. And they (key/value) are connected using colon `:` and properties separated from each other using comma `,` .
16 |
17 | - Syntax:
18 | const course = { courseId: 711 };
19 | const course = { 'courseId': 711 };
20 | const course = { "courseId": 711 };
21 |
22 | As you see the key string can be with or without quotes. Mostly without quotes but are essential in certain cases:
23 | - reserved word (e.g., for, if, let, true, etc.).
24 | - Contains spaces or special characters that cannot appear in a variable name.
25 |
26 | - Accessing object properties values:
27 |
28 | - Using `dot notation` : `course.courseId;`
29 | Limitations:
30 | 1. When the key is a number.
31 | 2. When the key is stored in a variable and we want to access this property by the variable.
32 | - Using `bracket notation` : `course['courseId'];`
33 |
34 | - Accessing nested object properties values:
35 |
36 | ```
37 | const bicycle = {
38 | color: 'blue',
39 | type: 'mountain bike',
40 | wheels: {
41 | diameter: 18,
42 | width: 8
43 | }
44 | };
45 |
46 | bicycle.wheels.width;
47 | ```
48 |
49 |
50 | ### Creating and modifying objects
51 |
52 | - [A link to the course page](https://classroom.udacity.com/nanodegrees/nd001/parts/4942f4d7-a48d-4794-9eb0-404b3ed3cfe1/modules/7e56389b-50d8-4e3a-84a0-eb3fd45456b2/lessons/504843ae-ba16-4573-a859-94da7a7d1dd4/concepts/2bbcfed5-e683-431b-ace2-b67c091400d2).
53 | - Create:
54 | ```
55 | // Using literal notation:
56 | const myObject = {};
57 |
58 | // Using the Object() constructor function (slower):
59 | const myObject = new Object();
60 |
61 | //Using constructor function:
62 | function MyObjectConstructor() {
63 | }
64 | const myObject = new MyObjectConstructor();
65 | ```
66 |
67 | - Modifying object properties
68 | ```
69 | const cat = {
70 | age: 2,
71 | name: 'Bailey'
72 | }
73 | cat.age += 1;
74 |
75 | cat.age;
76 | // 3
77 |
78 | cat.name = 'Bambi';
79 |
80 | cat.name;
81 | // 'Bambi'
82 | ```
83 |
84 | - Adding Object properties
85 | ```
86 | const printer = {};
87 |
88 | printer.on = true;
89 | printer.mode = 'black and white';
90 | printer.print = function () {
91 | console.log('The printer is printing!');
92 | };
93 | ```
94 |
95 | - Removing Object properties
96 | ```
97 | delete printer.mode;
98 | // true
99 | ```
100 |
101 | - Since Objects are passed by reference, making changes to an original object make the same change to its copy
102 | ```
103 | const iceCreamOriginal = {
104 | Andrew: 3,
105 | Richard: 15
106 | };
107 |
108 | const iceCreamCopy = iceCreamOriginal;
109 |
110 | iceCreamCopy.Richard;
111 | // 15
112 |
113 | iceCreamCopy.Richard = 99;
114 |
115 | iceCreamCopy.Richard;
116 | // 99
117 |
118 | iceCreamOriginal.Richard;
119 | // 99
120 | ```
121 |
122 | - Comparing an Object with Another Object
123 |
124 | ```
125 | const object1 = {
126 | name: bird}
127 | const object2 = {
128 | name: bird}
129 | object1 === object2;//false
130 |
131 | const object = object1;
132 | object;//{name: bird}
133 |
134 | object === object1;//true. Also any change in object1 will make the same change in object.
135 | object === object2;//false.
136 | ```
137 | ### Invoke object method
138 |
139 | - invoke methods different ways
140 |
141 | ```
142 | const developer = {
143 | sayHello: function () {
144 | console.log('Hi there!');
145 | }
146 | };
147 | developer.sayHello();//Hi there!
148 | developer['sayHello']();//Hi there!
149 | ```
150 |
151 | - passing arguments into methods
152 |
153 | ```
154 | const developer = {
155 | name: 'Andrew',
156 | favoriteLanguage: function (language) {
157 | console.log(`My name is ${this.name} and my favorite programming language is ${language}.`);
158 | }
159 | };
160 |
161 | developer.favoriteLanguage('JavaScript');//My name is Andrew and my favorite programming language is JavaScript.
162 | ```
163 | - Naming properties functions ( rather than using anonymous functions) is valid and is useful for debugging.
164 |
165 |
--------------------------------------------------------------------------------
/JS/JS Promises.md:
--------------------------------------------------------------------------------
1 | # Promises Course Stages:
2 |
3 | 1. Wrapping.
4 | 2. Thening.
5 | 3. Catching.
6 | 4. Chaining.
7 |
8 | # Promises States:
9 |
10 | 1. Fulfilled (Resolved). => The action related to the promise succeeded.
11 | 2. Rejected. => The action related to the promise failed.
12 | 3. Pending. => Promise has not yet fulfilled or rejected.
13 | 4. Settled. => Promise has either fulfilled or rejected.
14 |
--------------------------------------------------------------------------------
/JS/Memory management.md:
--------------------------------------------------------------------------------
1 | # Memory management
2 |
3 | - Description:
4 | _This is just an explanation of a garbage collection algorithm presented in_ [MDN-Garbage Collection](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management#Garbage_collection).
5 |
6 |
7 | ### Table of contents:
8 |
9 | 1. [Introduction](#introduction).
10 | 2. [Memory Life Cycle](#memory-life-cycle).
11 | 3. [Garbage Collection](#garbage-collection).
12 | 4. [Reference Counting Garbage Collection algorithm](#reference-counting-garbage-collection-algorithm).
13 | 5. [Mark and sweep algorithm](#mark-and-sweep-algorithm).
14 |
15 | ## Introduction
16 |
17 | - Low-level language (eg. C language) have low level memory management primitives like `free()`. ( this is not important to us now but we mention that to say that memory management must be done **explicitly**).
18 | - Unlike JavaScript, when for example objects are not used any more they are automatically "garbage collected" to free memory.
19 | - This gives a _**wrong**_ impression to JS developers to not care about memory management.
20 |
21 |
22 | ## Memory Life Cycle
23 |
24 | - Regardless of the programming language, memory life cycle is pretty much always the same:
25 | 1. Allocate the memory you need. (_explicit in low-level languages implicit in high-level languages like JS_)
26 | 2. Use the allocated memory. (read, write) (_explicit in all languages_)
27 | 3. Release the allocated memory when it is not needed anymore. (_explicit in low-level languages implicit in high-level languages like JS (GARBAGE COLLECTION)_)
28 |
29 | ```
30 | Allocate the memory in JS
31 | ```
32 | ===> JavaScript does it alongside with declaring values.
33 |
34 | ```
35 | Use the allocated memory
36 | ```
37 | ===> By reading or writing the value of a variable or an object property or even passing an argument to a function.
38 |
39 | ```
40 | Release the allocated memory
41 | ```
42 | ===>
43 | - High-level languages embed a piece of software called "**garbage collector**" whose job is to track memory allocation and use in order to find when a piece of allocated memory is not needed any longer in which case, it will automatically _free it_.
44 | - This process is an approximation (knowing whether some piece of memory is needed is undecidable. This means it can not be solved by an algorithm).
45 |
46 | ## Garbage Collection
47 |
48 | - The algorithms of garbage collection depends on "reference"
49 |
50 |
51 | ## Reference Counting Garbage Collection Algorithm
52 |
53 | - Description:
54 | _This is just an explanation of a garbage collection algorithm presented in_ [MDN-Garbage Collection](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management#Garbage_collection).
55 | - Definition: One of algorithms of JS Grabage Collection Algorithms.
56 | - The most naive Garbage Collection algorithm.
57 | - It reduces the definition of "an object is not needed anymore so Garbage collect it" to "an object has no other object referencing to it so Garbage collect it".
58 | - MDN Example with a more clear explanation:
59 |
60 | ```javascript
61 | var o = {
62 | a: {
63 | b: 2
64 | }
65 | };
66 | ```
67 | 2 objects are created:
68 |
69 | ```javascript
70 | {
71 | a: {
72 | b: 2
73 | }
74 | }
75 | ```
76 | And
77 | ```javascript
78 | {
79 | b: 2
80 | }
81 | ```
82 | The first one is referenced by being assigned to variable `o`. The second is referenced by the first one as a property of it.
83 |
84 | ```javascript
85 | var o2 = o;
86 | ```
87 | Now the first object has a second reference `o2`
88 | ```javascript
89 | o = 1;
90 | ```
91 | But now one of its references `o` variable are being re assigned to a different value. So the first object now has one reference `o2`.
92 | ```javascript
93 | var oa = o2.a;
94 | ```
95 | The second object now has a reference `oa` by assigning the `o2` object `a` property to `oa`
96 | ```javascript
97 | o2 = 'yo';
98 | ```
99 | Now the first object loses its last reference `o2`. So it can be garbage collected.
100 | ```javascript
101 | oa = null;
102 | ```
103 | Now the second object loses its reference `oa`. So it can also be garbage collected.
104 |
105 |
106 | - Another example: _trapped reference_ Or _circularReference_
107 | ```javascript
108 | var div;
109 | window.onload = function() {
110 | div = document.getElementById('myDivElement');
111 | div.circularReference = div;// the div references itself. It will continue in memory even if it is removed from DOM tree.
112 | div.lotsOfData = new Array(10000).join('*');//the div carries a lot of data. Memory consumed by this data will never be released.
113 | };
114 | ```
115 |
116 |
117 | ## Mark and sweep algorithm
118 |
119 | - It reduces the definition of "an object is not needed anymore so Garbage collect it" to "an object is not reachable so Garbage collect it".
120 | - This algorithm starts from the root object ( global object) and find all objects that are referenced from these roots, then all objects referenced from these, etc. Then the unreachable objects will be garbage collected.
121 | - This algorithm is better than the previous one since "an object has zero references" leads to this object being unreachable. The opposite is not true as in this example:
122 | ```javascript
123 | function f() {
124 | var o = {};
125 | var o2 = {};
126 | o.a = o2; // o references o2
127 | o2.a = o; // o2 references o
128 | return 'hi';
129 | }
130 |
131 | f();
132 | ```
133 |
--------------------------------------------------------------------------------
/JS/Object Iteration.md:
--------------------------------------------------------------------------------
1 | # Object Iteration
2 |
3 | ### Table of Contents:
4 |
5 | 1. [Description](#description).
6 | 2. [Iterable Protocol](#iterable-protocol).
7 |
8 | ### Description:
9 |
10 | - This will show us "**How to iterate over an object**".
11 |
12 | ### Iterable Protocol
13 |
14 | - **Definition**: define and customize the iteration behavior of objects (which are not iterables). This means that now we have the flexibility of defining and customizing this iteration behavior for objects.
15 | - Using `[Symbol.iterator]()`
16 |
17 |
18 | ### Iterator Protocol
19 |
20 | - **Definition**: define a standard way that an object produces a sequence of values (how an object will iterate).
21 | - Using `next()`
22 |
23 | ----------------------------
24 |
25 |
26 | - So for an object to be iterable ---must implement---> iterator method(define how object will be iterated).
27 | - Our iterator method here is `[Symbol.iterator]()`
28 | - `[Symbol.iterator]()` is a zero argument method ---returns---> iterator object (which is an object that conforms to iterator protocol).
29 | - On iterator object, you can call method `next()`
30 | - `next()` method is a zero argument method that returns an object with 2 properties:
31 | 1. `value`: value returned by the iterator. `undefined` when the iterator past the end of the iterated sequence (past the last value of the object).
32 | 2. `done`: (boolean) which can be true or false. `true` if the iterator past the end of the iterated sequence (past the last value of the object). `false` if the iterator was able to produce the next value in the sequence (still there is a value or values to produce).
33 |
34 |
35 | ```javascript
36 | const digits = [0, 1, 2];
37 | const arrayIterator = digits[Symbol.iterator]();
38 |
39 | console.log(arrayIterator.next());//Object {value: 0, done: false}
40 | console.log(arrayIterator.next());//Object {value: 1, done: false}
41 | console.log(arrayIterator.next());//Object {value: 2, done: false}
42 | console.log(arrayIterator.next());//Object {value: undefined, done: true}
43 | ```
44 |
45 |
46 |
--------------------------------------------------------------------------------
/JS/polyfills.md:
--------------------------------------------------------------------------------
1 | # Pollyfills
2 |
3 |
4 | ## 1. for startsWith() method:
5 |
6 | ```javascript
7 | if (!String.prototype.startsWith) {
8 | String.prototype.startsWith = function (searchString, position) {
9 | position = position || 0;
10 | return this.substr(position, searchString.length) === searchString;
11 | };
12 | }
13 | ```
14 | - Explanation:
15 |
16 | - We will start by showing how the method startsWidth() work.
17 | ```javascript
18 | "islam".startsWith("la", 2);//true
19 | ```
20 | `string.startsWith(searchString[, position]);`
21 |
22 | _searchString_ argument:
23 |
24 | The character(s) to be searched for at the start of this string or at the start point defined by `position` argument.
25 |
26 | _position_ argument:
27 |
28 | The position in this string at which to begin searching for searchString. It is optional and defaults to 0.
29 |
30 | -The conditional is checking if the method is on String object prototype (supported by the browser). If it is not on String object prototype (String.prototype.startsWith == undefined) ===> falsy so (!String.prototype.startsWith) will be true and excutes what code after it.
31 |
32 | -This code will declare a startWidth method to String prototype which value is an anonymous function with 2 arguments ( same like the original startsWidth method). position will be either the value we pass in calling the method of if not passes will be equal to 0 ( same like the original method. Default is 0) `position = position || 0;`
33 | - Then the function returns substr() Method.
34 | - `str.substr(start[, length])`
35 | returns the part of a string between the start index and a number of characters after it.
36 | - So the function will return true or false depending on wether the string value from `subStr(position, searchString.length) === searchString` or not
37 | - So for example in
38 | ```javascript
39 | "islam".startsWith("la", 2);
40 | ```
41 | this will return `subStr(2, 2) === la` start at position 2 which is character "l" to 2 characters which is "la" and this is eaqual to "la". So it returns true.
42 |
43 |
--------------------------------------------------------------------------------
/JS/symbols.md:
--------------------------------------------------------------------------------
1 | # symbols:
2 | - A new JS primitive data type.(number, string, boolean, null, undefined, symbol)
3 | - is "unique, and immutable data type that is used to identify object properties".
4 | - created by invoking Symbol() function.
5 | - Symbol('description') function can have an optional string description that is used for _debugging_.
6 | - Description is a way to describe the created symbol. It can not access the symbol or affect its value. That's why the symbols with the same description are not equal.
7 | - syntax:
8 | ```javascript
9 |
10 | const bowl = {
11 | [Symbol('apple')]: { color: 'red', weight: 136.078 },
12 | [Symbol('banana')]: { color: 'yellow', weight: 183.15 },
13 | [Symbol('orange')]: { color: 'orange', weight: 170.097 },
14 | [Symbol('banana')]: { color: 'yellow', weight: 176.845 }
15 | };
16 | console.log(bowl);//{Symbol(apple): {…}, Symbol(banana): {…}, Symbol(orange): {…}, Symbol(banana): {…}}
17 |
18 |
--------------------------------------------------------------------------------
/JS/this.md:
--------------------------------------------------------------------------------
1 | # `this`
2 |
3 | - An interesting reading about `this` is [here](https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch1.md).
4 |
--------------------------------------------------------------------------------
/JavaScript DOM.md:
--------------------------------------------------------------------------------
1 | # **JavaScript DOM**
2 |
3 |
4 | - ### When you request a website, it will respond with HTML. These bytes recieved are run through complicated and documented parsing process
5 | ===> determine different characters (eg., start tag character, an atrrbute and so on) ===> tokenizer ===> tokens (DOCTYPE, start tag, end tag, comment, and so on) ===> DOM (a tree structure that captures the content and properties of the HTML and all the relationships between the nodes)
6 |
--------------------------------------------------------------------------------
/Plagiarism .md:
--------------------------------------------------------------------------------
1 | ### Notes:
2 |
3 |
4 | # Writing Cleanroom
5 | - **The Basic Tenant of a Writing Cleanroom**
6 |
7 | ### **"_No unoriginal text should be pasted or otherwise enter into a work in progress without immediate citation being applied._"**
8 |
9 | 1. The act of copying and pasting (or simply retyping) text into your work should be treated with extreme reverence. If the text is not yours, it needs to be cited immediately after pasting.
10 |
11 | 2. Even if you intend to go back and rewrite a copied section or remove it altogether, time or memory might prevent that from happening.
12 |
13 | 3. This approach is **“write and cite”**, others take a “write first, cite later” approach. The problem with the latter is that it’s easy to _forget_ what needs to be done.
14 |
15 | ----------
16 |
17 | - **How to use a Writing Cleanroom**
18 |
19 | 1. Never mix unoriginal and original text in the same document.
20 |
21 | 2. When pasting text into your work, decide first if it’s text that needs to be copied. Would this information be better or equally-well presented as a paraphrase? If so, put it away and paraphrase the information instead. After you’re done, be sure to cite the source of the information immediately.
22 |
23 | 3. If you decide copying the text is appropriate, do so but immediately put it in either quotes or block-quotes as appropriate and add other needed citations.
24 |
25 | 4. Be careful to not remove any citation marks through reformatting or editing of the document. This can be especially problematic if you use block-quotes but convert the document to a format that doesn’t support it.
26 |
27 | -----------
28 |
29 | - **Paraphrasing**
30 |
31 | 1. **Paraphrasing** is not about changing the words someone else wrote, but rather, writing the information in your own words.
32 |
33 | 2. The easiest way to achieve this is to read the information you want to paraphrase and then _put it away_. Don’t copy it and don’t look at it. From there, just write the information in _your words_.
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Projects road map/P4: Classic Arcade Game.md:
--------------------------------------------------------------------------------
1 | ### First Steps:
2 | 1. Take [HTML5 Canvas course](https://classroom.udacity.com/courses/ud292).:heavy_check_mark:
3 | 2. Revise OOP course.:heavy_check_mark:
4 | 3. Read project instructions carefully ==> Take notes.:heavy_check_mark:
5 | 4. Read project rubric carefully ==> Take notes.:heavy_check_mark:
6 | 5. Read JS files comments carefully ==> Take notes.:heavy_check_mark:
7 | 6. Collect and organize all your notes in one file.:heavy_check_mark:
8 | 7. Before starting project debug it in concole. ==> Complete the missing.:heavy_check_mark:
9 | 8. Start the project.:heavy_check_mark:
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Study-Notes
2 | ## **Books, courses, articles, and tutorials study notes.**
3 |
4 | - **This repo will contain different text files for different source's study notes.**
5 |
6 | - **Every file represents a book, course, article, or tutorial.**
7 |
8 | - **Every file will carry the name of the source.**
9 |
10 | ## **License**
11 | This project is licensed under the terms of the MIT license.
12 |
--------------------------------------------------------------------------------
/React/intro.md:
--------------------------------------------------------------------------------
1 | # Intro.
2 |
3 | 1. What makes React SPECIAL?:
4 | - its compositional model. (composition: combining simple functions together to create complex functions.)/ ( A good function should follow the "DOT" rule)
5 | - its declarative nature.(Not imperative) (you tell JS what you want to do and it takes care of the steps to do it itself).
6 | - the way data flows through a component.(unidirectional data flow => from parent to children and also data update occurs only in parent component).(Not 2 way data binding).
7 | - it is just JavaScript.
8 |
9 | --------
10 |
11 | - In React the process of deciding what to render is decoupled from actually rendering it.
12 | - This decoupling makes it possible to render stuff on:
13 | - native devices.
14 | - server.
15 | - VR environments.
16 |
17 | - We use ReactDom because we are working on the browser.
18 |
--------------------------------------------------------------------------------
/ServiceWorker/notes.md:
--------------------------------------------------------------------------------
1 | ```javascript
2 | self.skipWaiting()
3 | ```
4 |
5 | ```javascript
6 | reg.installing.postMessage({...});
7 | ```
8 |
9 | ```javascript
10 | self.addEventListener('message', function(event) {
11 | event.data;
12 | });
13 | ```
14 |
15 | ```javascript
16 | navigator.serviceWorker.addEventListener('controllerchange', function() {
17 | //fires when service worker changes.
18 | });
19 | ```
20 |
--------------------------------------------------------------------------------
/ServiceWorker/steps.md:
--------------------------------------------------------------------------------
1 | # Steps:
2 |
3 | ## Register a service worker:
4 |
5 | - In the main.js:
6 |
7 | ```javascript
8 | if (navigator.serviceWorker) {
9 | navigator.serviceWorker.register('/sw.js').then(function() {
10 | console.log('SW registered');
11 | });
12 | }
13 | ```
14 |
15 | - In this case you should have `sw.js` in the main directory. Here the scope of the service worker is the default scope (any thing in the same level or deeper than `sw.js` file level.
16 |
17 | - To hijack a request with a custom response:
18 |
19 | ```javascript
20 | //In sw.js file
21 |
22 | self.addEventListener('fetch', function(event) {
23 | event.respondWith(
24 | new Response('Any custom response ', {
25 | headers: {'Content-Type': 'text/html'}
26 | })
27 | );
28 | });
29 | ```
30 |
31 | - To hijack a request with a custom response depending on the request itself.
32 |
33 | ```javascript
34 | // Here is a way to hijack a request depending on the file type of the request.
35 | // We will respond with a certain gif to every request with a jpg file type.
36 |
37 | self.addEventListener('fetch', function(event) {
38 | if (event.request.url.endsWith('.jpg')){
39 | event.respondWith(
40 | fetch('/imgs/evil.gif')
41 | );
42 | }
43 | });
44 | ```
45 |
46 | - To hijack a request with a response to 404 not found or offline
47 |
48 | ```javascript
49 | self.addEventListener('fetch', function(event) {
50 | event.respondWith(
51 | fetch(event.request).then(function(response) {
52 | if (response.status === 404) {
53 | //free download and personal use png from https://pngtree.com/freepng/404-error-vector_2871439.html
54 | return fetch('/img/404.png');
55 | }
56 | return response;
57 | }).catch(function () {
58 | return new Response('Perhaps, you are offline!');
59 | })
60 | );
61 | });
62 | ```
63 |
64 |
--------------------------------------------------------------------------------
/Time:
--------------------------------------------------------------------------------
1 | Look for the next year review on the professiona part and personal part.
2 | Imagine the reiew was that it was an amazing year for both professional and personal parts.
3 | Figure out what made it so amazing => write 3 to 5 things that did so fr every part.
4 | Plan to work on these things through the next year => put them on your first periorities.
5 | Break each of them into small doable parts.
6 | Make a a schedule tht contains 3 divisions: professional, relatioships, and self.
7 | Put the tasks into these divisions at every weekend (Thursday suggested).
8 |
9 | --------------------------------
10 |
11 | Hours/week = 7 * 24 = 168 hours.
12 | Sleep = 56 hours.
13 | Work = 40 hours
14 | Malika = 25 hours
15 | Other stuff = 15 hours
16 | Total = 136 hours
17 | Remain = 32 hours ( This is a plenty amount of free hours for a week to do what you planned).
18 |
--------------------------------------------------------------------------------
/angular js/cheat sheet.md:
--------------------------------------------------------------------------------
1 | Startung a new app with angular yeoman and bower.
2 |
3 |
4 | Being on the app root:
5 | `$ npm install -g grunt-cli bower yo generator-karma generator-angular`
6 |
7 | Then
8 | `$ yo angular udaciMeals`
9 |
10 | Then
11 | ```,.
12 | $ npm install
13 | $ npm install -g bower
14 | $ bower install
15 | $ npm install -g grunt-cli
16 | $ grunt serve
17 | ```
18 |
19 | To create a controller
20 |
21 | `$ yo angular:controller `
22 |
23 | To create a view
24 |
25 | `$ yo angular:view `
26 |
27 | To create a service
28 |
29 | `$ yo angular:service `
30 |
31 | To install ui-router
32 |
33 | `$ yo install -S angular-ui-router`
34 |
--------------------------------------------------------------------------------
/angular js/directives.md:
--------------------------------------------------------------------------------
1 | ## Directives
2 |
3 | 1. `ng-if="/condition"`
4 | ```html
5 | Rating: {{menu.rating}} People love this item
6 | ```
7 | **Use: Either creates or removes an element based on the validity of its expression.**
8 |
9 |
10 | 2.
11 |
--------------------------------------------------------------------------------
/gulp/gulp tutorial.md:
--------------------------------------------------------------------------------
1 | # gulp tutorial
2 |
3 | ## Install gulp:
4 |
5 | 1. *globally*:
6 |
7 | ```
8 | npm install -g gulp
9 | ```
10 | 2. locally (on your project main directory:
11 |
12 | ```
13 | npm install --save-dev gulp
14 | ```
15 |
16 | ## gulpfile.js
17 |
18 | - In this JS file you will write tasks that gulp will run.
19 | - Save it in the project main directory.
20 | ```
21 | var gulp = require('gulp');
22 |
23 | gulp.task('default', function() {
24 | console.log('Hello gulp!');
25 | });
26 | ```
27 |
28 | - On terminal:
29 | ```
30 | gulp
31 | ```
32 | ## Uglify JS files
33 |
34 | - Install gulp-uglify package.
35 | - Go to https://gulpjs.com/plugins/
36 | - Search for gulp-uglify. Click it. To see tha install syntax.
37 | - In your terminal at the root of your project:
38 | ```
39 | npm install --save-dev gulp-uglify
40 | ```
41 | - In gulpfile.js:
42 |
43 | ```javascript
44 | var gulp = require('gulp');
45 | var uglify = require('gulp-uglify);
46 |
47 | gulp.task('scripts'/*name of task. you can put whatever name you want*/, function() {
48 | gulp.src('js/**/*.js')
49 | .pipe(uglify())
50 | .pipe(gulp.dest('minjs'));
51 | }
52 | ```
53 |
54 | - On terminal:
55 | ```
56 | gulp scripts
57 | ```
58 |
59 |
--------------------------------------------------------------------------------
/gulp/gulpfile.js:
--------------------------------------------------------------------------------
1 | var gulp = require('gulp');
2 | var uglify = require('gulp-uglify');
3 | var sass = require('gulp-sass');
4 | var plumber = require('gulp-plumber');
5 | var imagemin = require('gulp-imagemin');
6 | var autoprefixer = require('gulp-autoprefixer')
7 |
8 | gulp.task('scripts', function() {
9 | gulp.src('js/*.js')
10 | .pipe(plumber())
11 | .pipe(uglify())
12 | .pipe(gulp.dest('dist/minjs'));
13 | });
14 |
15 | gulp.task('styles', function() {
16 | gulp.src('sass/**/*.scss')
17 | .pipe(sass(
18 | {outputStyle: 'compressed'}
19 | ).on('error', sass.logError))
20 | .pipe(autoprefixer({
21 | browsers: ['last 2 versions']
22 | }))
23 | .pipe(gulp.dest('css'));
24 | });
25 |
26 |
27 | gulp.task('image', function() {
28 | gulp.src('img/*')
29 | .pipe(imagemin())
30 | .pipe(gulp.dest('img/build'));
31 | });
32 |
33 | gulp.task('watch', function() {
34 | gulp.watch('js/*.js', ['scripts']);
35 | gulp.watch('sass/**/*.scss', ['styles']);
36 | });
37 | gulp.task('default', ['scripts', 'styles', 'watch']);
38 |
--------------------------------------------------------------------------------