1. Obtain the data type of detection variable
typeof be used to obtain detected data type of the variable
var num = 18;
console.log(typeof num) // 结果 number
Different types of return value
var num = 10;
console.log(typeof num); // number
var str = 'pink';
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);
2. literal
Literals in the source code is a fixed value represented by law, colloquially, showing how the expression is literal value.
- Digital literal: 8, 9, 10
- String literal: 'horse Programmers', "anterior end"
- Boolean literals: true, false