iPod Video White

πŸ““ TIL

[220418] JS data type

k_m_jin 2022. 4. 18. 23:00

JS 데이터(μžλ£Œν˜•, Date Type)

μ›μ‹œν˜•

  1. 문자
  2. 숫자
  3. 뢈린
  4. null
  5. undefined
  6. 심볼
  7. ν°μ •μˆ˜(BigInt)

μ°Έμ‘°ν˜•

  1. λ°°μ—΄
  2. 객체
  3. ν•¨μˆ˜

문자

λ”°μ˜΄ν‘œλ‘œ λ¬Άμ—¬ μžˆμ–΄μ•Ό 함!

"Heropy"
'heropy'
`heropy`

숫자

NaN : 숫자둜 ν‘œμ‹œκ°€ λΆˆκ°€! (μˆ«μžλ°μ΄ν„°)
NaN

boolean

true
false

null

값이 μ—†μŒμ„ λͺ…μ‹œμ μœΌλ‘œ λ‚˜νƒ€λ‚Ό λ•Œ μ“°λŠ” κ°’(데이터)

undefined

값이 ν• λ‹Ήλ˜μ§€ μ•Šμ€ μƒνƒœλ₯Ό μ•”μ‹œμ μœΌλ‘œ λ‚˜νƒ€λƒ„

심볼

μœ μΌν•œ μ‹λ³„μž(ID) 데이터 이름을 λ§Œλ“€ λ–Ό μ‚¬μš©

const s = Symbol('hello world!')
const user = {
	name: kmjin
    [s]: 92
}

console.log(user.name)
console.log(user[s])

BigInt

큰 μ •μˆ˜ (Integer)

123n

λ°°μ—΄

객체

ν•¨μˆ˜

ν˜•λ³€ν™˜

== λ™λ“±μ—°μ‚°μž) : ν˜•λ³€ν™˜ν•΄μ„œ 비ꡐ함 (μ‚¬μš©ν•˜μ§€λ§κ²ƒ)

=== (일치 μ—°μ‚°μž) : λ©”λͺ¨λ¦¬ μ£Όμ†Œλ₯Ό 비ꡐ

truthy & falsy

falsy

false
null
undefined
0
-0
NaN
0n
'' // 곡백이 μžˆλ‹€λ©΄ truthy

μžλ£Œν˜• 확인

  1. typeof (null array λŠ” λΆˆκ°€)
  2. Array.isArray({})
  3.  
  4. Object.protptype.toString.call
function checkType(parameter){
  return Object.prototypw.toString.call(paremeter).slice()
}
console.log(checkType(argument))

λ³€μˆ˜

  1. const
    • scope : block level
    • μž¬ν• λ‹Ή : x
    • 쀑볡 μ„ μ–Έ : x
    • Hoisting : x
    • μ „μ—­ 등둝 : x
  2. let
    • scope : block level
    • μž¬ν• λ‹Ή : o
    • 쀑볡 μ„ μ–Έ : x
    • Hoisting : x
    • μ „μ—­ 등둝 : x
  3. var
    • scope : function level
    • μž¬ν• λ‹Ή : o
    • 쀑볡 μ„ μ–Έ : o
    • Hoisting : x
    • μ „μ—­ 등둝 : O
  • Hoisting : μ„ μ–ΈλΆ€λ₯Ό μœ νš¨λ²”μœ„ μ΅œμƒμœ„λ‘œ λŒμ–΄μ˜¬λ €μ§€λŠ” ν˜„μƒ
  • μ „μ—­ (Global) μ„ μ–Έμ‹œ μ „μ—­ 객체(window)의 μ†μ„±μœΌλ‘œ 등둝
  • 일단 const 둜 μ“°κ³  μž¬ν• λ‹Ήμ΄ ν•„μš”ν•΄μ§€λ©΄ let

ν•¨μˆ˜

μ„ μ–Έκ³Ό ν‘œν˜„

//ν•¨μˆ˜ μ„ μ–Έ
function abc() {

}
//ν•¨μˆ˜ ν‘œν˜„ 
const abc = function () {

}
  1. ν•¨μˆ˜ μ„ μ–Έ
    • ν˜Έμ΄μŠ€νŒ… 0
  2. ν•¨μˆ˜ ν‘œν˜„
    • 이름이 μ—†κ³  κ°’μœΌλ‘œ μ‚¬μš©λ˜λŠ” ν•¨μˆ˜
    • ν˜Έμ΄μŠ€νŒ… 0
λ°˜μ‘ν˜•

'πŸ““ TIL' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

[220421] μ—°μ‚°μž/if /switch  (0) 2022.04.22
[220419] export / import / lodash / Json  (0) 2022.04.19
[220417] Data type / λ‚΄μž₯ λ©”μ†Œλ“œ  (0) 2022.04.18
[220415] switch statement  (0) 2022.04.15
[220412] grid  (0) 2022.04.13