Skip to content

Commit 6aefbc8

Browse files
Merge pull request #37 from teahsea/nikunj/small-changes
Replace unnecessary use of let with const
2 parents 1957f15 + 7a26761 commit 6aefbc8

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

README.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ console.log(sum(...numbers)); // 60
100100
**2.1. Copying an array:**
101101

102102
```js
103-
let fruits = ["Apple", "Orange", "Banana"];
104-
let newFruitArray = [...fruits];
103+
const fruits = ["Apple", "Orange", "Banana"];
104+
const newFruitArray = [...fruits];
105105

106106
console.log(newFruitArray);
107107
```
@@ -121,10 +121,10 @@ Output:
121121
**2.2. Concatenating arrays:**
122122

123123
```js
124-
let arr1 = ["A", "B", "C"];
125-
let arr2 = ["X", "Y", "Z"];
124+
const arr1 = ["A", "B", "C"];
125+
const arr2 = ["X", "Y", "Z"];
126126

127-
let result = [...arr1, ...arr2];
127+
const result = [...arr1, ...arr2];
128128

129129
console.log(result);
130130
```
@@ -144,8 +144,8 @@ Output:
144144
**2.3. Spreading elements together with an individual element:**
145145

146146
```js
147-
let fruits = ["Apple", "Orange", "Banana"];
148-
let newFruits = ["Cherry", ...fruits];
147+
const fruits = ["Apple", "Orange", "Banana"];
148+
const newFruits = ["Cherry", ...fruits];
149149

150150
console.log(newFruits);
151151
```
@@ -165,7 +165,7 @@ Output:
165165
**2.4. Spreading elements on function calls:**
166166

167167
```js
168-
let fruits = ["Apple", "Orange", "Banana"];
168+
const fruits = ["Apple", "Orange", "Banana"];
169169

170170
const getFruits = (f1, f2, f3) => {
171171
console.log(`Fruits: ${f1}, ${f2} and ${f3}`);
@@ -217,7 +217,7 @@ Output:
217217
Sets are a new object type with ES6 (ES2015) that allow to create collections of unique values. The values in a set can be either simple primitives like strings or integers, but more complex object types like object literals or arrays can also be part of a set.
218218

219219
```js
220-
let numbers = new Set([10, 20, 20, 30, 40, 50]);
220+
const numbers = new Set([10, 20, 20, 30, 40, 50]);
221221

222222
console.log(numbers); Set(5) { 10, 20, 30, 40, 50 }
223223
console.log(typeof numbers); // Object
@@ -236,7 +236,10 @@ function add(x = 10, y = 20) {
236236
console.log(x + y);
237237
}
238238

239-
add(10, 30); // 40
239+
add(10, 30); // Output: 10 + 30 = 40
240+
add(15); // Output: 15 + 20 = 35
241+
add(); // Output: 10 + 20 = 30
242+
240243
```
241244

242245
**⚝ [Try this example on CodeSandbox](https://codesandbox.io/s/js-default-parametrs-tjw9uk?file=/src/index.js)**
@@ -272,7 +275,7 @@ Hello World
272275
**6. Arrow Function (=>):**
273276

274277
```js
275-
let add = (x, y) => x + y;
278+
const add = (x, y) => x + y;
276279

277280
console.log(add(10, 20)); // 30
278281
```
@@ -347,7 +350,7 @@ function* generator(num) {
347350
yield num + 20;
348351
yield num + 30;
349352
}
350-
let gen = generator(10);
353+
const gen = generator(10);
351354

352355
console.log(gen.next().value); // 20
353356
console.log(gen.next().value); // 30

0 commit comments

Comments
 (0)