What does Javascript data type not include?
The data types of Javascript do not include Symbol. JavaScript has 6 data types, namely Undefined, Null, Boolean, Number, String and Object.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
What does Javascript’s data type not include?
##This article is based on (Advanced Programming with JavaScript (3rd Edition)) Summary
The six major data types of JavaScript (excluding Symbol)
Undefined,
Null,
Boolean,
Number,
String and
Object
are 7 in ES6 There is an additional data type Symbol, which is not covered in this article.
Undefined means undefined,
Null means empty,
Boolean represents a Boolean value,
Number represents a numerical value, and String represents a string.
Usually we can use the
typeof operator to detect the data type of a variable.
Note that typeof is an operator! Operator! Operator!The typeof operator applies the following rules:
- "undefined"
- This value is undefined.
- "boolean"
——This value is a Boolean value
- "string"
——This value is a string
- "number"
——This value is a numerical value
- "object"
——This value is an object or Null
- "function"
——This value is the function
str="I am String type":
<p style="line-height: normal;">console.log(typeof str) //"string" 注意typeof操作符的返回的结果是字符串<br/></p>
1. typeof returns
"object" for
null,
2. typeof returns
"undefined for undeclared variables "
3. typeof also returns
"undefined"
var s = null console.log(typeof s) //"object" console.log(typeof a) //"undefined", 注意变量a未声明 var b; console.log(typeof b) //"undefined", 注意变量b声明但未初始化
typeof, and we also To learn more about the specific information of the variable, we often use instanceof to determine the data type of the variable.
Undefined and
Null types have only one value, which are
undefined and
null respectively .
For
undefined, you need to remember the following two points:
- The value of a variable that has been declared but not initialized is
- undefined
(refer to the above code )
- undefined
is equal to
null
console.log(undefined == null) //true
null, you need to remember two points:
- typeof null
Returns
"object". Logically, null is a reference to object (for examples, see
typeof)
- undefined
is equal to
null
Boolean type has two values - —
true and
false.
Any data can call the Boolean function
Boolean(), which will return a Boolean value.
true | false | |
---|---|---|
true | false | |
Non-zero string | ""(empty string) | |
Non-zero numbers (including infinity) | 0 and NaN | |
Any object | null | |
Not applicable | undefined | |
Not applicable | null |
字面量 | 含义 |
---|---|
\n | 换行符 |
\t | 制表符 |
\b | 退格符 |
\r | 回车符 |
\f | 换页符 |
\ | 斜杠 |
\’ | 单引号 |
\” | 双引号 |
\xnn | x表示十六进制, n为0-F, nn表示一个字符. 如\x41表示”A” |
\unnnn | u表示Unicode, 也为十六进制. nnnn表示一个十六进制的Unicode字符 |
例如:
console.log("这是单引号: \'") //这是单引号: 'console.log("这是\n换行符")/* 这是 换行符 */console.log("这是大写字母: \x41") //这是大写字母: A
转换为字符串 toString()和String()
大部分值都有toString()方法, 因此我们可以使用这个方法.
var a = 2console.log(a.toString()) //2var b = trueconsole.log(b.toString()) //true
还可以给toString()
添加一个参数, 这个参数表示基数.
var num = 7console.log(num.toString(2)) //111console.log(num.toString(3)) //21
前面说了大部分值可以使用toString()
方法, 那么哪些值不能使用呢? 那就是null
和undefined
.
当我们需要将一个变量A转换为字符串时, 假如我们不知道变量A是否是null
和undefined
, 我们可以使用String()
函数. 这个函数可以讲任意类型的值转换为字符串. 其规则如下:
- 如果可以调用
toString()
方法则调用该方法. - 如果是
null
, 则返回"null"
- 如果是
undefined
, 则返回"undefined"
Object
Object
类型俗称对象, 对象的实例通常使用new
操作符进行创建. 对象的实例还是对象, 我们会在对象的实例中添加属性和方法.
var obj = new Object();
Object
的实例有下列基本的属性和方法:
constructor
constructor
属性保存着穿件当前对象的函数, 也叫构造函数. 如上例中的Object()
hasOwnProperty(propertyName)
这个方法用于检测当前对象实例中是否有属性名为propertyName
的属性.propertyName
必须为字符串isPrototypeOf(object)
其用于检查传入的对象object是否为当前对象实例的原型propertyIsEnumerable(propertyName)
用于检查给定的属性propertyName
是否可以用for-in
语句来枚举.propertyName
必须为字符串toLocaleString()
,toString()
,valueOf()
这三个方法都可以返回对象的字符串表示,valueOf()
还可以返回对象的数值, 布尔值表示.
可以参考这篇文章:Javascript toString()、toLocaleString()、valueOf()三个方法的区别-博客园-一个悬浮在空中的胖子
var obj = new Object() obj.constructor //ƒ Object() { [native code] }obj.name = "ES" //给obj添加属性obj.hasOwnProperty("name") //true, 注意参数必须为字符串形式obj.propertyIsEnumerable("name") //trueobj.toString() //"[object Object]"
推荐学习:《javascript高级教程》
The above is the detailed content of What does Javascript data type not include?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript is a programming language widely used in web development, while WebSocket is a network protocol used for real-time communication. Combining the powerful functions of the two, we can create an efficient real-time image processing system. This article will introduce how to implement this system using JavaScript and WebSocket, and provide specific code examples. First, we need to clarify the requirements and goals of the real-time image processing system. Suppose we have a camera device that can collect real-time image data
