Home > Web Front-end > JS Tutorial > JavaScript basic data types (introduction)

JavaScript basic data types (introduction)

青灯夜游
Release: 2019-11-23 16:01:19
forward
2112 people have browsed it

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).

JavaScript basic data types (introduction)

Number

Integer or floating point number

var numInt = 1;
var numFloat = 1.1;
Copy after login

String

A string is a sequence of characters representing a text value

var stringSingle = 'a';
var string = 'abscmj';
Copy after login

Boolean value

true / false

var t = true;
var f = false;
Copy after login

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
Copy after login

null

A special keyword indicating a null value

// foo不存在,它从来没有被定义过或者是初始化过:
foo;
"ReferenceError: foo is not defined"
// foo现在已经是知存在的,但是它没有类型或者是值:
var foo = null; 
foo;
null
Copy after login

The difference between undefined and null

// typeof返回数据的类型
typeof null        // "object" (因为一些以前的原因而不是'null')
typeof undefined   // "undefined"
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template