2021-11-30 TIL

๋””์•„ยท2021๋…„ 11์›” 30์ผ
0

๋ฉ‹์‚ฌFE์Šค์ฟจ1๊ธฐ

๋ชฉ๋ก ๋ณด๊ธฐ
12/20
post-thumbnail

๐Ÿฆ Day23

๐Ÿ’ป ์˜ค๋Š˜ ๋ณด๊ณ  ๋“ฃ๊ณ  ๋ฐฐ์šด ๊ฒƒ

1. object ๊ฐ’ ํ˜ธ์ถœ ๋ฐฉ๋ฒ•

// 
const member = [
      {
          name: "Tina",
          age: 24,
          gender: "female",
          position: "Front-end"
      },
      {
          name: "Rob",
          age: 31,
          gender: "male",
          position: "Back-end"
      },
      {
          name: "Hugh",
          age: 28,
          gender: "male",
          position: "Dev-ops"
      }
]

// ์ด๋ฆ„์ด Hugh์ธ ๋ฉค๋ฒ„์˜ position ๊ฐ’ ์•Œ์•„๋‚ด๊ธฐ
member[2].position
// Dev-ops

2. undefined, null, NaN์˜ ์ž๋ฃŒํ˜•

  • undefined: undefined
  • null: object
  • NaN : number

3. ๋ฐ˜๋ณต๋ฌธ

3-1. while๋ฌธ

//while๋ฌธ์œผ๋กœ ๊ตฌ๊ตฌ๋‹จ ์ถœ๋ ฅํ•˜๊ธฐ
let i = 2;
let j = 1;

while(i<10){
  while(j<10){
    console.log(`${i} X ${j} = ${i*j}`)
    j++
  }
  i++
  j = 1
}
/*
2 X 1 = 2
2 X 2 = 4
2 X 3 = 6
2 X 4 = 8
2 X 5 = 10
2 X 6 = 12
2 X 7 = 14
2 X 8 = 16
2 X 9 = 18
3 X 1 = 3
3 X 2 = 6
3 X 3 = 9
3 X 4 = 12
3 X 5 = 15
3 X 6 = 18
3 X 7 = 21
3 X 8 = 24
3 X 9 = 27
4 X 1 = 4
4 X 2 = 8
4 X 3 = 12
4 X 4 = 16
4 X 5 = 20
4 X 6 = 24
4 X 7 = 28
4 X 8 = 32
4 X 9 = 36
5 X 1 = 5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
5 X 5 = 25
5 X 6 = 30
5 X 7 = 35
5 X 8 = 40
5 X 9 = 45
6 X 1 = 6
6 X 2 = 12
6 X 3 = 18
6 X 4 = 24
6 X 5 = 30
6 X 6 = 36
6 X 7 = 42
6 X 8 = 48
6 X 9 = 54
7 X 1 = 7
7 X 2 = 14
7 X 3 = 21
7 X 4 = 28
7 X 5 = 35
7 X 6 = 42
7 X 7 = 49
7 X 8 = 56
7 X 9 = 63
8 X 1 = 8
8 X 2 = 16
8 X 3 = 24
8 X 4 = 32
8 X 5 = 40
8 X 6 = 48
8 X 7 = 56
8 X 8 = 64
8 X 9 = 72
9 X 1 = 9
9 X 2 = 18
9 X 3 = 27
9 X 4 = 36
9 X 5 = 45
9 X 6 = 54
9 X 7 = 63
9 X 8 = 72
9 X 9 = 81
*/

3-2. for๋ฌธ

let arrFruit = ['apple', 'banana', 'mandarine','blueberries']

//forEach
arrFruit.forEach((fruit, idx) => console.log(idx, fruit))
/*
0 'apple'
1 'banana'
2 'mandarine'
3 'blueberries'
*/

// for ... in
// ๋ฐฐ์—ด์˜ ๊ฐ ์ธ๋ฑ์Šค๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ ์ธ๋ฑ์Šค ์ถœ๋ ฅ
for (var fruit in arrFruit){
  console.log(fruit, arrFruit[fruit]);
}
/*
0 apple
1 banana
2 mandarine
3 blueberries
*/

//for ... of
// ๋ฐฐ์—ด์˜ ๊ฐ ์ธ๋ฑ์Šค ์ˆœํšŒํ•˜๋ฉฐ ํ•ด๋‹น ์ธ๋ฑ์Šค์˜ ์š”์†Œ ์ถœ๋ ฅ
for (var fruit of arrFruit){
  console.log(fruit);
}
/*
apple
banana
mandarine
blueberries
*/

4. ํ•จ์ˆ˜

function add(x, y){
  // ์—ฌ๊ธฐ์„œ x์™€ y๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜(parameter)๋ผ๊ณ  ํ•œ๋‹ค. ์™ธ๋ถ€์—์„œ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ ๋„˜๊ฒจ๋ฐ›๋Š” ์ธ์ž๋ฅผ ์ „๋‹ฌ๋ฐ›๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.
  return x + y
}

add(3,5) // 8
// ์—ฌ๊ธฐ์„œ 3,5๋Š” ์ „๋‹ฌ์ธ์ž(argument)๋ผ๊ณ  ํ•œ๋‹ค. ํ•จ์ˆ˜์— ์ด ๊ฐ’์ด ๋„˜๊ฒจ์ ธ์„œ ํ•จ์ˆ˜ ๋‚ด๋ถ€ ๊ณ„์‚ฐ์‹์ด ์ˆ˜ํ–‰๋œ๋‹ค.

4-1. ์ฝœ๋ฐฑํ•จ์ˆ˜

function add(x,y){
  return x+y
}
function mul(x,y){
  return x*y
}

function cal(a,b){
  return a(10, 10) + b(10, 10);
}

cal(add, mul) // ์ฝœ๋ฐฑํ•จ์ˆ˜

4-2. ํ™”์‚ดํ‘œํ•จ์ˆ˜

function add(x,y){
  return x+y
}
// ์œ„์˜ addํ•จ์ˆ˜๋ฅผ ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋กœ ํ‘œํ˜„
let add = ((x,y) => x+y)

4-3. ๊ธฐ๋ช… ํ•จ์ˆ˜

  // ๊ธฐ๋ช… ํ•จ์ˆ˜
  let aa = function sum(x, y) {
      return x + y
  }

  // ์ต๋ช… ํ•จ์ˆ˜์ธ๊ฒƒ ๊ฐ™์ง€๋งŒ ๋ฐ”๋€œ
  let bb = function(x, y) {
      return x + y
  }
  // ES5์—์„œ๋Š” ๋นˆ ๋ฌธ์ž์—ด์ด์—ˆ๋Š”๋ฐ ES6์—์„œ name ๊ฐ’์„ ๊ฐ€์ง€๋Š” ๊ฒƒ์œผ๋กœ ๋ฐ”๋€Œ์—ˆ์Šต๋‹ˆ๋‹ค.
  let cc = (x, y) => x + y;

4-4. ์ต๋ช… ํ•จ์ˆ˜

console.dir(function (x, y) {return x + y;})
profile
์–ผ๋ ˆ๋ฒŒ๋ ˆ ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž

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