๐Ÿš€ Languege/JavaScript

[๊ธฐ๋ณธ ๋ฌธ๋ฒ•] ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ž๋ฃŒํ˜•/Array/Object

mini_world 2021. 4. 15. 00:18

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ๋™์ ์–ธ์–ด๋กœ ๋ณ€์ˆ˜ ํƒ€์ž…์„ ๋ฏธ๋ฆฌ ์„ ์–ธํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. 
์–ด๋–ค ๋ฐ์ดํ„ฐ ํƒ€์ž…์ด ์žˆ๋Š”์ง€ ํ•œ๋ฒˆ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค.๐Ÿค—


1. ๊ธฐ๋ณธ ์ž๋ฃŒํ˜•

1) Boolean

- true/false ๋‘๊ฐ€์ง€ ๊ฐ’์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
- ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์‹œ ๋…ผ๋ฆฌ์ ์œผ๋กœ ์ฐธ/๊ฑฐ์ง“์„ ํŒ๋‹จํ•  ํ•„์š”๊ฐ€ ์žˆ์„๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
- ์˜ˆ) ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๊ฐ’์ด 10 ์ด์ƒ์ด๋ฉด ์ฐธ, ์•„๋‹ˆ๋ฉด ๊ฑฐ์ง“ (๋น„๊ต์—ฐ์‚ฐ์ž) 

const boolT = true;
const boolF = false;
console.log(boolT,boolF);

/*
์‹คํ–‰ ๊ฒฐ๊ณผ
===============================
true false
===============================
*/

 

2) Null

- ๋ณ€์ˆ˜๊ฐ’์ด ๋น„์–ด์žˆ๋‹ค๋Š” ํ‘œ๊ธฐ๋ฅผ ํ•˜๊ธฐ ์œ„ํ•œ ์ž๋ฃŒํ˜•์ž…๋‹ˆ๋‹ค.
- undefined ํ˜•์€ ๋ฉ”๋ชจ๋ฆฌ์— ์•„๋ฌด๋Ÿฐ ๋ฐ์ดํ„ฐ๊ฐ€ ์—†์ง€๋งŒ, null ์ž๋ฃŒํ˜•์˜ ๊ฒฝ์šฐ "Null"ํ˜•์ด ๊ฐ’์œผ๋กœ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.

let nullType = null;
console.log(nullType)


/*
์‹คํ–‰ ๊ฒฐ๊ณผ
===============================
null
===============================
*/

3) Undefined

- ๋ณ€์ˆ˜๋ช…๋งŒ ์„ ์–ธ๋˜์–ด์žˆ๊ณ , ๋ณ€์ˆ˜๊ฐ’์ด ์—†๋Š” ์ž๋ฃŒํ˜•์ž…๋‹ˆ๋‹ค.
- ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์€ ํ™•๋ณด ๋˜์–ด์žˆ์ง€๋งŒ ์‹ค์ œ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด๊ฐ€์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. 

let undefinedType
console.log(undefinedType)

//๋ณ€์ˆ˜๊ฐ’์— ์ง์ ‘ undefined๋ฅผ ๋„ฃ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
// let undefinedType = undefined;

/*
์‹คํ–‰ ๊ฒฐ๊ณผ
===============================
undefined
===============================
*/

 

4) Number

- ์ˆซ์ž ์ž๋ฃŒํ˜•์ž…๋‹ˆ๋‹ค.
- ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ๋Š” ์ •์ˆ˜, ์‹ค์ˆ˜๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. (์ •ํ™•ํžˆ๋Š” ์ •์ˆ˜๋งŒ์„ ์œ„ํ•œ ์ž๋ฃŒํ˜•์ด ์—†์Šต๋‹ˆ๋‹ค.)

const floatingType = 123123.123123;
console.log(floatingType);

/*
์‹คํ–‰ ๊ฒฐ๊ณผ
===============================
123123.123123
===============================
*/

 

5) String
- ๋ฌธ์ž ์ž๋ฃŒํ˜•์ž…๋‹ˆ๋‹ค.

const stringType = "์‚ฌ๊ณผ๋Š” ๋ง›์žˆ์–ด";
console.log(stringType);

/*
์‹คํ–‰ ๊ฒฐ๊ณผ
===============================
์‚ฌ๊ณผ๋Š” ๋ง›์žˆ์–ด
===============================
*/

 

2. Array

๋ฐฐ์—ด์€ ์ธ๋ฑ์Šค๋ฅผ ๊ฐ€์ง€๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ์ž๋ฃŒ ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค.
ํ•˜๋‚˜์˜ ๋ฐฐ์—ด์— ์—ฌ๋Ÿฌ ์ž๋ฃŒํ˜•์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ• ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

const arraySample = ["judy", 30, true, null]
console.log (arraySample)

/*
์‹คํ–‰ ๊ฒฐ๊ณผ
===============================
[ 'judy', 30, true, null ]
===============================
*/

๋ฐฐ์—ด์˜ ๋ฐ์ดํ„ฐ๋Š” ์ˆœ์„œ๋Œ€๋กœ ์ €์žฅ๋˜๋ฉฐ, ๋ฐ์ดํ„ฐ๋Š” ์ธ๋ฑ์Šค๋ฅผ ์ด์šฉํ•ด์„œ ์ ‘๊ทผํ•ฉ๋‹ˆ๋‹ค.

const arraySample = ["judy", 30, true, null]
console.log (arraySample[0]);
console.log (arraySample[1]);


/*
์‹คํ–‰ ๊ฒฐ๊ณผ
===============================
judy
30
===============================
*/

 

3. Object

๊ฐ์ฒด๋Š” ํ‚ค(key)์™€ ๊ฐ’(value)๋กœ ๊ตฌ์„ฑ๋œ Property์˜ ์ง‘ํ•ฉ์ž…๋‹ˆ๋‹ค.
์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ ์ „๋ถ€ ๋‹ค ๋„ฃ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

const objectSample = {
    name: "๊น€์ดˆ๋กฑ",
    age: 30,
    nationality: "korean",
    favoriteFoods: ["๊น€์น˜","๋œ์žฅ์ฐŒ๊ฐœ","๊ณ„๋ž€ํ›„๋ผ์ด","์ŠคํŒธ๊ตฌ์ด"],
    family: [
        {
            father: "๊น€๋“์ฃผ",age: 63
        },
        {
            mom:"์ •ํ˜œ์ธ",age: 62
        },
        {
            sister:"๊น€๋‹ค์€", age:26
        }
    ],
    character: undefined
}
console.log(objectSample)

/*
์‹คํ–‰ ๊ฒฐ๊ณผ
===============================
{
  name: '๊น€์ดˆ๋กฑ',
  age: 30,
  nationality: 'korean',
  favoriteFoods: [ '๊น€์น˜', '๋œ์žฅ์ฐŒ๊ฐœ', '๊ณ„๋ž€ํ›„๋ผ์ด', '์ŠคํŒธ๊ตฌ์ด' ],
  family: [
    { father: '๊น€๋“์ฃผ', age: 63 },
    { mom: '์ •ํ˜œ์ธ', age: 62 },
    { sister: '๊น€๋‹ค์€', age: 26 }
  ],
  character: undefined
}
===============================
*/

์˜ค๋ธŒ์ ํŠธ ๋‚ด์˜ ๋ฐ์ดํ„ฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

const objectSample = {
    name: "๊น€์ดˆ๋กฑ",
    age: 30,
    nationality: "korean",
    favoriteFoods: ["๊น€์น˜","๋œ์žฅ์ฐŒ๊ฐœ","๊ณ„๋ž€ํ›„๋ผ์ด","์ŠคํŒธ๊ตฌ์ด"],
    family: [
        {
            father: "๊น€๋“์ฃผ",age: 63
        },
        {
            mom:"์ •ํ˜œ์ธ",age: 62
        },
        {
            sister:"๊น€๋‹ค์€", age:26
        }
    ],
    character: undefined
}
console.log(objectSample.family[1].age)

/*
์‹คํ–‰ ๊ฒฐ๊ณผ
===============================
62
===============================
*/

 


๊ณต์‹ํ™ˆํŽ˜์ด์ง€ :developer.mozilla.org/ko/docs/Web/JavaScript/Data_structures

 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์ž๋ฃŒํ˜• - JavaScript | MDN

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์ž๋ฃŒํ˜• ๋ชจ๋“  ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋Š” ๋‚ด์žฅ ์ž๋ฃŒํ˜•์ด ์žˆ์ง€๋งŒ, ์ข…์ข… ์ด๋Ÿฌํ•œ ๋‚ด์žฅ ์ž๋ฃŒํ˜•์€ ์–ธ์–ด๋งˆ๋‹ค ๋‹ค๋ฅด๋‹ค. ์ด ๋ฌธ์„œ์—์„œ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ๋‚ด์žฅ ์ž๋ฃŒํ˜•๊ณผ, ๋‚ด์žฅ ์ž๋ฃŒํ˜•์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜

developer.mozilla.org

 

728x90