Home > Article > Web Front-end > JavaScript basic data types (introduction)
In JavaScript, the basic data types include the following five numbers, strings, Boolean values, null values and undefined values. (ES6 adds a new Symbol type value, which will not be introduced in this article).
Number
Integer or floating point number
var numInt = 1; var numFloat = 1.1;
String
A string is a sequence of characters representing a text value
var stringSingle = 'a'; var string = 'abscmj';
Boolean value
true / false
var t = true; var f = false;
5. undefined
undefined indicates the attribute when the variable is undefined
var x; if (x === undefined) { console.log(1) //1 } // 这里 var a 等价于 var a = undefined
null
A special keyword indicating a null value
// foo不存在,它从来没有被定义过或者是初始化过: foo; "ReferenceError: foo is not defined" // foo现在已经是知存在的,但是它没有类型或者是值: var foo = null; foo; null
The difference between undefined and null
// typeof返回数据的类型 typeof null // "object" (因为一些以前的原因而不是'null') typeof undefined // "undefined"
null means "no object", that is, there should be no value there
undefined means "missing value" , that is, there should be a value here, but it has not been defined yet
If you want to know more about JavaScript, please visit the js tutorial column!
The above is the detailed content of JavaScript basic data types (introduction). For more information, please follow other related articles on the PHP Chinese website!