Javascript
์ค์ตํ ์์ค ์ ๋ฆฌ
โข
obj_copy.js
const obj1 = {
key1: 10,
key2: "์๋
ํ์ธ์",
key3: {
isLogin: false
}
}
const obj2 = obj1 // ์ฃผ์๊ฐ ๋ณต์ฌ
const obj3 = { ...obj1 } // ๊ฐ์ฒด์ ์์ ๋ณต์ฌ [๊ฐ์ฒด ๋ด์ ๊ฐ์ฒด๋ ์ฃผ์๊ฐ ๋ณต์ฌ]
const obj4 = JSON.parse(JSON.stringify(obj1));
obj1.key1 += 1;
obj1.key3.isLogin = true;
console.log("obj1", obj1);
console.log("obj2", obj2);
console.log("obj3", obj3);
console.log("obj4", obj4);
JavaScript
๋ณต์ฌ
โข
spread_po.js
const [name, ...info] = ["์ต๋ฏผ์", 50, "์์ธ"];
console.log("name", name);
console.log("info", info);
const names = ['์ต๋ฏผ์', '์ ํด์ง', '์ด๋ํ', '๊น๊ณ ์'];
const stars = ['์ด๋ํ', ...names, ...names];
console.log(stars);
const fruits = ['์ฌ๊ณผ', '์ค๋ ์ง', '๋ธ๊ธฐ', '์๋ฐ'];
const [apple, orange, ...rest] = fruits;
console.log(rest);
let me = {
my_name: "jonathan",
my_age: 10,
my_region: '์์ธ',
my_email: 'jonathan@naver.com'
}
const { my_name, my_age, ...my_rest } = me;
console.log(my_rest);
JavaScript
๋ณต์ฌ
โข
arrow_func.js
function sum1(x, y) { return x + y; }
const sum2 = function (x, y) { return x + y; }
const sum3 = (x, y) => { return x + y; }
const sum4 = (x, y) => x + y;
const sum5 = (x, y) => { return x + y; }
console.log(sum1(1, 2))
console.log(sum2(1, 2))
console.log(sum3(1, 2))
console.log(sum4(1, 2))
console.log(((x, y) => x + y)(1, 2))
console.log(sum5(1, 2))
JavaScript
๋ณต์ฌ
โข
map.js
// ๋ฐฐ์ด ๋ฉ์๋ map
// ๋ฐฐ์ด ์์ ์์๋ค์ ์ฒ๋ฆฌํด์, [์๋ก์ด ๋ฐฐ์ด ์์ฑ]
const arr = [1, 3, 5, 7, 9];
const mapArr1 = arr.map((value) => value + 1);
const mapArr2 = arr.map((value, index) => value + index);
const mapArr3 = arr.map((value, index, array) => value + array[4]);
console.log(mapArr1);
console.log(mapArr2);
console.log(mapArr3)
JavaScript
๋ณต์ฌ
โข
filter.js
// ๋ฐฐ์ด ๋ฉ์๋ filter
// ์ฝ๋ฐฑ ์กฐ๊ฑด์ ์ถฉ์กฑํ๋ ์์๋ง์ ์ถ์ถํด [์๋ก์ด ๋ฐฐ์ด ๋ฐํ]
const arr = [1, 2, 3, 4, 5, 6];
// const mapArr1 = arr.map(value => value % 2 == 1);
// console.log(mapArr1);
const filterArr1 = arr.filter(value => value % 2 == 1);
console.log(filterArr1);
const filterArr2 = arr.filter((value, index) => index > 3);
console.log(filterArr2);
const filterArr3 = arr.filter((value, index, array) => value > array[2]);
console.log(filterArr3);
JavaScript
๋ณต์ฌ
โข
forEach.js
// ๋ฐฐ์ด ๋ฉ์๋ forEach
// ๋ฐฐ์ด ๊ฐ ์์์ ๋ํด์ ํจ์๋ฅผ ์คํํ๋ค.
const weekArr = ['์', 'ํ', '์', '๋ชฉ', '๊ธ']
weekArr.forEach((value => {
console.log(value + "์์ผ");
}));
JavaScript
๋ณต์ฌ
โข
reduce.js
// ๋ฐฐ์ด ๋ฉ์๋ reduce
// ๋ฐฐ์ด์ ํตํด ํ๋์ ๊ฐ์ ๋ง๋ ๋ค
const arr = [1, 2, 3, 4, 5];
const value1 = arr.reduce((acc, cur) => { return acc + cur });
const value2 = arr.reduce((acc, cur) => { return acc + cur }, 900);
console.log(value1);
console.log(value2);
const lastArr = arr.reduce((acc, cur) => {
if (cur % 2 === 0) {
acc.push(cur)
}
return acc;
}, []);
console.log(lastArr)
JavaScript
๋ณต์ฌ
React
โข
first_react
import './App.css';
function App() {
const name = "React"
const url = "https://naver.com"
const style = { color: 'red', backgroundColor: 'black' }
const num = 10;
return (
// ์ค๊ดํธ๋ฅผ ์ด์ฉํด ๋ณ์ ์ฝ์
๊ฐ๋ฅ
<div>
<h1>{name + " JS"} ์์</h1>
<a href={url}>๋ค์ด๋ฒ</a>
{/* ๋จ์ผ ํ๊ทธ๋ ํ๊ทธ๋ฅผ ๋ซ์์ผ ํ๋ค */}
<br></br>
<input type='text' value={name}></input>
<br/>
<input type='password' />
{/* class, for => className, htmlFor */}
<div className="title">์ ๋ชฉ</div>
<label htmlFor="user_id">์์ด๋</label>
<input type='text' id="user_id"></input>
{/* style */}
<div style={{color: 'red', backgroundColor: 'black'}}>์๋
ํ์ธ์</div>
<div style={style}>์๋
ํ์ธ์</div>
<div>
{
num > 10 ?
<h1>num์ 10๋ณด๋ค ํฌ๋ค</h1> :
<h1>num์ 10๋ณด๋ค ๊ฐ๊ฑฐ๋ ์๋ค</h1>
}
</div>
</div>
);
}
export default App;
JavaScript
๋ณต์ฌ
โข
component_react
โฆ
Comp.jsx
const Comp = () => {
return (
<div>
๋์ ์ฒซ ์ปดํฌ๋ํธ
</div>
)
}
export default Comp;
JavaScript
๋ณต์ฌ
โฆ
Comps.jsx
const Header = () => {
return (
<div>
<h1>
<a href='/'>React</a>
</h1>
</div>
);
}
const Navi = () => {
const menuList = [
{ name: "ํ", link: "/" },
{ name: "์ถ์ฒ", link: "recomm" },
{ name: "๋ทฐํฐ", link: "beauty" },
]
return (
<nav>
{
menuList.map((menu) => {
return (
<div>
<a href={menu.link}>
{menu.name}
</a>
</div>
)
})
}
</nav>
);
}
const Article = (props) => {
const style = {
textAlign: 'center',
backgroundColor: "#aaa",
height: '20vh',
margin: '10px 50px',
}
return (
<article style={style}>
<h2>{props.text}</h2>
</article>
);
}
export default { Header, Navi, Article };
JavaScript
๋ณต์ฌ
โฆ
Introduce.jsx
import Button from "../Button";
const Introduce = (props) => {
return (
<div>
<h2>์๋
ํ์ธ์</h2>
<Button size="small" color='red'>ํด๋ฆญ</Button>
<Button size="medium" color='orange'>๋๋ฅด์ธ์</Button>
<Button size="large" color='yellow'>Click</Button>
<Button event={() => alert('ํด๋ฆญ๋์์ต๋๋ค.')}></Button>
<p>๋ด ์น๊ตฌ ์ด๋ฆ {props.name}์
๋๋ค.</p>
<p>๋ด ์น๊ตฌ์ ์ฑ๋ณ์ {props.gender}์
๋๋ค.</p>
</div>
);
}
Introduce.defaultProps = {
name: "minsung",
gender: '๋จ์'
}
export default Introduce;
JavaScript
๋ณต์ฌ
โฆ
App.js
import './App.css';
import Comp from './components/Comp';
import Comps from './components/Comps';
import Introduce from './components/Introduce';
function App() {
return (
<div>
<Comps.Header></Comps.Header>
<Comps.Navi></Comps.Navi>
{ /* props: ๋ถ๋ชจ์ปดํฌ๋ํธ๊ฐ ์์์ปดํฌ๋ํธ์๊ฒ ์ ๋ฌํ๋ ๊ฐ */ }
<Comps.Article text="ํ์ํฉ๋๋ค."></Comps.Article>
<Comps.Article text="๋ง๋์ ๋ฐ๊ฐ์ต๋๋ค."></Comps.Article>
<Comp />
<Introduce name="์ ์ฌ์" gender="๋จ์"></Introduce>
<Introduce name="๊น์ข
๊ตญ" gender="๋จ์"></Introduce>
<Introduce name="์ง์์ง" gender="๋จ์"></Introduce>
<Introduce name="์ ์๋ฏผ" gender="์ฌ์"></Introduce>
<Introduce></Introduce>
</div>
);
}
export default App;
JavaScript
๋ณต์ฌ
โข
layout_react - ๊ฒ์ํ ๊พธ๋ฏธ๊ธฐ
โฆ
Layout.css
header {
background-color: lightgreen;
padding: 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
header a {
text-decoration: none;
color: black;
font-size: 18px;
}
header nav {
display: flex;
}
header nav li {
background-color: lightsalmon;
list-style-type: none;
margin-right: 10px;
padding: 3px 6px;
border-radius: 10px;
border: 1px solid black;
box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.15);
}
main {
padding: 50px;
min-height: 50vh;
}
footer {
background-color: #bbb;
padding: 20px;
}
CSS
๋ณต์ฌ
โฆ
Layout.jsx
import "./Layout.css";
const Layout = ({children}) => {
return (
<>
<header>
<a href="/">๋ฉ์ธ๋ก๊ณ </a>
<nav>
<li><a href="/#menu1">menu1</a></li>
<li><a href="/#menu2">menu2</a></li>
<li><a href="/#menu3">menu3</a></li>
<li><a href="/#menu4">menu4</a></li>
</nav>
</header>
<main>
{children}
</main>
<footer>์ฐ๋ฝ์ฒ ์ ๋ณด</footer>
</>
);
}
export default Layout;
JavaScript
๋ณต์ฌ
โฆ
App.js
import logo from './logo.svg';
import './App.css';
import Layout from './components/Layout';
function App() {
return (
<div className="App">
<Layout>
<div>
<h1>๊ฒ์ํ ํ๋ฉด</h1>
<table>
<tr>
<th>๋ฒํธ</th>
<th>์ ๋ชฉ</th>
<th>์์ฑ์</th>
</tr>
<tr>
<td>1</td>
<td>์๋
ํ์ธ์</td>
<td>minsung</td>
</tr>
<tr>
<td>2</td>
<td>ํ์ค์ ์ฐจ๊ฐ๋ค</td>
<td>minsung</td>
</tr>
</table>
</div>
</Layout>
</div>
);
}
export default App;
JavaScript
๋ณต์ฌ
JSON ์๋ฒ ์ค์น
โข
npm ์คํ
sudo npm i -g json-server
CSS
๋ณต์ฌ
โข
server ์คํ (json server์ react ์๋ฒ๊ฐ ๋์์ ์คํ๋์ด ์์ด์ผ ํจ)
json-server --watch data.json --port 8080
--watch/-w can be omitted, JSON Server 1+ watches for file changes by default
JSON Server started on PORT :8080
Press CTRL-C to stop
Watching data.json...
โกโธ(หถห แต หหถ)โธโก
Index:
http://localhost:8080/
Static files:
Serving ./public directory if it exists
Endpoints:
No endpoints found, try adding some data to data.json
CSS
๋ณต์ฌ



