| ์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
- ํด๋์ค์ ๋ ํฐ
- textdecoration
- ๊ทธ๋ฃน์ ๋ ํฐ
- liststyleposition
- ์ถ์ฝ
- bordercollapse
- wordspacing
- ์์ด๋์ ๋ ํฐ
- inlineblock
- selectorslevel4
- ๋ชจ๋์นํฐํธ
- gtammertable
- ํ์ ์ ๋ ํฐ
- fontweight
- CDN
- ์ ๋๋ฒ์ ์ ๋ ํฐ
- ์ฃผ์
- texttransform
- borderspacing
- borderstyle
- ๊ตฌ๊ธํฐํธ
- formtag
- liststyletype
- captionside
- textshadow
- ํฅ์ค์ฝ๋
- ๋นํ๊ทธ
- ํผํ๊ทธ
- ํฐํธ์จ์ดํธ
- liststyleimage
- Today
- Total
็ก์
Operator (์ฐ์ฐ์) ๋ณธ๋ฌธ
๐จ Operators
๋ณ์์ ์ ์ฅ๋ ๊ฐ์ด๋ ๋ฆฌํฐ๋ด ๊ฐ์ ๊ณ์ฐํ๊ฑฐ๋ ๋น๊ตํ์ฌ ์๋ก์ด ๊ฐ์ ๋ง๋ค์ด๋ด๋ ๊ธฐํธ.
1๏ธโฃ ์ฐ์ ์ฐ์ฐ์ (Arithmetic Operators)
์ซ์ ๋ฐ์ดํฐ๋ฅผ ์ด์ฉํด ๊ธฐ๋ณธ์ ์ธ ์ํ ๊ณ์ฐ์ ์ํํ๋ค.
let a = 10;
let b = 3;
console.log(a + b); // 13
console.log(a - b); // 7
console.log(a * b); // 30
console.log(a / b); // 3.3333...
console.log(a % b); // 1 (10์ 3์ผ๋ก ๋๋ ๋๋จธ์ง)
console.log(a ** b); // 1000 (10์ 3์ ๊ณฑ)
// ๋๋จธ์ง ์ฐ์ฐ์ ํ์ฉ: ํ์ง ํ๋ณ
let num = 7;
console.log(num % 2 === 0 ? "์ง์" : "ํ์"); // "ํ์"
- +: ๋ง์ .
- -: ๋บ์ .
- *: ๊ณฑ์ .
- /: ๋๋์ .
- %: ๋๋จธ์ง. (ํ์ง, ๋ฐฐ์ ํ๋ณ์ ํ์ฉ)
- **: ๊ฑฐ๋ญ์ ๊ณฑ. (์: 2 ** 3์ 8)
2๏ธโฃ ๋์ /ํ ๋น ์ฐ์ฐ์ (Assignment Operators)
๋ณ์์ ๊ฐ์ ์ ์ฅํ๊ฑฐ๋ ๊ธฐ์กด ๊ฐ์ ์ฐ์ฐ ํ ๋ค์ ์ ์ฅํ๋ค.
let total = 100;
total += 50; // total = total + 50๊ณผ ๊ฐ์ (150)
total -= 20; // total = total - 20๊ณผ ๊ฐ์ (130)
total *= 2; // total = total * 2์ ๊ฐ์ (260)
total /= 10; // total = total / 10๊ณผ ๊ฐ์ (26)
console.log("์ต์ข
ํฉ๊ณ:", total); // 26
- =: ๊ฐ ์ ์ฅ.
- +=: ๋ํ ํ ์ ์ฅ.
- -=: ๋บ ํ ์ ์ฅ.
- *=: ๊ณฑํ ํ ์ ์ฅ.
- /=: ๋๋ ํ ์ ์ฅ.
- %=: ๋๋จธ์ง ์ ์ฅ.
๐ ์ฐ์ฐ๊ณผ ๋์ ์ ํ ๋ฒ์ ์ฒ๋ฆฌํ ์ ์๋ค. (์: a += 5๋ a = a + 5์ ๋์ผ)
3๏ธโฃ ๋น๊ต ์ฐ์ฐ์ (Comparison Operators) (์ผ๋ฐ ๋น๊ต vs ์๊ฒฉํ ๋น๊ต)
๋ ๊ฐ์ ๋น๊ตํ์ฌ ์ฐธ(true) ๋๋ ๊ฑฐ์ง(false)์ ๋ฐํํ๋ค.
let x = 5;
let y = "5";
// ์ผ๋ฐ ๋น๊ต (๊ฐ๋ง ๊ฐ์ผ๋ฉด ์ฐธ)
console.log(x == y); // true
// ์๊ฒฉํ ๋น๊ต (๊ฐ๊ณผ ์๋ฃํ์ด ๋ชจ๋ ๊ฐ์์ผ ์ฐธ)
console.log(x === y); // false (์ซ์ 5์ ๋ฌธ์์ด "5"๋ ๋ค๋ฆ)
// ๋ถ๋ฑํธ ๋น๊ต
console.log(10 > 5); // true
console.log(10 <= 10); // true
console.log(10 !== 5); // true (10๊ณผ 5๋ ๊ฐ์ง ์์)
- ==: ๋๋ฑ ๋น๊ต. (๊ฐ๋ง ๋น๊ต, ํ์ ๋ฌด์)
- ===: ์ผ์น ๋น๊ต. (๊ฐ๊ณผ ํ์ ๋น๊ต) (๊ถ์ฅ)
- !=: ๋ถ๋ฑ ๋น๊ต. (๊ฐ์ด ๋ค๋ฆ)
- !==: ๋ถ์ผ์น ๋น๊ต. (๊ฐ ๋๋ ํ์ ์ด ๋ค๋ฆ)
- >: ํฌ๋ค.
- <: ์๋ค.
- >=: ํฌ๊ฑฐ๋ ๊ฐ๋ค.
- <=: ์๊ฑฐ๋ ๊ฐ๋ค.
๐ ์ค๋ฌด์์๋ ๋๋ถ๋ถ ===, !== ์ฌ์ฉ.
4๏ธโฃ ๋ ผ๋ฆฌ ์ฐ์ฐ์ (Logical Operators)
์ฌ๋ฌ ์กฐ๊ฑด์ ๊ฒฐํฉํ๊ฑฐ๋ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์ ํ๋ค. (์ฌ๋ฌ ์กฐ๊ฑด์ ๋ฌถ์ด์ ํ๋จํ ๋ ์ฌ์ฉ)
let hasID = true; // ์ ๋ถ์ฆ ์์ง ์ฌ๋ถ
let isAdult = false; // ์ฑ์ธ ์ฌ๋ถ
// AND (&&): ๋ ๋ค ์ฐธ์ด์ด์ผ ํจ
console.log(hasID && isAdult); // false (์ ๋ถ์ฆ์ ์์ง๋ง ์ฑ์ธ์ด ์๋)
// OR (||): ํ๋๋ง ์ฐธ์ด์ด์ผ ํจ
console.log(hasID || isAdult); // true (์ ๋ถ์ฆ์ด ์์ผ๋ฏ๋ก ํต๊ณผ)
// NOT (!): ์ฐธ/๊ฑฐ์ง์ ๋ค์ง์
console.log(!hasID); // false (true์ ๋ฐ๋)
- &&: AND. (๋ชจ๋ ์ฐธ์ด๋ฉด true)
- ||: OR. (ํ๋๋ผ๋ ์ฐธ์ด๋ฉด true)
- !: NOT. (๋ฐ๋๊ฐ ๋ฐํ)
5๏ธโฃ ์ฆ๊ฐ ์ฐ์ฐ์ (Increment / Decrement Operators)
๊ฐ์ 1์ฉ ์ฆ๊ฐ ๋๋ ๊ฐ์์ํค๋ฉฐ, ์์น์ ๋ฐ๋ผ ์คํ ์์๊ฐ ๋ฌ๋ผ์ง๋ค.
let count = 0;
count++; // count = count + 1 (1)
console.log(count);
count--; // count = count - 1 (0)
console.log(count);
// ์ ์(++n)์ ํ์(n++)์ ์ฐจ์ด
let n = 5;
console.log(n++); // 5 ์ถ๋ ฅ ํ 6์ผ๋ก ์ฆ๊ฐ (ํ์ฌ ์ค์์๋ ์ฆ๊ฐ ์ ๊ฐ ์ฌ์ฉ)
console.log(++n); // 7๋ก ๋จผ์ ์ฆ๊ฐ ํ ์ถ๋ ฅ (ํ์ฌ ์ค์์ ์ฆ๊ฐ๋ ๊ฐ ์ฌ์ฉ)
- ++: 1 ์ฆ๊ฐ.
- --: 1 ๊ฐ์.
6๏ธโฃ ์ผํญ ์ฐ์ฐ์ (Conditional Operator)
์กฐ๊ฑด์ ๋ฐ๋ผ ๋ค๋ฅธ ๊ฐ์ ๋ฐํํ๋ค.
const age = 20;
const result = age >= 18 ? "์ฑ์ธ" : "๋ฏธ์ฑ๋
์";
console.log(result); // ์ฑ์ธ
- ๊ตฌ์กฐ: ์กฐ๊ฑด์ ? ์ฐธ์ผ ๋ ๊ฐ : ๊ฑฐ์ง์ผ ๋ ๊ฐ.
๐ if๋ฌธ์ ๊ฐ๋จํ๊ฒ ์ค์ธ ํํ.
7๏ธโฃ typeof ์ฐ์ฐ์ (Type Operator)
๋ฐ์ดํฐ์ ์๋ฃํ(type) ์ ๋ฌธ์์ด(string)๋ก ๋ฐํํ๋ค.
console.log(typeof 123); // "number"
console.log(typeof "hello"); // "string"
console.log(typeof true); // "boolean"
console.log(typeof undefined);// "undefined"
- typeof๋ ๊ฐ์ด ์ด๋ค ๋ฐ์ดํฐ ํ์ ์ธ์ง ํ์ธํ ๋ ์ฌ์ฉํ๋ค.
- ๋๋ฒ๊น ์ด๋ ์กฐ๊ฑด๋ฌธ์์ ๋ฐ์ดํฐ ํ์ ์ ํ์ธํ ๋ ์ ์ฉํ๋ค.
๐โ POINT ๐โ
โ๏ธ ๋น๊ต ์์๋ === (์ผ์น ์ฐ์ฐ์)๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ ํ์ ์ค๋ฅ๋ฅผ ๋ฐฉ์งํ๋ค. โ๏ธ
โ๏ธ % (๋๋จธ์ง ์ฐ์ฐ์)๋ ์ง์/ํ์, ๋ฐฐ์ ํ๋จ์ ๋งค์ฐ ์ ์ฉํ๋ค. โ๏ธ
โ๏ธ ๋ ผ๋ฆฌ ์ฐ์ฐ์๋ฅผ ํ์ฉํ๋ฉด ๋ณต์กํ ์กฐ๊ฑด๋ฌธ๋ ๊ฐ๊ฒฐํ๊ฒ ํํํ ์ ์๋ค. โ๏ธ
๐ ์ฃผ์ ์ฐ์ฐ์ ์์ฝํ ๐
| ์ข ๋ฅ | ์ฐ์ฐ์ |
| ์ฐ์ | +, -, *, /, %, ** |
| ํ ๋น | =, +=, -=, *=, /= |
| ๋น๊ต | ==, ===, !=, !==, >, <, >=, <= |
| ๋ ผ๋ฆฌ | &&, ||, ! |
| ์ฆ๊ฐ | ++, -- |
| ์ผํญ | ์กฐ๊ฑด์ ? ๊ฐ1 : ๊ฐ2 |
| ํ์ | typeof |
โ๏ธ ์ค์ ์์ ์ฝ๋ โ๏ธ
// 1. ์ฐ์ ๋ฐ ๋์
์ฐ์ฐ
let score = 10;
score += 5; // score๋ 15
console.log(score % 2); // 1 (๋๋จธ์ง ์ฐ์ฐ์ผ๋ก ํ์์์ ํ์ธ)
// 2. ๋น๊ต ์ฐ์ฐ (์๊ฒฉํ ๋น๊ต)
console.log(10 == "10"); // true (๊ฐ๋ง ๊ฐ์ผ๋ฉด ๋จ)
console.log(10 === "10"); // false (์๋ฃํ์ด ๋ค๋ฆ: ์ซ์ vs ๋ฌธ์์ด)
// 3. ๋
ผ๋ฆฌ ์ฐ์ฐ
let isAdult = true;
let hasTicket = false;
// ์ฑ์ธ์ด๊ณ ํฐ์ผ๋ ์์ด์ผ ์
์ฅ ๊ฐ๋ฅ
console.log(isAdult && hasTicket); // false
// ์ฑ์ธ์ด๊ฑฐ๋ ํฐ์ผ์ด ์์ผ๋ฉด ์
์ฅ ๊ฐ๋ฅ
console.log(isAdult || hasTicket); // true
'<script>' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| Truthy and Falsy (์ฐธ ๊ฐ์ ๊ฐ & ๊ฑฐ์ง ๊ฐ์ ๊ฐ) (0) | 2026.05.28 |
|---|---|
| Conditional statement (์กฐ๊ฑด๋ฌธ) (0) | 2026.05.28 |
| Data Types (๋ฐ์ดํฐ ํ์ ) (0) | 2026.05.28 |
| Variables (๋ณ์) (0) | 2026.05.28 |
| HTML์์ JavaScript๋ฅผ ๋ฐฐ์นํ๋ ๊ฐ์ฅ ์ข์ ์์น (0) | 2026.05.26 |
