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>For the typeof operator, there are A little weird thing is:
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声明但未初始化for variables that are declared but not initialized, because of the weird characteristics of
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!

The advantages of React are its flexibility and efficiency, which are reflected in: 1) Component-based design improves code reusability; 2) Virtual DOM technology optimizes performance, especially when handling large amounts of data updates; 3) The rich ecosystem provides a large number of third-party libraries and tools. By understanding how React works and uses examples, you can master its core concepts and best practices to build an efficient, maintainable user interface.

React is a JavaScript library for building user interfaces, suitable for large and complex applications. 1. The core of React is componentization and virtual DOM, which improves UI rendering performance. 2. Compared with Vue, React is more flexible but has a steep learning curve, which is suitable for large projects. 3. Compared with Angular, React is lighter, dependent on the community ecology, and suitable for projects that require flexibility.

React operates in HTML via virtual DOM. 1) React uses JSX syntax to write HTML-like structures. 2) Virtual DOM management UI update, efficient rendering through Diffing algorithm. 3) Use ReactDOM.render() to render the component to the real DOM. 4) Optimization and best practices include using React.memo and component splitting to improve performance and maintainability.

React is widely used in e-commerce, social media and data visualization. 1) E-commerce platforms use React to build shopping cart components, use useState to manage state, onClick to process events, and map function to render lists. 2) Social media applications interact with the API through useEffect to display dynamic content. 3) Data visualization uses react-chartjs-2 library to render charts, and component design is easy to embed applications.

Best practices for React front-end architecture include: 1. Component design and reuse: design a single responsibility, easy to understand and test components to achieve high reuse. 2. State management: Use useState, useReducer, ContextAPI or Redux/MobX to manage state to avoid excessive complexity. 3. Performance optimization: Optimize performance through React.memo, useCallback, useMemo and other methods to find the balance point. 4. Code organization and modularity: Organize code according to functional modules to improve manageability and maintainability. 5. Testing and Quality Assurance: Testing with Jest and ReactTestingLibrary to ensure the quality and reliability of the code

To integrate React into HTML, follow these steps: 1. Introduce React and ReactDOM in HTML files. 2. Define a React component. 3. Render the component into HTML elements using ReactDOM. Through these steps, static HTML pages can be transformed into dynamic, interactive experiences.

React’s popularity includes its performance optimization, component reuse and a rich ecosystem. 1. Performance optimization achieves efficient updates through virtual DOM and diffing mechanisms. 2. Component Reuse Reduces duplicate code by reusable components. 3. Rich ecosystem and one-way data flow enhance the development experience.

React is the tool of choice for building dynamic and interactive user interfaces. 1) Componentization and JSX make UI splitting and reusing simple. 2) State management is implemented through the useState hook to trigger UI updates. 3) The event processing mechanism responds to user interaction and improves user experience.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

Zend Studio 13.0.1
Powerful PHP integrated development environment