두 존재하지 않는 것을 나타냅니다. 그리고 이 둘을 서로 다른 데이터 타입으로 분리한 것은 끝
없는 혼란을 낳았고, 특히 초보자들이 고생하고 있습니다.
일반적인 규칙을 제시한다면,
null
은 프로그래머에게 허용된 데이터 타입이며
undefined
는
자바스크립트 자체에서 사용한다고 기억하십시오. 이 규칙이 강제는 아닙니다. 프로그래머도
언제든
undefined
값을 사용할 수는 있지만, 꼭 필요할 때만 사용하도록 주의해야 합니다. 필
자가 변수에 직접
undefined
를 할당하는 경우는, 아직 값이 주어지지 않은 변수의 동작을 고의
로 흉내 내야 할 때뿐입니다. 변수의 값을 아직 모르거나 적용할 수 없는 경우에는 대부분
null
이 더 나은 선택입니다. 사소한 것에 지나치게 신경 쓰는 것처럼 보일 테고, 어떤 면에서는 실
제로 그렇기도 합니다. 초보 프로그래머들은 불확실할 때는
null
을 사용하라고 배우니까요. 변
수를 선언하기만 하고 명시적으로 값을 할당하지
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.