TIL * 22.02.05

RIHOยท2022๋…„ 2์›” 5์ผ
0

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
6/13
post-thumbnail
post-custom-banner

๐Ÿ”ถ JS

1.

// ๋‹ค์Œ ๋‘ ์ค„์˜ ์ฝ”๋“œ๋Š” ๋™์ผํ•˜๋‹ค.

greeting.innerText = `hello ${username}`;
greeting.innerText = 'hello ' + username

2.

    localStorage.setItem("username", username);

localStorage์— ๊ฐ’ ์ €์žฅ. username์ด๋ผ๋Š” key์— username์ด๋ผ๋Š” ๊ฐ’์„ ๋„ฃ๋Š”๋‹ค.

3. padStart()

๋ฌธ์ž์—ด์˜ ์‹œ์ž‘ ๋ถ€๋ถ„์— ๋‹ค๋ฅธ ๋ฌธ์ž๋ฅผ ์ฑ„์›Œ ์ฃผ์–ด์ง„ ๊ธธ์ด๋ฅผ ๋งŒ์กฑํ•˜๋Š” ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ๋ฉ”์„œ๋“œ. (ex: ์‹œ๊ณ„ ์ œ์ž‘)

function getClock() {
    const time = new Date();
    const hour = String(time.getHours()).padStart(2, '0');
    const minute = String(time.getMinutes()).padStart(2, '0');
    const second = String(time.getSeconds()).padStart(2, '0');

    // clock.innerText = (`${hour < 10 ? `0${hour}` : hour}:${minute < 10 ? `0${minute}` : minute}:${second < 10 ? `0${second}` : second}`);
    clock.innerText = `${hour}:${minute}:${second}`;
}

4.

getElementById : ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด๊ณผ ์ผ์น˜ํ•˜๋Š” id ์†์„ฑ์„ ๊ฐ€์ง„ ์š”์†Œ๋ฅผ ์ฐพ๊ณ  ์ด๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” element ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜
querySelector : ์„ ํƒ์ž์™€ ์ผ์น˜ํ•˜๋Š” ๋ฌธ์„œ ๋‚ด ์ฒซ๋ฒˆ์งธ element๋ฅผ ๋ฐ˜ํ™˜. id๊ฐ€ ์—†๋Š” ์š”์†Œ์— ์ ‘๊ทผํ•  ๋•Œ ์‚ฌ์šฉ

๋‚˜๋Š” ์ฃผ์„์œผ๋กœ ์ฒ˜๋ฆฌํ•œ ๋Œ€๋กœ ์ฝ”๋“œ๋ฅผ ์งฐ์—ˆ๋Š”๋ฐ, padStart๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ชฝ์ด ํ›จ์”ฌ ๊น”๋”ํ•˜๋‹ค.



5. ํ™”์‚ดํ‘œ ํ•จ์ˆ˜

const fn = (arg1) => {
 {...}
}

arg1์„ ์ธ์ž๋กœ ๋ฐ›๋Š” ํ•จ์ˆ˜ fn.

  • ์ต๋ช… ํ•จ์ˆ˜๋กœ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ํ™”์‚ดํ‘œ ํ•จ์ˆ˜์—์„œ this๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์™ธ๋ถ€์—์„œ ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์˜จ๋‹ค.
  • ์ƒ์„ฑ์ž ํ•จ์ˆ˜๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค. ์ฆ‰ new ์™€ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค.

์ฐธ๊ณ : https://ko.javascript.info/arrow-functions

๐Ÿ’ซ Git

git commit -am "commit message"
์ˆ˜์ •๋œ ํŒŒ์ผ์— ๋Œ€ํ•œ add ๋ฐ commit์„ ์ผ๊ด„์ ์œผ๋กœ ์ง„ํ–‰ ๋ฐ ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€ ์ž…๋ ฅ.

๐Ÿ“› Error

1.

Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')

<script> ํƒœ๊ทธ์˜ ์œ„์น˜๋ฅผ ์•„๋ž˜๋กœ ์กฐ์ •ํ•˜๋‹ˆ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค.

2.

todo-list์˜ ์‚ญ์ œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๋˜ ๋„์ค‘ button ํด๋ฆญ์ด ์•„๋‹Œ, submit์„ ํ•  ๋•Œ๋งˆ๋‹ค delete ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”(!) ์น˜๋ช…์ ์ธ ๋…ผ๋ฆฌ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค.

์‚ฌ์ง„๊ณผ ๊ฐ™์ด <ui> ํƒœ๊ทธ๊ฐ€ <form> ํƒœ๊ทธ ๋‚ด๋ถ€์— ๋“ค์–ด๊ฐ€ ์žˆ์–ด, parentElement ๋ฉ”์„œ๋“œ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋™์ž‘ํ•˜์ง€ ์•Š์•„ ๋ฐœ์ƒํ•œ ์˜ค๋ฅ˜์˜€๋‹ค.

๋ชจ๋“  ์˜ค๋ฅ˜๋ฅผ JS์—์„œ๋งŒ ์ฐพ์œผ๋ ค๊ณ  ํ•˜์ง€ ๋ง์ž.

profile
Front-End / ๊ธฐ๋ก์šฉ
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€