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
Copy file name to clipboardExpand all lines: README.md
+27-3Lines changed: 27 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,18 @@ const null_var = null;
65
65
console.log(null_var); // prints null to the console
66
66
```
67
67
68
+
There are two ways to declare a variable in JS, one is `const` and the other is `let`. The difference between them is that the `const` variables cannot be reassigned, but the `let` variables can be reassigned.
69
+
70
+
```javascript
71
+
constconst_var=10;
72
+
let let_var =10;
73
+
74
+
const_var =20; // throws an error in the JavaScript
75
+
let_var =20; // works fine
76
+
```
77
+
78
+
For the const datatype, if you have assigned an array or an object, you can change the values of the array or the object, you can add additional elements and many more, but you cannot reassign the variable.
79
+
68
80
### Strings
69
81
70
82
Some of the default string functions and properties are:
@@ -150,7 +162,7 @@ const b = 20;
150
162
console.log(a + b); // prints 30 to the console
151
163
```
152
164
153
-
We can also perform addition on strings, which is called as concatenation.
165
+
We can also perform addition on strings, which is called concatenation.
154
166
155
167
```javascript
156
168
consta="Hello";
@@ -192,9 +204,9 @@ console.log(Math.round(10.5)); // prints 11 to the console
192
204
193
205
## Arrays
194
206
195
-
Arrays are a type of datatypes(advanced), which can be store any kind of datatype of in it. Arrays are mutable, meaning the content of the array can be changed at any point in time.
207
+
Arrays are a type of datatype(advanced), which can store any kind of datatype in it. Arrays are mutable, meaning the content of the array can be changed at any point in time.
196
208
197
-
They are defined by the square bracket notation and also as a object notation. One of the advantage of the array datatype is, if you know the location(index) of the element, then you can access it by constant-time operation.
209
+
They are defined by the square bracket notation and also as an object notation. One of the advantages of the array datatype is, if you know the location(index) of the element, then you can access it by constant-time operation.
198
210
199
211
**Defining an Array**
200
212
```javascript
@@ -228,6 +240,8 @@ arr.pop();
228
240
console.log(arr); // prints [1, 2, 3, 4] to the console
229
241
```
230
242
243
+
When running a push operation, it will return the length of the array.
244
+
231
245
**Queue Operations**
232
246
```javascript
233
247
var arr = [1, 2, 3, 4, 5];
@@ -244,6 +258,16 @@ console.log(slice); // prints [3, 4, 5, 6, 7] to the console
244
258
console.log(arr); // prints [1, 2, 8, 9]
245
259
```
246
260
261
+
To apply a specific operation on each element of the array, we can use the `forEach()` method.
262
+
263
+
```javascript
264
+
var arr = [1, 2, 3, 4, 5];
265
+
266
+
arr.forEach((element) => {
267
+
console.log(element);
268
+
});
269
+
```
270
+
247
271
## Conditions
248
272
249
273
Conditions are used to check whether a condition is true or false, and based on that we can perform some operations.
0 commit comments