Data Types

1. μˆ«μžν˜•

  • μ–΄λŠ μˆ«μžλ“  0으둜 λ‚˜λˆ„λ©΄ λ¬΄ν•œλŒ€

    console.log(1 / 0); // Infinity
  • Infinityλ₯Ό 직접 참쑰도 κ°€λŠ₯

    console.log(Infinity); // Infinity
  • NaN은 계산 쀑 μ—λŸ¬κ°€ λ°œμƒν–ˆλ‹€λŠ” 의미이며, 좔가연산해도 κ²°κ΅­ NaN λ°˜ν™˜λ¨

    console.log("숫자 μ•„λ‹˜" / 2); // NaN

2. BigInt

  • μžλ°”μŠ€ν¬λ¦½νŠΈμ—μ„œλŠ” 일정 μˆ˜μ€€μœΌλ‘œ ν¬κ±°λ‚˜ μž‘μ€ κ°’ μ΄ν•˜λ‘œλŠ” μˆ«μžν˜•μœΌλ‘œ λ‚˜νƒ€λ‚Ό 수 μ—†μ§€λ§Œ, 길이에 상관없이 μ •μˆ˜ λ¦¬ν„°λŸ΄ 끝에 n을 뢙이면 λ§Œλ“€ 수 있음.

    const bigInt = 123456789123456789n;

3. λ¬Έμžν˜•

  • λ”°μ˜΄ν‘œμ—λŠ” μ„Έ κ°€μ§€κ°€ 있음

    let str = "Hello"; // 큰 λ”°μ˜΄ν‘œ
    let str2 = 'Ella Yeonsu Choi'; // μž‘μ€ λ”°μ˜΄ν‘œ
    let phrase = `Nice to meet you`; // λ°±ν‹±
  • λ°±ν‹±μœΌλ‘œ λ³€μˆ˜λŠ” ν‘œν˜„μ‹μ„ 감싼 ν›„, ${...} μ•ˆμ— λ„£μ–΄μ£Όλ©΄, μ›ν•˜λŠ” λ³€μˆ˜λ‚˜ ν‘œν˜„μ‹μ„ λ¬Έμžμ—΄ 쀑간에도 넣을 수 있음 (큰 λ”°μ˜΄ν‘œλ‚˜ μž‘μ€ λ”°μ˜΄ν‘œλŠ” ν™•μž₯ κ°€λŠ₯을 μ§€μ›ν•˜μ§€ μ•ŠμŒ)

    let name = "Ella"
    
    // λ³€μˆ˜λ₯Ό λ¬Έμžμ—΄ 쀑간에 μ‚½μž…
    console.log(`Hello, ${name}!`) // Hello, Ella!
    
    // ν‘œν˜„μ‹μ„ λ¬Έμžμ—΄ 쀑간에 μ‚½μž…
    console.log(`the result is ${1 + 2}`); // the result is 3

4. Booleanν˜•

  • true, false 두 κ°€μ§€ κ°’ 밖에 μ—†μœΌλ©°, 비ꡐ κ²°κ³Όλ₯Ό μ €μž₯ν•  λ•Œλ„ μ‚¬μš©λ¨

    let isGreater = 4 > 1;
    console.log(isGreater); // true

5. null κ°’

  • μœ„μ˜ μžλ£Œν˜• 쀑 μ–΄λŠ μžλ£Œν˜•μ—λ„ μ†ν•˜μ§€ μ•ŠλŠ” 값이며, μ˜€λ‘œμ§€ null κ°’λ§Œ ν¬ν•¨ν•˜λŠ” λ³„λ„μ˜ μžλ£Œν˜•μž„.

  • μ˜λ―ΈλŠ” μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” (nothing) κ°’, λΉ„μ–΄μžˆλŠ”(empty) κ°’, μ•Œ 수 μ—†λŠ”(unknown) 값을 λͺ…μ‹œμ μœΌλ‘œ λ‚˜νƒ€λƒ„.

    let age = null; // μ•Œ 수 μ—†μŒ, λΉ„μ–΄μžˆμŒ

