Nhảy tới nội dung

Kiểu null

null trong JavaScript là giá trị biểu thị không có giá trị.

null literal

null literal trong JavaScript là null.

ts
const x = null;
ts
const x = null;

Type annotation của null

Để type annotation cho null trong TypeScript, sử dụng null.

ts
const x: null = null;
ts
const x: null = null;

Lưu ý về toán tử typeof

JavaScript có toán tử typeof để kiểm tra type của giá trị. Cần lưu ý khi dùng typeof với null sẽ trả về "object".

ts
console.log(typeof null);
"object"
ts
console.log(typeof null);
"object"

Chi tiết về toán tử typeof xem tại phần "Toán tử typeof".

📄️ Toán tử typeof

Toán tử typeof của JavaScript cho phép kiểm tra kiểu của giá trị.