Frontend/JavaScript
[ μλ°μ€ν¬λ¦½νΈ(JavaScript) ] typeof μ°μ°μμ λν΄ μμ보μ
YWTechIT
2021. 11. 3. 20:09
728x90
π typeof μ°μ°μμ λν΄ μμ보μ
β typeof μ°μ°μ
typeof
μ°μ°μλ νΌμ°μ°μμ λ°μ΄ν° νμ μ λ¬Έμμ΄λ‘ λ°ννλ€. μ΄ 7κ°μ§ λ¬Έμμ΄string
,number
,boolean
,undefined
,symbol
,object
,function
μ€ ν κ°λ₯Ό λ°ννλ€.null
μ λ°ννλ κ²½μ°λ μμΌλ©°, ν¨μμ κ²½μ°function
μ λ°ννλ€.typeof(null)
μ κ²°κ΄κ°μnull
μ΄ μλλΌobject
λ₯Ό λ°ννλλ° μ£Όμνμ. μ΄κ²μ μλ°μ€ν¬λ¦½νΈμ 첫 λ²μ§Έ λ²μ μ λ²κ·Έλ€.(typeof nullμ μμ¬) νμ§λ§ κΈ°μ‘΄ μ½λμ μν₯μ μ€ μ μκΈ° λλ¬Έμ μμ§κΉμ§ μμ λμ§ λͺ»νκ³ μλ€. λ§μ½,null
νμ μΈμ§ νμΈνκ³ μΆλ€λ©΄ μΌμΉ μ°μ°μ(===
)λ₯Ό μ¬μ©νμ¬ νμΈνμ.- μ μΈνμ§ μμ μλ³μλ₯Ό
typeof
μ°μ°μλ‘ μ°μ°ν΄λ³΄λ©΄ReferenceError
κ° λ°μνμ§ μκ³undefined
λ₯Ό λ°ννλ€.
728x90
typeof ('') // string
typeof (1) // number
typeof (NaN) // number
typeof (true) // boolean
typeof (undefined) // undefined
typeof (Symbol()) // symbol
typeof (null) // object
typeof ([]) // object
typeof ({}) // object
typeof (new Date()) // object
typeof (/test/gi) // object
typeof (function(){}) // function
let a = null
a === null // true
typeof(nothing) // undefined
reference
λ°μν