Home Web Front-end JS Tutorial Comprehensive JavaScript Development Technology - Chapter 3 JS Data Type_Basic Knowledge

Comprehensive JavaScript Development Technology - Chapter 3 JS Data Type_Basic Knowledge

May 16, 2016 pm 06:05 PM

3.1 基本数据类型
1.字符串类型(string) :由unicode字符、数字、标点符号组成,在javascript中没有char字符类型 ,即使只表示一个字符,也必须用到字符串
2数字型(number):不区分整型和浮点型
3.布尔型(boolean)
3.2复合数据类型
1.数组(array):数组元素:放在数组中的数据称为数组元素。
数组下标:从0开始编号
读:arr[0];
赋值:arr[1]=120;
2.对象:
对象名.属性名
对象名.方法名()
3.3其它有数据类型
函数:
1.javascript中的函数是一种数据类型,因此,可以被存储在变量、数组或对象中。
2 null:在javascript中null是一种独立数据类型,代表没有值
3.undefined 即未定义的意思,有4种情况会返回undefined。
a.定义一个变量,但还没有赋值 。
b.使用了一个未定义的变量
C.定义了一个不存在的对象属性
d.引用了一个不存在的数组元素。
3.4数据类型的转换
原则:将数据类型转换为当前环境中所需要使用的数据类型。
javascript数据类型隐式转换规则
1.数据类型的隐式转换:

               原数据类型 目票数据类型 说明
     字符串 非空字符串 数字弄

如果字符串中的字符为数字,则转换为字符串的数字,如"123"转换为数字是123,

如果字符串中的字符不是纯数字,则转换为naa

布尔型 true
空字符中 数字型 0
布尔型 flase
字符串”true" 数字型 Nan
布尔型 true
字段符串"flase“ 数字型 Nan
布尔型 true
  数字型 普通数字 字符串 可以把数字转换成字符串"数字"
布尔型 数字0转换为false,其他数字转换为true
Nan 字符串型 转换为字符串"Nan"
布尔型 转换为false
布尔型 true 字符串型 转换为字符串"true“
数字型 转换为1
false 字符串型 转换为字符串"false"
数字理 转换为0
null   字符串型 转换为字符串"null”
数字型 转换为0
布尔型 转换为false
undefined 字符串型 转换为字符串"undefined“
数字型 转换为Nan
布尔型 转换为false

                             2.另类数据的隐式转换

                             3.数据类型的显示转换

                                       1.转换为数字型

                                             。nubmer(value)将value转换为整数或浮点数

                                             。parseInt(value)可以将value转换成整数

                                             。parseFlaot(value)转成浮点

                                            不能转成数字型,将返回Nan

                                                                       将其它类型转换为数字型的转换规则

数据类型 说明
字符串 空字符串 使用Number()转换为0,使用parseInt()和parseFloat()转换为Nan
字符串"ture" 转为Nan
字符串"false 转为Nan
其他字符串

如果字符串中的字符为数字,则转为字符中中的数字,如字符串"123"

可以转换为数字123。如果字符串不是纯数字,则转换为Nan

布尔型 true 使用Number()转换为0,使用parseInt()和parseFloat()转换为Nan
false 使用Number()转换为0,使用parseInt()和parseFloat()转换为Nan
null 使用Number()转换为0,使用parseInt()和parseFloat()转换为Nan
undefined 转换为Nan

                                                                   ​ 

Convert other data types to Boolean

                        数据类型 语明
字符串 空字符串 转换为false
字符串"true" 转换为true
字符串"flase" 转换为true
其他字符串 转换为true
数字型 0 转换为false
Nan 转换为false
其他数字 转换为true
null 转换为false
undefined 转换为false
3. Convert to string type

Convert other data types into string types

                                                            

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The difference in console.log output result: Why are the two calls different? The difference in console.log output result: Why are the two calls different? Apr 04, 2025 pm 05:12 PM

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

TypeScript for Beginners, Part 2: Basic Data Types TypeScript for Beginners, Part 2: Basic Data Types Mar 19, 2025 am 09:10 AM

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript

Can PowerPoint run JavaScript? Can PowerPoint run JavaScript? Apr 01, 2025 pm 05:17 PM

JavaScript can be run in PowerPoint, and can be implemented by calling external JavaScript files or embedding HTML files through VBA. 1. To use VBA to call JavaScript files, you need to enable macros and have VBA programming knowledge. 2. Embed HTML files containing JavaScript, which are simple and easy to use but are subject to security restrictions. Advantages include extended functions and flexibility, while disadvantages involve security, compatibility and complexity. In practice, attention should be paid to security, compatibility, performance and user experience.

See all articles