You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -43,7 +44,7 @@ You can write and execute JavaScript code within the browser console itself
43
44
44
45
-`alert('Hello World');` displays an alert box with the text Hello in the browser
45
46
-`undefined` means nothing was returned from executed code
46
-
- if you type a number, console will return it. If you type `4 + 4` it will return 8
47
+
- if you type a number, console will return it, ff you type `4 + 4` it will return 8
47
48
- you can select from the DOM by targetting `document` and it will return the HTML document structure
48
49
- what you can do within JavaScript file, can do it within the JavaScript console also
49
50
- when you reload the browser, you code will be gone, it's usually used for debugging/testing JavaScript code before committing it in a JavaScript file
@@ -64,7 +65,7 @@ comments */
64
65
65
66
### Console and other functions
66
67
67
-
-`console.log()` is very useful when testing and debugging codes.
68
+
-`console.log()` is very useful when testing and debugging codes
68
69
-`console.table();` create a table for objects
69
70
-`console.error();` create an error log
70
71
-`consoe.warn();` create a warn log
@@ -111,7 +112,7 @@ Three keywords for declaring a variable in JavaScript
111
112
112
113
-`const` or constant is a variable that cannot be changed or reassigned a new value
113
114
- when `const` is used for Arrays, Objects and other types of data that are primitive like strings and numbers (i.e things that can change but cannot be reassigned), we are able to change the values
114
-
- cannot reassign the value but we can change/mutate array/object properties.
115
+
- cannot reassign the value but we can change/mutate array/object properties
115
116
- can add/change the array/objects but cannot reassign/re-declare the array or object
116
117
117
118
### Conclusion & Recommendation
@@ -122,7 +123,7 @@ use `const` unless:
122
123
123
124
1. the value is changing,
124
125
2. you need to init a variable or
125
-
3. you are using the variable in a iterator for a loop.
126
+
3. you are using the variable in a iterator for a loop
126
127
127
128
Using `const` lets your program or anyone else who is looking at your code, know that the variable should not be reassigned. It can be mutated if its an array or object, but it cannot be reassigned as a new primitive value. This will make your code more robust, secure and more readable.
128
129
@@ -146,7 +147,7 @@ There are a bunch of different data types but there are _Two Types_ of data type
146
147
2.**Number** a number (integers, decimals, floats are all consindered as numbers)
147
148
3.**Boolean** true or false (1 or 0)
148
149
4.**Null** intentional empty value
149
-
5.**Undefined** a variable that has not been assigned a value.
150
+
5.**Undefined** a variable that has not been assigned a value
150
151
6.**Symbols** (ES6)
151
152
152
153
### Reference Data Types
@@ -185,7 +186,7 @@ Type conversion is the process of taking a variable and changing its data type.
185
186
Two ways to convert data types into strings:
186
187
187
188
1.`String()` function
188
-
2.`.toString()` method
189
+
2.`toString()` method
189
190
190
191
We can convert the following data types to a string:
191
192
@@ -272,25 +273,42 @@ Append means to add onto a variable and not replace it. Use (`+=`) append a vari
272
273
273
274
### String Properties & Methods
274
275
275
-
Similar to Numbers, String has built-in properties and methods, E.g. `.length`, `.toUpperCase()`;
276
-
277
-
-`.length` indicates the length of a string
278
-
-`.concat()` concatenates the string arguments to the calling string and returns a new string
279
-
-`.toUpperCase` returns the calling string value converted to uppercase
280
-
-`.toLowerCase()` returns the calling string value converted to lower case
281
-
-`.indexOf()` returns the index within the calling String of the first occurrence of the specified value, else will return -1
282
-
-`.lastIndexOf()` returns the index within the calling String object of the last occurrence of the specified value, else will return -1
283
-
-`.charAt()` returns the character at the specified index in a string
284
-
- get last char by `.length - 1`
285
-
-`substring()` returns the part of the string between the start and end indexes, or to the end of the string.
276
+
Similar to Numbers, String has built-in properties and methods, E.g. `length`, `toUpperCase()`;
277
+
278
+
-`length` indicates the length of a string
279
+
-`concat()` concatenates the string arguments to the calling string and returns a new string
280
+
-`toUpperCase` returns the calling string value converted to uppercase
281
+
-`toLowerCase()` returns the calling string value converted to lower case
282
+
-`indexOf()` returns the index within the calling String of the first occurrence of the specified value, else will return -1
283
+
-`lastIndexOf()` returns the index within the calling String object of the last occurrence of the specified value, else will return -1
284
+
-`charAt()` returns the character at the specified index in a string
285
+
- get last char by `length - 1`
286
+
-`substring()` returns the part of the string between the start and end indexes, or to the end of the string
286
287
-`slice()` extracts a section of a string and returns it as a new string, without modifying the original string
287
-
- slice from left to right, E.g. `.slice(-3)`
288
+
- slice from left to right, E.g. `slice(-3)`
288
289
- slice from right to left (negative number = return last x letters from the string)
289
290
-`split()` splits a String into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split
290
291
-`replace()` returns a new string with some or all matches of a pattern replaced by a replacement
291
292
-`includes()` determines whether one string may be found within another string, returning `true` or `false`
292
293
293
294
To distinguish a property from a method:
294
295
295
-
- properties do not have brackets (`()`) at the end, E.g. `.length`
296
-
- methods has brackets (`()`) at the end, E.g. `.toUpperCase()`
296
+
- properties do not have brackets (`()`) at the end, E.g. `length`
297
+
- methods has brackets (`()`) at the end, E.g. `toUpperCase()`
298
+
299
+
300
+
## Template Literals
301
+
302
+
**Template literals** are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them.
303
+
304
+
Instead of using single (`'`) or double (`"`) quotes we can use back-ticks (`) to indicate a Template Literal. Anything with the back-ticks can be written as normal HTML tags.
305
+
306
+
To enter a JavaScript variable, we can use the syntax `${variableName}` instead of a bunch of `+`.
0 commit comments