null
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
시도해보기
function getVowels(str) {
const m = str.match(/[aeiou]/gi);
if (m === null) {
return 0;
}
return m.length;
}
console.log(getVowels("sky"));
// Expected output: 0
구문
js
null;
설명
null
은 리터럴로서 null
이라 씁니다. null
은 undefined
과 같이 글로벌 객체의 속성에 대한 식별자가 아닙니다. 대신 null
은 식별되지 않은 것을 표현합니다. 즉, 변수가 아무런 객체를 가리키지 않음을 표현합니다. API에서는 null
을 종종 관련된 객체가 존재하지 않을 때 그 객체 대신 사용합니다.
js
// 정의되지 않고 초기화된 적도 없는 foo
foo; //ReferenceError: foo is not defined
// 존재하지만 값이나 자료형이 존재하지 않는 foo
var foo = null;
foo; //null
null
과 undefined
의 차이
null
또는 undefined
를 검사할 때, 동등 연산자(==)와 일치 연산자(===)의 차이를 주의하세요. 동등 연산자는 자료형 변환을 수행합니다.
js
typeof null; // "object" (하위호환 유지를 위해 "null"이 아님)
typeof undefined; // "undefined"
null === undefined; // false
null == undefined; // true
null === null; // true
null == null; // true
!null; // true
isNaN(1 + null); // false
isNaN(1 + undefined); // true
명세
Specification |
---|
ECMAScript® 2025 Language Specification # sec-null-value |
브라우저 호환성
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
null |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.