Skip to content

Commit 901ac78

Browse files
committed
added some stuff
1 parent 537d6cb commit 901ac78

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ const null_var = null;
6565
console.log(null_var); // prints null to the console
6666
```
6767

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+
const const_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+
6880
### Strings
6981

7082
Some of the default string functions and properties are:
@@ -150,7 +162,7 @@ const b = 20;
150162
console.log(a + b); // prints 30 to the console
151163
```
152164

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.
154166

155167
```javascript
156168
const a = "Hello";
@@ -192,9 +204,9 @@ console.log(Math.round(10.5)); // prints 11 to the console
192204

193205
## Arrays
194206

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.
196208

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.
198210

199211
**Defining an Array**
200212
```javascript
@@ -228,6 +240,8 @@ arr.pop();
228240
console.log(arr); // prints [1, 2, 3, 4] to the console
229241
```
230242

243+
When running a push operation, it will return the length of the array.
244+
231245
**Queue Operations**
232246
```javascript
233247
var arr = [1, 2, 3, 4, 5];
@@ -244,6 +258,16 @@ console.log(slice); // prints [3, 4, 5, 6, 7] to the console
244258
console.log(arr); // prints [1, 2, 8, 9]
245259
```
246260

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+
247271
## Conditions
248272

249273
Conditions are used to check whether a condition is true or false, and based on that we can perform some operations.

0 commit comments

Comments
 (0)