W3Schools: => Google for: w3schools js alert
, w3schools js String
, etc.
MDN JS: => Google for: mdn js alert
, mdn js String
, etc.
JavaScript Day 01
- Dynamic HTML Pages
- Web Applications:
- Desktop Applications (Using Electron.JS)
- Bookmarklets
- Browser Extensions
- Mobile Apps
- Server Applications
- Command Line Tools
- Electronics (Arduino)
- Artificial Intelligence / Machine Learning
- Brain Controlled Applications!
- Hello World
- Strings
- Numbers
- typeof Operator
How do we clear the console?
- Click the
Clear Console
Button - Press
Ctrl + L
- Write
console.clear();
How do we change the default browser used by the Live Server VSCode extension?
- Go to
File > Preferences > Settings
and search forLive Server custom browser
- In the
Live Server: Custom Browser
setting select your favorite Browser - Note: Settings are saved automatically
- Note: On Mac you can access the Settings from:
Code > Preferences > Settings
JavaScript Day 02
What happens if I omit the ; after a statement? Is it optional?
- If you omit a semicolon
;
at the end of the statement, JavaScript will try to guess and automatically place the semicolon itself. Most of the times, it does a good job at this, but there are cases where the automatic semicolon placement mechanism will produce undesirable effects. Therefore, we tend to place the semicolons ourselves. Try to get into the habit of placing semicolons at the end of your statements.
Does the semicolons at the end of JavaScript statements work much like the ones in CSS?
- In a way, they do. Just like we must end each CSS rule with a semicolon; we also have to end each JS statement with a semicolon too, but, unlike CSS, JavaScript can deal with omitted semicolons by placing them automatically. So, most of the time, our statements will work without semicolons at the end, whereas in CSS an omitted semicolon will break subsequent CSS rules.
Are the break
and default
statements optional inside the switch
statement?
- Yes, they can be omitted, but make sure to check out the following 2 MDN resources:
- What happens if I forgot a break?
Switch
description
When we do a string comparison with ==, e.g. "4" == 3, which operand gets converted?
- The String part is converted to a Number, e.g. "4" becomes 4 and then it's value is compared with 3
(Reference: Comparing Strings to Numbers)
How does the switch statement compares the switch value with each case value?
Example:
switch (a) {
case 2:
// do something
break;
case 42:
// do another thing
break;
default:
// fallback to here
}
-
"...the matching that occurs between the a expression and each case expression is identical to the === algorithm." Reference:
-
How do we print newlines to the console?
Using the '\n' escape character.
console.log("A line and \n another line and yet \n another line!");
-
When should we place the <script> tags in the <head> area?
- When you insert a library script such as the jQuery library
- When performance/page load times are not considerably affected by the script
- When you want to tweak CSS styling before the body is rendered via a script.
- Arrays: Dynamic relationship with variables and values.
- Arrays: push, pop, shift, unshift & length.
- Arrays: Change the value of a specific Array element.
- Arrays: Different behaviors with const and array values
- What is the difference between placing <script> in head and before </body>?
- The
defer
andasync
script attributes - Where to place JavaScript in an HTML file?
- String Methods
- Number Methods
- Array Methods - Full Reference
- Should I write script in the body or the head of the html? [duplicate]
- When to use the <script> tag in the head and body section of a html page?
- Loose Equals == vs. Strict Equals ===
- The Switch Statement
JavaScript Day 03
-
Quick Array Reference:
`let months = [ 1, 2, 3 ];`<br/> `months.push( 4, 5, 6 ); // [ 1, 2, 3, `**`4, 5, 6`**` ]`<br/> `months.pop(); // [ 1, 2, 3, 4, 5 ]`<br/> `months.shift(); // [ 2, 3, 4, 5 ]`<br/> `months.unshift( 0, 1 ); // [ `**`0, 1`**`, 2, 3, 4, 5]`<br/> `months[0]; // 0`<br/> `months[1]; // 1`<br/> **NESTED ARRAYS:** Arrays inside Arrays and how to access them ``` let nested = [ 1, 2, 3, [ "Corto", "Maltese" ]
];
`nested[0]; // 1`<br/> `nested[1]; // 2`<br/> `nested[2]; // 3`<br/> `nested[3]; // [ "Corto", "Maltese" ]`<br/> `nested[3][0]; // "Corto"`<br/> `nested[3][1]; // "Maltese"`<br/>
Can we manually break out of an Infinite Loop?
- If you're using Chrome,
Shift-Esc
to bring up the Chrome task manager, and kill the task.
Reference: TeamTreehouse / Stack Overflow
- How to avoid infinite loops in JavaScript
- Visualization of passing data by Value vs. by Reference
- ( See Resources - Tools section below for the Chrome Extension that displays a warning icon at the bottom right section of the webpage to indicate JavaScript errors on web pages. Here's a video showing how to install and use the Extension.)