[js] basic concepts

miaยท2024๋…„ 12์›” 20์ผ
0

๐Ÿ“์‹œ์ž‘ํ•˜๊ธฐ

VS code์—์„œ ์‹คํ–‰:

js์™€ css๋Š” html์— ๋ถ™์–ด์„œ ์‹คํ–‰๋œ๋‹ค.
๋ธŒ๋ผ์šฐ์ €๋Š” html ํŒŒ์ผ์„ ์ฝ๊ณ , html์ด glued๋œ css์™€ js๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" />
    <title>Momentum</title>
  </head>
  <body>
    <script src="app.js"></script>
  </body>
</html>

๐Ÿ“๋ณ€์ˆ˜

"always const, sometimes let, never var"

Variable

  • const : ๋ฐ”๊พธ์ง€ ์•Š์„ ๋ณ€์ˆ˜
  • let : ๋ฐ”๊ฟ€ ์ˆ˜๋„ ์žˆ๋Š” ๋ณ€์ˆ˜
  • var : ์•ˆ์”€

Type

  • false : ๊ฑฐ์ง“
  • true : ์ฐธ
  • null : ์•„๋ฌด๊ฒƒ๋„ ์—†์Œ ('์—†์Œ'์ด๋ผ๋Š” ๊ฐ’์ด ์กด์žฌํ•จ)
  • undefined : ์„ ์–ธํ•ด๋†“๊ณ  ๊ฐ’์„ ์ฃผ์ง€ ์•Š์€ ์ƒํƒœ

๐Ÿ“ํ•จ์ˆ˜

console.log();	// ์ฝ˜์†”์— ๋ณด๋‚ด๋Š” ๋ฉ”์‹œ์ง€

๐Ÿ“์ž๋ฃŒ๊ตฌ์กฐ

๐Ÿ’š Array : [ ]

๊ฐ ํ•ญ๋ชฉ์— ๋Œ€ํ•œ ์„ค๋ช…์ด ํ•„์š” ์—†๋Š” ๋ฆฌ์ŠคํŠธ
๋ณ€์ˆ˜, string, integer, boolean, null, undefined ๋“ฑ ์•„๋ฌด๊ฑฐ๋‚˜ ๋„ฃ์–ด๋„ ๋จ

const mon = "mon";
const tue = "tue";
const wed = "wed";

const halfOfWeek = [mon, tue, wed];

์‚ฌ์šฉ๋ฒ•:

const daysOfWeek = ["mon", "tue", "wed", "thu", "fri", "sat"];

// ๋ฐฐ์—ด์—์„œ ์•„์ดํ…œ ๊ฐ€์ ธ์˜ค๊ธฐ
console.log(daysOfWeek[5]);

// ๋ฐฐ์—ด์— ์•„์ดํ…œ ์ถ”๊ฐ€ํ•˜๊ธฐ
daysOfWeek.push("sun");

๐Ÿ’š Object : { }

๊ฐ ํ•ญ๋ชฉ์— ๋Œ€ํ•œ ์„ค๋ช…์ด ํ•„์š”ํ•œ ๋ฆฌ์ŠคํŠธ
property๋ฅผ ๊ฐ€์ง„ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•จ

const player = {
  name: "mia",
  level: 90,
  job: "machinist",
};

console.log(player.job); // player.job๊ณผ player["job"]์€ ๊ฐ™์Œ

player.lastName = "potato";	// Object์— ์•„์ดํ…œ ์ถ”๊ฐ€ํ•˜๊ธฐ
profile
๋ฐ”๋ณด

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