λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

javascript/ν΄λ¦°μ½”λ“œ

[JS] ν΄λ¦°μ½”λ“œ (undefined, null) κ°œλ…, 차이점

728x90
undefined , null => 값이 μ—†κ±°λ‚˜ μ •μ˜λ˜μ§€ μ•Šμ€κ²ƒ(μ—†λ‹€λŠ” 것을 λͺ…μ‹œμ μœΌλ‘œ ν‘œν˜„ν•œ 것)
undefined -> NaN null -> 0
type undefined type Object
!null // true
!undefined // true
!!null //false

null === false // false
!null === true // true

undefined == null // true
undefined === null // false
!undefined === !null // true

//undefined : μ„ μ–Έν–ˆμ§€λ§Œ 값은 μ •μ˜λ˜μ§€ μ•Šκ³  ν• λ‹Ήλ˜μ§€μ•ŠμŒ.
let a;
let b=null;
typeof a // undefined
typeof b // object

//null은 숫자적으둜 ν‘œν˜„ν• λ•Œ '0'이닀.
null + 123 // 123
undefined + 10 // NaN

'null' κ³Ό  'undefined' λΉ„μŠ·ν•˜κ³  ν—·κ°ˆλ¦¬κΈ° λ•Œλ¬Έμ—,

νŒ€μ—μ„œ 빈 값을 null or undefined둜 μ •ν• μ§€ μ„ νƒν•΄μ„œ ν†΅μΌν•˜λŠ” 것이 μ’‹λ‹€!

728x90