Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb65916

Browse files
Update App.js
1 parent 340eb16 commit fb65916

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

‎src/App.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
import React, { useState } from 'react';
22
import './style.css';
3-
3+
/*
4+
Differences between forEach() and map() methods:
5+
The forEach() method does not returns a new array based on the given array. The map() method returns an entirely new array. The forEach() method returns "undefined". The map() method returns the newly created array according to the provided callback function.1
6+
*/
47
const numArr = [1, 2, 3];
5-
68
const res = numArr.map((el) => el * 2);
7-
console.log(numArr, res); // [1, 2, 3] [2, 4, 6]
8-
9-
const res2 = numArr.forEach((el, i, arr) => (arr[i] = el * 2));
10-
console.log(numArr, res2); // [2, 4, 6] undefined
9+
console.log(numArr, res);
1110

12-
const obj = {
13-
name: 'Ram',
14-
age: 21,
15-
printInfo: function () {
16-
console.log(`My name is ${this.name}, and my age is ${this.age}`);
17-
},
18-
};
11+
const res2 = numArr.forEach((val, i, arr) => (arr[i] = val * 2));
12+
console.log(numArr, res2);
1913

20-
obj.printInfo(); // My name is Ram, and my age is 21
14+
const person = {
15+
name: "Deepak",
16+
age: 28,
17+
printInfo: function() {
18+
console.log(`My name is ${this.name} and my age is ${this.age}`);
19+
}
20+
}
21+
person.printInfo()
2122

2223
export default function App() {
23-
const ERROR_MSG = 'Age is must be greater than 18';
24+
const ERROR_MSG = 'Age is less than 18';
2425
const [text, setText] = useState('');
2526
const [isError, setError] = useState(false);
26-
const handleTextInput = (e) => {
27+
28+
const handleInputError = (e) => {
2729
setError(false);
2830
console.log(e.target.value);
2931
setText(e.target.value);
@@ -33,7 +35,7 @@ export default function App() {
3335
};
3436
return (
3537
<div>
36-
<input value={text} onChange={handleTextInput} />
38+
<input type={text} onChange={handleInputError} />
3739
<br />
3840
{isError ? ERROR_MSG : null}
3941
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /