μλ°μ€ν¬λ¦½νΈλ λμ μΈμ΄λ‘ λ³μ νμ
μ 미리 μ μΈν νμκ° μμ΅λλ€.
μ΄λ€ λ°μ΄ν° νμ
μ΄ μλμ§ νλ² νμΈν΄λ΄
λλ€.π€
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