javaScript学习笔记之typeof, null, 和 undefined之间的对比
生活随笔
收集整理的這篇文章主要介紹了
javaScript学习笔记之typeof, null, 和 undefined之间的对比
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
typeof 操作符
你可以使用 typeof 操作符來檢測變量的數據類型。
null
在 JavaScript 中 null 表示 "什么都沒有"。
null是一個只有一個值的特殊類型。表示一個空對象引用。
undefined
在 JavaScript 中, undefined 是一個沒有設置值的變量。
typeof 一個沒有值的變量會返回 undefined。
typeof 操作符來檢測變量的數據類型
typeof "John" // 返回 string typeof 3.14 // 返回 number typeof false // 返回 boolean typeof [1,2,3,4] // 返回 object typeof {name:'John', age:34} // 返回 object代碼如下:
<!DOCTYPE html> <html><head><meta charset="utf-8"><title>typeof, null, 和 undefined</title></head><body><p> typeof 操作符返回變量或表達式的類型</p><!-- <p>null是一個對象</p> --><p總結
以上是生活随笔為你收集整理的javaScript学习笔记之typeof, null, 和 undefined之间的对比的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: javaScript学习笔记之break
- 下一篇: 单点登陆的三种实现方式