- Published on
๐ JS(4)-๋๋ฆผ์ฝ๋ฉ ๊ฐ์ ์ ๋ฆฌ
- ๊ธ์ด์ด
๐ ๋ชฉ์ฐจ
โจ ์๋ฐ์คํฌ๋ฆฝํธ ๊ธฐ์ด ๊ฐ์ (ES5+): ๊ฐ์ด ๋ ธํธ๋ฅผ ์์ฑํ๋ฉฐ ๋ฐฐ์์ ๐
๐๐ป
- ์๋ฐ์คํฌ๋ฆฝํธ์ ์ญ์ฌ์ ๋ชฉ์ ๋ฐ ๋ํฅ
- ์๋ฐ์คํฌ๋ฆฝํธ ๋์์๋ฆฌ
์ฐ์ฐ.๋ฐ๋ณต๋ฌธ(4๊ฐ)
๋ค๋ฅธ ์ธ์ด์์๋ ๊ณตํต์ ์ผ๋ก ์ธ ์ ์๋ operators~
1. String concatenation (๋ฌธ์ ์ฐ๊ฒฐ)
console.log('my' + ' cat');
console.log('1' + 2);
console.log(`string literals: 1 + 2 = ${1 + 2}`);
2. Numeric operators (์ซ์ ์ฐ์ฐ์)
console.log(1 + 1); // add
console.log(1 - 1); // substract
console.log(1 / 1); // divide
console.log(1 * 1); // multiply
console.log(5 % 2); // remainder
console.log(2 ** 3); // exponentiation
++
, --
operators
3. let counter = 2;
const preIncrement = ++counter;
// counter = counter + 1;
// preIncrement = counter;
console.log(`preIncrement: ${preIncrement}, counter: ${counter}`);
const postIncrement = counter++;
// postIncrement = counter;
// counter = counter + 1;
console.log(`postIncrement: ${postIncrement}, counter: ${counter}`);
const preDecrement = --counter;
console.log(`preDecrement: ${preDecrement}, counter: ${counter}`);
const postDecrement = counter--;
console.log(`postDecrement: ${postDecrement}, counter: ${counter}`);
=
operators
4. let x = 3;
let y = 6;
x += y; // x = x + y;
x -= y;
x *= y;
x /= y;
<=
operators
5. console.log(10 < 6); // less than
console.log(10 <= 6); // less than or equal
console.log(10 > 6); // greater than
console.log(10 >= 6); // greater than or equal
||
, &&
, !
)(๋
ผ๋ฆฌ ์ฐ์ฐ์)
๋น๊ต ์ฐ์ฐ์๋ true๊ฐ์ ์ฐพ์ผ๋ฉด ๊ทธ ๋ค๋ก๋ ์ฐ์ฐ์ ํ์ง ์๋๋ค.
6. Logical operators (๊ทธ๋ฌ๋ฏ๋ก ๊ฐ๋จํ value๊ฐ์ ์ ์ผ ๋จผ์ ๋๋๊ฒ ํจ์จ์ ์ด๋ค. ๋ฌด๊ฑฐ์ด expression์ ๋งจ ๋ค์ ๋๊ธฐ~!
==
, ===
)
7. Equality Operators (== loose equality, with type conversion ํ์ ๊น์ง๋ ๋น๊ตํ์ง ์๋๋ค.
=== strict equality, no type conversion ํ์ ๊น์ง ๋น๊ตํ๋ค!
object equality by reference
const ellie1 = { name: 'ellie' };
const ellie2 = { name: 'ellie' }; //ellie1๊ณผ ellie2๋ ์๋ก ๋ค๋ฅธ ๋ ํผ๋ฐ์ค๋ฅผ ๊ฐ๋ฆฌํจ๋ค.
const ellie3 = ellie1;
console.log(ellie1 == ellie2); //reference๊ฐ์ด ๋ค๋ฅด๋ฏ๋ก false
console.log(ellie1 === ellie2); //reference๊ฐ์ด ๋ค๋ฅด๋ฏ๋ก false
console.log(ellie1 === ellie3); //reference๊ฐ์ ellie1์ ํ ๋นํ ๊ฒ์ด๋ผ true
// equality - puzzler
console.log(0 == false); //๊ฐ์ด ๋ค๋ฅด๋ฏ๋ก true
console.log(0 === false); //ํ์
์ด ๋ค๋ฅด๋ฏ๋ก false
console.log('' == false); //true
console.log('' === false); //ํ์
์ด ๋ค๋ฅด๋ฏ๋ก false
console.log(null == undefined); //true
console.log(null === undefined); //ํ์
์ด ๋ค๋ฅด๋ฏ๋ก false
8. Conditional operators : if (์กฐ๊ฑด ์ฐ์ฐ์)
if
,else if
,else
9. Ternary operators (์ผํญ ์ฐ์ฐ์)
condition ? value1 : value2; ๋๋ฌด nesting์ ํ๋ฉด ๊ฐ๋ ์ฑ์ด ๋จ์ด์ง๋ฏ๋ก ๊ฐ๋จํ ๊ฒฝ์ฐ์์๋ง ์ฐ์.
10. Switch operators (switch ์ฐ์ฐ์)
switch
- case
if
๋ฌธ์ ๋๋ฌด ๋ฐ๋ณตํ๊ฒ ๋๋ฉด switch
๋ฌธ์ ์ฐ๋๊ฒ ์ข๋ค.
11. while loop (while ๋ฐ๋ณต๋ฌธ)
while () {}
()์์ ์์ด ์ฐธ์ผ ๋๋ง ์์ ์๋ ์์ ๊ณ์ ๋ฐ๋ณตํด์ ์คํ
12. do-while loop (do-while ๋ฐ๋ณต๋ฌธ)
do
๋ธ๋ญ์ ๋จผ์ ์คํํ๊ณ while
์ด ์ฐธ์ธ์ง ์๋์ง ๊ฒ์ฌ
๋ธ๋ญ์ ๋จผ์ ์คํํ๊ณ ์ถ๋ค๋ฉด ์๊ฑธ ์ด๋ค.
### 13. for loop (for ๋ฐ๋ณต๋ฌธ)
```css
//for loop, for(begin; condition; step)
for (i = 3; i > 0; i--) {
console.log(`for: ${i}`);
}
for (let i = 3; i > 0; i = i - 2) {
// inline variable declaration
console.log(`inline variable for: ${i}`);
}
14. nested loop (์ค์ฒฉ ๋ฐ๋ณต๋ฌธ)
์คํ ์๋๊ฐ ๋๋ ค์ ๋๋๋ก ์ฐ์ง ์๋๊ฒ ์ข๋ค.
for (let i = 0; i < 10; i++) {
for (let j = 0; j < 10; j++) {
console.log(`i: ${i}, j:${j}`);
}
}
break, continue
continue
๋ if๋ฌธ์ด ์ฐธ์ผ ๋ ๋์ด๊ฐ๋ ๊ฒ.