/**
* 五种基本数据类型:string, number, boolean, null, undefined
*/
// undefined
// 声明变量foo,未声明变量bar
var foo;
console.log(`typeof foo: ${foo}`, `typeof bar: ${bar}`); // typeof foo: undefined typeof bar: undefined
if (foo === undefined) { // foo全等于undefined
console.log('foo全等于undefined');
} else {
console.log('foo不全等于undefined');
}
if (typeof bar === 'undefined') { // bar全等于undefined
console.log('bar全等于undefined');
} else {
console.log('bar不全等于undefined');
}
// typeof 返回字符串类型
console.log(`typeof (typeof foo): ${typeof (typeof foo)}`); // typeof (typeof foo): string
// 定义函数f()但没有函数体,默认为undefined
function f() { }
console.log(`typeof f(): ${typeof f()}`, `f() === undefined: ${f() === undefined}`); // typeof f(): undefined f() === undefined: true // null
console.log(`typeof Null: ${typeof Null}`); // typeof Null: undefined
console.log(`typeof null: ${typeof null}`); // typeof null: object // string
// 常用转义字符
// ---------------------------------------------------------------------------
// \n 换行
// \t 制表符
// \b 空格
// \r 回车
// \f 换页符
// \\ 反斜杠
// \' 单引号
// \" 双引号
// \0nnn 八进制代码 nnn 表示的字符(n 是 0 到 7 中的一个八进制数字)
// \xnn 十六进制代码 nn 表示的字符(n 是 0 到 F 中的一个十六进制数字)
// \unnnn 十六进制代码 nnnn 表示的 Unicode 字符(n 是 0 到 F 中的一个十六进制数字)
// ---------------------------------------------------------------------------
var foo = 'hello';
console.log(`typeof foo: ${typeof foo}`); // typeof foo: string // boolean
var right = true,
wrong = false;
console.log(`typeof right: ${typeof right}, typeof wrong: ${typeof wrong}`); // typeof right: boolean, typeof wrong: boolean // number
// 整型
var foo = 100;
console.log(`typeof foo: ${typeof foo}`); // typeof foo: number
// 八进制
var foo = 017;
console.log(foo); //
// 十六进制
var foo = 0xAB;
console.log(foo) //
// 浮点数
var foo = 23.01;
console.log(foo); // 23.01
// 最大值
console.log(`Number.MAX_VALUE = ${Number.MAX_VALUE}`); // Number.MAX_VALUE = 1.7976931348623157e+308
// 最小值
console.log(`Number.MIN_VALUE = ${Number.MIN_VALUE}`); // Number.MIN_VALUE = 5e-324
// 正无穷大
console.log(`Number.POSITIVE_INFINITY = ${Number.POSITIVE_INFINITY}`); // Number.POSITIVE_INFINITY = Infinity
// 负无穷大
console.log(`Number.NEGATIVE_INFINITY = ${Number.NEGATIVE_INFINITY}`); // Number.NEGATIVE_INFINITY = -Infinity
// isFinite 验证是有限数字
var foo = Number.POSITIVE_INFINITY,
bar = foo * 3;
if (isFinite(bar)) { // bar是无穷大数字
console.log('bar是有限数字');
} else {
console.log('bar是无穷大数字');
}
// NaN 不是一个数字,特殊数值,不可用于直接计算
var foo = 'hello';
if (isNaN(foo)) { // foo不是数字
console.log('foo不是数字');
} else {
console.log('foo是数字');
}

最新文章

  1. socket.io简单入门(一.实现简单的图表推送)
  2. JavaScript Json对象和Json对象字符串的关系 jsonObj<->JsonString
  3. php 字符串和数字比较一些问题
  4. doPost()和doGet()
  5. 尚学堂Spring视频教程(五):Spring AOP
  6. 提高tomcat的并发能力
  7. Application 统计在线人数
  8. javascript调用oc的方法
  9. IOS 学习笔记 2015-03-22 OC-API-日期
  10. UIView类绘图出现错误提示
  11. Javascript基础 - js中曾经忽略的知识点
  12. python 之走坑的道路
  13. 中文代码示例之Vuejs入门教程(一)
  14. 【js】js中判断对数是否为空
  15. 【RL-TCPnet网络教程】第16章 UDP用户数据报协议基础知识
  16. DAY18 常用模块(二)
  17. 20175325 MyCP (课下作业,必做)
  18. C#基础知识总结(五)
  19. ES6 基础
  20. AbatorForEclipse插件使用总结

热门文章

  1. django报错
  2. 【LeetCode+51nod】股票低买高卖N题
  3. [CentOS]安装软件:/lib/ld-linux.so.2: bad ELF interpreter 解决
  4. 返回结果的 HTTP 状态 码
  5. Flutter-tabbar切換
  6. webRTC脱坑笔记(三)— webRTC API之RTCPeerConnection
  7. PHP数据如何向上取整
  8. flutter图片组件
  9. zenoss(智能监控软件)
  10. LG1440 求 m 区间内的最小值