6. undefined κ°’

  • nullκ³Ό λ§ˆμ°¬κ°€μ§€λ‘œ, '값이 ν• λ‹Ήλ˜μ§€ μ•Šμ€ μƒνƒœ'λ₯Ό μ•”μ‹œμ μœΌλ‘œ λ‚˜νƒ€λ‚΄λ©°, λ³€μˆ˜λ₯Ό μ„ μ–Έν–ˆμœΌλ‚˜ 값이 ν• λ‹Ήλ˜μ§€ μ•Šμ•˜μ„ λ•Œ ν•΄λ‹Ή λ³€μˆ˜μ— undefinedκ°€ 할당됨

    let age; // λ³€μˆ˜λ₯Ό μ„ μ–Έν–ˆμœΌλ‚˜ λ³€μˆ˜λ₯Ό ν• λ‹Ήν•˜μ§€ μ•ŠμŒ
    console.log(age); // 'undefined'
  • λ³€μˆ˜μ— undefinedλ₯Ό ν• λ‹Ήν•˜λŠ” 것도 κ°€λŠ₯ν•˜λ‚˜, 직접 할당은 κΆŒν•˜μ§€ μ•Šκ³  μ΄λ•ŒλŠ” null μ‚¬μš© ꢌμž₯ν•˜κ³  λ³€μˆ˜μ˜ μ΄ˆκΈ°κ°’μ„ μœ„ν•΄ μ˜ˆμ•½μ–΄λ‘œ 남겨두기.

7. 객체와 심볼

  • 객체(object)ν˜•μ„ μ œμ™Έν•œ λ‹€λ₯Έ μžλ£Œν˜•μ€ λ¬Έμžμ—΄μ΄λ“  μˆ«μžλ“  ν•œ κ°€μ§€λ§Œ ν‘œν˜„ ν•  수 있기 λ•Œλ¬Έμ— μ›μ‹œ(primitive) μžλ£Œν˜•μ΄λΌ 뢀름. 반면, κ°μ²΄λŠ” data collectionμ΄λ‚˜ λ³΅μž‘ν•œ entityλ₯Ό ν‘œν˜„ κ°€λŠ₯.

  • 심볼(symbol)ν˜•μ€ 객체의 κ³ μœ ν•œ μ‹λ³„μž(unique identifier)λ₯Ό λ§Œλ“€ λ•Œ μ‚¬μš©λ¨

8. typeof μ—°μ‚°μž

  • 인수의 μžλ£Œν˜•μ„ λ°˜ν™˜ν•˜λ©°, 두 κ°€μ§€ ν˜•νƒœμ˜ 문법 지원

    • μ—°μ‚°μž: typeof x

    • ν•¨μˆ˜: typeof(x)

    typeof undefined // 'undefined'
    typeof 0 // 'number'
    typeof 10n // 'bigint'
    typeof Symbol("id") // 'symbol'
    typeof Math // 'object'
    typeof null // 'object'
    typeof alert // 'function'
  • MathλŠ” μˆ˜ν•™ 연산을 μ œκ³΅ν•˜λŠ” *λ‚΄μž₯객체 μ΄λ―€λ‘œ 'object'κ°€ 좜λ ₯됨. 참고둜 λ‚΄μž₯κ°μ²΄λž€, μžλ°”μŠ€ν¬λ¦½νŠΈκ°€ 기본적으둜 κ°€μ§€κ³  μžˆλŠ” 객체둜 function, array, number, string 등이 ν¬ν•¨λœλ‹€.

  • null은 κ³ μœ ν•œ μžλ£Œν˜•μ„ κ°€μ§€λŠ” 특수 κ°’μœΌλ‘œ 객체가 μ•„λ‹ˆλ‚˜, ν•˜μœ„ ν˜Έν™˜μ„± μœ μ§€λ₯Ό μœ„ν•΄ μ–Έμ–΄ 자체 였λ₯˜λΌλ„ 놔둔 κ²ƒμž„.

  • typeofλŠ” ν”Όμ—°μ‚°μžκ°€ ν•¨μˆ˜λ©΄ 'function'을 λ°˜ν™˜ν•˜λ‚˜, ν•¨μˆ˜ν˜• μ΄λΌλŠ” 것은 μ—†κ³  ν•¨μˆ˜λŠ” κ°μ²΄ν˜•μ— 속함.

Last updated