获取变量数据类型

获取检测变量的数据类型typeof

typeof可以用来获取检测变量的数据类型

var num = 10;
console.log(typeof num);  //number
var str = '芜湖';
console.log(typeof str);  //string
var flag = true;
console.log(typeof flag); //boolean
var vari = undefined;
console.log(typeof vari); //undefined
var timer = null;
console.log(typeof timer); //object
// prompt 取过来的值是 字符型的
var age = prompt('请输入您的年龄');
console.log(age);
console.log(typeof age);

字面量

字面量是在源代码中一个固定值的表示法,通俗来说,就是字面量表示如何表达这个值。

  • 数字字面:8,9,10
  • 字符串字面量:'芜湖起飞',"从南到北"
  • 布尔值面量:true,false
最后修改:2023 年 02 月 14 日
如果觉得我的文章对你有用,请随意赞赏